From c7f792aefd5dc59886641ad9ac957ac7e2edc532 Mon Sep 17 00:00:00 2001 From: FoxRefire <155989196+FoxRefire@users.noreply.github.com> Date: Thu, 25 Apr 2024 03:41:58 +0900 Subject: [PATCH] [Refactor] Move some snippets --- popup.js | 21 --------------------- popup_drawList.js | 13 +++++++++++++ popup_showHistory.js | 15 ++++++++++++--- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/popup.js b/popup.js index 13526de..ffa34aa 100644 --- a/popup.js +++ b/popup.js @@ -2,24 +2,6 @@ let psshs=chrome.extension.getBackgroundPage().getPsshs(); let requests=chrome.extension.getBackgroundPage().getRequests(); let pageURL=chrome.extension.getBackgroundPage().getPageURL(); -function selectPssh(){ - document.getElementById('home').style.display='none'; - document.getElementById('selectPssh').style.display='block'; -} - -function selectRequest(){ - document.getElementById('home').style.display='none'; - document.getElementById('selectRequest').style.display='block'; -} - -function showHistory(){ - chrome.storage.local.get(null, ((data) => { - jsonview.renderJSON(JSON.stringify(data), document.getElementById('histDisp')); - })); - document.getElementById('home').style.display='none'; - document.getElementById('history').style.display='block'; -} - async function guess(){ //Init Pyodide let pyodide = await loadPyodide(); @@ -49,9 +31,6 @@ if(psshs.length!=0){ document.addEventListener('DOMContentLoaded', function() { document.getElementById('noEME').style.display='none'; document.getElementById('home').style.display='block'; - document.getElementById('historyButton').addEventListener("click", showHistory); - document.getElementById('psshButton').addEventListener("click", selectPssh); - document.getElementById('licenseButton').addEventListener("click", selectRequest); document.getElementById('guess').addEventListener("click", guess); drawList(psshs,'psshSearch','psshList','pssh'); drawList(requests.map(r => r['url']),'requestSearch','requestList','license'); diff --git a/popup_drawList.js b/popup_drawList.js index c0b2754..3a9dcbc 100644 --- a/popup_drawList.js +++ b/popup_drawList.js @@ -1,3 +1,16 @@ +function selectPssh(){ + document.getElementById('home').style.display='none'; + document.getElementById('selectPssh').style.display='block'; +} + +function selectRequest(){ + document.getElementById('home').style.display='none'; + document.getElementById('selectRequest').style.display='block'; +} + +document.getElementById('psshButton').addEventListener("click", selectPssh); +document.getElementById('licenseButton').addEventListener("click", selectRequest); + var userInputs={}; function drawList(arr,_searchBox,_list,_userInputs){ const elements = arr; diff --git a/popup_showHistory.js b/popup_showHistory.js index 9688162..94f858d 100644 --- a/popup_showHistory.js +++ b/popup_showHistory.js @@ -1,11 +1,17 @@ -document.getElementById('backHistory').addEventListener("click", backHistory); +function showHistory(){ + chrome.storage.local.get(null, ((data) => { + jsonview.renderJSON(JSON.stringify(data), document.getElementById('histDisp')); + })); + document.getElementById('home').style.display='none'; + document.getElementById('history').style.display='block'; +} + function backHistory(){ document.getElementById('histDisp').innerHTML=""; document.getElementById('history').style.display='none'; document.getElementById('home').style.display='block'; } -document.getElementById('saveHistory').addEventListener("click", saveHistory); function saveHistory(){ chrome.storage.local.get(null, ((data) => { let blob = new Blob([JSON.stringify(data, null, "\t")], {type: "text/plain"}); @@ -20,10 +26,13 @@ function saveHistory(){ })); } -document.getElementById('clearHistory').addEventListener("click", clearHistory); function clearHistory(){ if(confirm("Do you really want to clear history?")){ chrome.storage.local.clear(); document.getElementById('histDisp').innerHTML=""; } } +document.getElementById('historyButton').addEventListener("click", showHistory); +document.getElementById('backHistory').addEventListener("click", backHistory); +document.getElementById('saveHistory').addEventListener("click", saveHistory); +document.getElementById('clearHistory').addEventListener("click", clearHistory);