From d79bb625a926147cb096a729c04b8fe147d81606 Mon Sep 17 00:00:00 2001 From: dyou Date: Wed, 20 Dec 2023 10:46:42 +0800 Subject: [PATCH] add clear button, update import action --- options.html | 1 + words.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/options.html b/options.html index b448f2a..18a2035 100644 --- a/options.html +++ b/options.html @@ -35,6 +35,7 @@

LexiBridge设置

示例文件: CET6单词下载

+

diff --git a/words.js b/words.js index 289f444..3c9af2e 100644 --- a/words.js +++ b/words.js @@ -47,15 +47,23 @@ }); document.getElementById("import-btn").addEventListener("click", (e) => { + e.target.classList.add("is-loading"); e.preventDefault(); const files = document.querySelector("[name=source]").files; for (const file of files) { const reader = new FileReader(); - reader.onload = (e) => { + reader.onload = async(e) => { const data = JSON.parse(e.target.result); - chrome.storage.local.set({"words":data}) + await chrome.storage.local.set({"words":data}) + window.location.reload(); } reader.readAsText(file); } }); + document.getElementById("clear-btn").addEventListener("click", async(e) => { + e.target.classList.add("is-loading"); + e.preventDefault(); + await chrome.storage.local.set({"words":[]}) + window.location.reload(); + }); })();