diff --git a/autoload.js b/autoload.js index b2020e7..aa2d56f 100644 --- a/autoload.js +++ b/autoload.js @@ -31,7 +31,11 @@ if (screen.width >= 768) { loadExternalResource(live2d_path + "live2d.min.js", "js"), loadExternalResource(live2d_path + "waifu-tips.js", "js") ]).then(() => { - initWidget(live2d_path + "waifu-tips.json", "https://live2d.fghrsh.net/api"); + initWidget({ + waifuPath: live2d_path + "waifu-tips.json", + apiPath: "https://live2d.fghrsh.net/api", + cdnPath: "https://cdn.jsdelivr.net/gh/fghrsh/live2d_api" + }); }); } // initWidget 第一个参数为 waifu-tips.json 的路径,第二个参数为 API 地址 diff --git a/waifu-tips.js b/waifu-tips.js index f44a4b8..88e3330 100755 --- a/waifu-tips.js +++ b/waifu-tips.js @@ -3,7 +3,8 @@ * https://github.com/stevenjoezhang/live2d-widget */ -function loadWidget(waifuPath, apiPath) { +function loadWidget(config) { + let { waifuPath, apiPath } = config; localStorage.removeItem("waifu-display"); sessionStorage.removeItem("waifu-text"); document.body.insertAdjacentHTML("beforeend", `
@@ -220,7 +221,13 @@ function loadWidget(waifuPath, apiPath) { } } -function initWidget(waifuPath = "/waifu-tips.json", apiPath = "") { +function initWidget(config, apiPath = "") { + if (typeof config === "string") { + config = { + waifuPath: config, + apiPath + }; + } document.body.insertAdjacentHTML("beforeend", `
看板娘
`); @@ -228,7 +235,7 @@ function initWidget(waifuPath = "/waifu-tips.json", apiPath = "") { toggle.addEventListener("click", () => { toggle.classList.remove("waifu-toggle-active"); if (toggle.getAttribute("first-time")) { - loadWidget(waifuPath, apiPath); + loadWidget(config); toggle.removeAttribute("first-time"); } else { localStorage.removeItem("waifu-display"); @@ -244,6 +251,6 @@ function initWidget(waifuPath = "/waifu-tips.json", apiPath = "") { toggle.classList.add("waifu-toggle-active"); }, 0); } else { - loadWidget(waifuPath, apiPath); + loadWidget(config); } }