Use destructuring assignment

This commit is contained in:
Mimi 2020-07-31 15:13:35 +08:00
parent b6f9613eca
commit 26dfd56fc3
2 changed files with 13 additions and 11 deletions

View File

@ -136,6 +136,8 @@ https://github.com/xiaoski/live2d_models_collection
除此之外,还有桌面版本: 除此之外,还有桌面版本:
https://github.com/amorist/platelet 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 ## 许可证 License

View File

@ -170,29 +170,29 @@ function loadWidget(config) {
.then(response => response.json()) .then(response => response.json())
.then(result => { .then(result => {
window.addEventListener("mouseover", event => { window.addEventListener("mouseover", event => {
for (let tips of result.mouseover) { for (let { selector, text } of result.mouseover) {
if (!event.target.matches(tips.selector)) continue; if (!event.target.matches(selector)) continue;
let text = randomSelection(tips.text); text = randomSelection(text);
text = text.replace("{text}", event.target.innerText); text = text.replace("{text}", event.target.innerText);
showMessage(text, 4000, 8); showMessage(text, 4000, 8);
return; return;
} }
}); });
window.addEventListener("click", event => { window.addEventListener("click", event => {
for (let tips of result.click) { for (let { selector, text } of result.click) {
if (!event.target.matches(tips.selector)) continue; if (!event.target.matches(selector)) continue;
let text = randomSelection(tips.text); text = randomSelection(text);
text = text.replace("{text}", event.target.innerText); text = text.replace("{text}", event.target.innerText);
showMessage(text, 4000, 8); showMessage(text, 4000, 8);
return; return;
} }
}); });
result.seasons.forEach(tips => { result.seasons.forEach(({ date, text }) => {
const now = new Date(), const now = new Date(),
after = tips.date.split("-")[0], after = date.split("-")[0],
before = tips.date.split("-")[1] || after; 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])) { 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()); text = text.replace("{year}", now.getFullYear());
//showMessage(text, 7000, true); //showMessage(text, 7000, true);
messageArray.push(text); messageArray.push(text);