Skip to content

Commit

Permalink
add clear button, update import action
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanMo committed Dec 20, 2023
1 parent c7eb416 commit d79bb62
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ <h1 class="title">LexiBridge设置</h1>
</div>
<p class="help">示例文件: <a download href="https://raw.githubusercontent.com/ChanMo/LexiBridge/main/en_zh.json">CET6单词下载</a></p>
</div>
<p><button id="clear-btn" class="button is-danger is-outlined">清空词库</button></p>

<div class="table-container">
<table class="table is-fullwidth">
Expand Down
12 changes: 10 additions & 2 deletions words.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
})();

0 comments on commit d79bb62

Please sign in to comment.