From 26dfd56fc313cb317c184af658b274c110db2ee3 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Fri, 31 Jul 2020 15:13:35 +0800 Subject: [PATCH] Use destructuring assignment --- README.md | 4 +++- waifu-tips.js | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 2cbd9ff..b2c03b6 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,9 @@ https://github.com/xiaoski/live2d_models_collection 除此之外,还有桌面版本: https://github.com/amorist/platelet -https://github.com/akiroz/Live2D-Widget +https://github.com/akiroz/Live2D-Widget +https://github.com/zenghongtu/PPet +https://github.com/LikeNeko/L2dPetForMac ## 许可证 License diff --git a/waifu-tips.js b/waifu-tips.js index 290e449..1e83f54 100755 --- a/waifu-tips.js +++ b/waifu-tips.js @@ -170,29 +170,29 @@ function loadWidget(config) { .then(response => response.json()) .then(result => { window.addEventListener("mouseover", event => { - for (let tips of result.mouseover) { - if (!event.target.matches(tips.selector)) continue; - let text = randomSelection(tips.text); + for (let { selector, text } of result.mouseover) { + if (!event.target.matches(selector)) continue; + text = randomSelection(text); text = text.replace("{text}", event.target.innerText); showMessage(text, 4000, 8); return; } }); window.addEventListener("click", event => { - for (let tips of result.click) { - if (!event.target.matches(tips.selector)) continue; - let text = randomSelection(tips.text); + for (let { selector, text } of result.click) { + if (!event.target.matches(selector)) continue; + text = randomSelection(text); text = text.replace("{text}", event.target.innerText); showMessage(text, 4000, 8); return; } }); - result.seasons.forEach(tips => { + result.seasons.forEach(({ date, text }) => { const now = new Date(), - after = tips.date.split("-")[0], - before = tips.date.split("-")[1] || after; + after = date.split("-")[0], + before = 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])) { - let text = randomSelection(tips.text); + text = randomSelection(text); text = text.replace("{year}", now.getFullYear()); //showMessage(text, 7000, true); messageArray.push(text);