You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
live2d-widget/autoload.js

72 lines
2.6 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//waifu-tips.js:包含了按钮和对话框的逻辑
//waifu-tips.json :定义了触发条件selectorCSS 选择器和触发时显示的文字text
//waifu.css:看板娘的样式表。可以对看板娘的位置布局等做自定义修改
// 注意live2d_path 参数应使用绝对路径
// const live2d_path = "https://fastly.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/";
// const live2d_path = "https://cdn.jsdelivr.net/gh/shendongjun/live2d-widget/";
const live2d_path = "/live2d-widget/";
// 封装异步加载资源的方法
function loadExternalResource(url, type) {
return new Promise((resolve, reject) => {
let tag;
if (type === "css") {
tag = document.createElement("link");
tag.rel = "stylesheet";
tag.href = url;
}
else if (type === "js") {
tag = document.createElement("script");
tag.src = url;
}
if (tag) {
tag.onload = () => resolve(url);
tag.onerror = () => reject(url);
document.head.appendChild(tag);
}
});
}
// 加载 waifu.css live2d.min.js waifu-tips.js
if (screen.width >= 768) {
Promise.all([
loadExternalResource(live2d_path + "waifu.css", "css"),
loadExternalResource(live2d_path + "live2d.min.js", "js"),
loadExternalResource(live2d_path + "waifu-tips.js", "js")
]).then(() => {
initWidget({
waifuPath: live2d_path + "waifu-tips.json",
//四选一 建议选shendongjun
// apiPath: "https://live2d.fghrsh.net/api/",
// cdnPath: "https://fastly.jsdelivr.net/gh/fghrsh/live2d_api/"
// cdnPath: "https://live2d-api.vercel.app/@1.0.0/"
cdnPath: "https://npm.elemecdn.com/akilar-live2dapi@latest/"
});
});
}
// initWidget 第一个参数为 waifu-tips.json 的路径,第二个参数为 API 地址
// API 后端可自行搭建,参考 https://github.com/fghrsh/live2d_api
// 初始化看板娘会自动加载指定目录下的 waifu-tips.json
console.log("看板娘加载出来喽!")
console.log(`
く__,.ヘヽ. / ,ー、 〉
', !-─‐-i / /´
/`ー' L//`ヽ、
/ , /| , , ',
イ / /-/ L_ ハ ヽ! i
レ ヘ 7イト レ'ァ-ト、!ハ| |
!,/7 '0' ´0iソ| |
|.从" _ ,,,, / |./ |
レ'| i.、,,__ _,.イ / .i |
レ'| | / k__/レ'ヽ, ハ. |
| |/i 〈|/ i ,.ヘ | i |
.|/ / ヘ! |
kヽ>、ハ _,.ヘ、 /、!
!'〈//´', '7'ーr'
レ'ヽL__|___i,___,ンレ|
ト-,/ |___./
'ー' !_,.:
`);