From d8a1d6afd428741b4cb1e89703a5330a96269578 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Wed, 4 Dec 2019 23:56:02 +0800 Subject: [PATCH] Use vanilla javascript --- waifu-tips.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/waifu-tips.js b/waifu-tips.js index 765f162..4d1454c 100755 --- a/waifu-tips.js +++ b/waifu-tips.js @@ -160,16 +160,18 @@ function loadWidget(waifuPath, apiPath) { .then(response => response.json()) .then(result => { result.mouseover.forEach(tips => { - $(document).on("mouseover", tips.selector, function() { + window.addEventListener("mouseover", event => { + if (!event.target.matches(tips.selector)) return; var text = Array.isArray(tips.text) ? tips.text[Math.floor(Math.random() * tips.text.length)] : tips.text; - text = text.replace("{text}", $(this).text()); + text = text.replace("{text}", event.target.innerText); showMessage(text, 4000, 8); }); }); result.click.forEach(tips => { - $(document).on("click", tips.selector, function() { + window.addEventListener("click", event => { + if (!event.target.matches(tips.selector)) return; var text = Array.isArray(tips.text) ? tips.text[Math.floor(Math.random() * tips.text.length)] : tips.text; - text = text.replace("{text}", $(this).text()); + text = text.replace("{text}", event.target.innerText); showMessage(text, 4000, 8); }); });