diff --git a/waifu-tips.js b/waifu-tips.js index dab9215..290e449 100755 --- a/waifu-tips.js +++ b/waifu-tips.js @@ -64,8 +64,8 @@ function loadWidget(config) { if (!window.ASTEROIDSPLAYERS) window.ASTEROIDSPLAYERS = []; window.ASTEROIDSPLAYERS.push(new Asteroids()); } else { - let script = document.createElement("script"); - script.src = "https://cdn.jsdelivr.net/gh/GalaxyMimi/CDN/asteroids.js"; + const script = document.createElement("script"); + script.src = "https://cdn.jsdelivr.net/gh/stevenjoezhang/asteroids/asteroids.js"; document.head.appendChild(script); } }); @@ -88,7 +88,7 @@ function loadWidget(config) { document.getElementById("waifu-toggle").classList.add("waifu-toggle-active"); }, 3000); }); - let devtools = () => {}; + const devtools = () => {}; console.log("%c", devtools); devtools.toString = () => { showMessage("哈哈,你打开了控制台,是想要看看我的小秘密吗?", 6000, 9); @@ -104,7 +104,7 @@ function loadWidget(config) { (function welcomeMessage() { let text; if (location.pathname === "/") { // 如果是主页 - let now = new Date().getHours(); + const now = new Date().getHours(); if (now > 5 && now <= 7) text = "早上好!一日之计在于晨,美好的一天就要开始了。"; else if (now > 7 && now <= 11) text = "上午好!工作顺利嘛,不要久坐,多起来走动走动哦!"; else if (now > 11 && now <= 13) text = "中午了,工作了一个上午,现在是午餐时间!"; @@ -114,7 +114,7 @@ function loadWidget(config) { else if (now > 21 && now <= 23) text = ["已经这么晚了呀,早点休息吧,晚安~", "深夜时要爱护眼睛呀!"]; else text = "你是夜猫子呀?这么晚还不睡觉,明天起的来嘛?"; } else if (document.referrer !== "") { - let referrer = new URL(document.referrer), + const referrer = new URL(document.referrer), domain = referrer.hostname.split(".")[1]; if (location.hostname === referrer.hostname) text = `欢迎阅读「${document.title.split(" - ")[0]}」`; else if (domain === "baidu") text = `Hello!来自 百度搜索 的朋友
你是搜索 ${referrer.search.split("&wd=")[1].split("&")[0]} 找到的我吗?`; @@ -132,7 +132,7 @@ function loadWidget(config) { fetch("https://v1.hitokoto.cn") .then(response => response.json()) .then(result => { - let text = `这句一言来自 「${result.from}」,是 ${result.creator} 在 hitokoto.cn 投稿的。`; + const text = `这句一言来自 「${result.from}」,是 ${result.creator} 在 hitokoto.cn 投稿的。`; showMessage(result.hitokoto, 6000, 9); setTimeout(() => { showMessage(text, 4000, 9); @@ -148,7 +148,7 @@ function loadWidget(config) { } text = randomSelection(text); sessionStorage.setItem("waifu-text", priority); - let tips = document.getElementById("waifu-tips"); + const tips = document.getElementById("waifu-tips"); tips.innerHTML = text; tips.classList.add("waifu-tips-active"); messageTimer = setTimeout(() => { @@ -188,7 +188,7 @@ function loadWidget(config) { } }); result.seasons.forEach(tips => { - let now = new Date(), + const now = new Date(), after = tips.date.split("-")[0], before = tips.date.split("-")[1] || after; if ((after.split("/")[0] <= now.getMonth() + 1 && now.getMonth() + 1 <= before.split("/")[0]) && (after.split("/")[1] <= now.getDate() && now.getDate() <= before.split("/")[1])) { @@ -202,9 +202,8 @@ function loadWidget(config) { })(); async function loadModelList() { - let response = await fetch(`${cdnPath}model_list.json`); - let result = await response.json(); - modelList = result; + const response = await fetch(`${cdnPath}model_list.json`); + modelList = await response.json(); } async function loadModel(modelId, modelTexturesId, message) { @@ -213,7 +212,7 @@ function loadWidget(config) { showMessage(message, 4000, 10); if (useCDN) { if (!modelList) await loadModelList(); - let target = randomSelection(modelList.models[modelId]); + const target = randomSelection(modelList.models[modelId]); loadlive2d("live2d", `${cdnPath}model/${target}/index.json`); } else { loadlive2d("live2d", `${apiPath}get/?id=${modelId}-${modelTexturesId}`); @@ -222,11 +221,11 @@ function loadWidget(config) { } async function loadRandModel() { - let modelId = localStorage.getItem("modelId"), + const modelId = localStorage.getItem("modelId"), modelTexturesId = localStorage.getItem("modelTexturesId"); if (useCDN) { if (!modelList) await loadModelList(); - let target = randomSelection(modelList.models[modelId]); + const target = randomSelection(modelList.models[modelId]); loadlive2d("live2d", `${cdnPath}model/${target}/index.json`); showMessage("我的新衣服好看嘛?", 4000, 10); } else { @@ -244,7 +243,7 @@ function loadWidget(config) { let modelId = localStorage.getItem("modelId"); if (useCDN) { if (!modelList) await loadModelList(); - let index = (++modelId >= modelList.models.length) ? 0 : modelId; + const index = (++modelId >= modelList.models.length) ? 0 : modelId; loadModel(index, 0, modelList.messages[index]); } else { fetch(`${apiPath}switch/?id=${modelId}`) @@ -266,7 +265,7 @@ function initWidget(config, apiPath) { document.body.insertAdjacentHTML("beforeend", `
看板娘
`); - let toggle = document.getElementById("waifu-toggle"); + const toggle = document.getElementById("waifu-toggle"); toggle.addEventListener("click", () => { toggle.classList.remove("waifu-toggle-active"); if (toggle.getAttribute("first-time")) {