From 349a7a7ac97f3559490ce65c53974b6ea07a42b2 Mon Sep 17 00:00:00 2001 From: FoxRefire <155989196+FoxRefire@users.noreply.github.com> Date: Fri, 21 Jun 2024 18:50:42 +0900 Subject: [PATCH] Refactor:Cleanup code --- background.js | 10 +++------- popup.js | 18 ++++++++---------- popup_showHistory.js | 2 +- popup_updateNotice.js | 8 ++------ 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/background.js b/background.js index f6da5af..bc8dd00 100644 --- a/background.js +++ b/background.js @@ -7,7 +7,7 @@ window.pageURL=""; window.clearkey=""; chrome.storage.local.get("isBlock", (value) => { - window.isBlock = value.isBlock ? true : false; + window.isBlock = value.isBlock; }) function convertHeaders(obj){ @@ -18,11 +18,7 @@ window.blockRules = await fetch("blockRules.conf").then((r)=>r.text()); blockRules = blockRules.replace(/\n^\s*$|\s*\/\/.*|\s*$/gm, ""); blockRules = blockRules.split("\n"); function testBlock(url) { - if(window.isBlock){ - return blockRules.map(e => url.includes(e)).some(e=>e) - } else { - return false - } + return window.isBlock && blockRules.map(e => url.includes(e)).some(e=>e); } //Get URL and headers from POST requests @@ -99,7 +95,7 @@ chrome.runtime.onStartup.addListener(createMenu) chrome.contextMenus.onClicked.addListener(item => { if(item.menuItemId == "toggleBlocking"){ chrome.storage.local.get("isBlock", (value) => { - if(value.isBlock == true){ + if(value.isBlock){ chrome.storage.local.set({'isBlock': false}, null); chrome.contextMenus.update("toggleBlocking",{title: "Enable License Blocking"}) } else { diff --git a/popup.js b/popup.js index a80ddbb..079d1ea 100644 --- a/popup.js +++ b/popup.js @@ -78,14 +78,12 @@ if (clearkey) { document.getElementById('ckResult').value = clearkey; document.getElementById('ckResult').addEventListener("click", copyResult); document.getElementById('toggleHistory').style.display = 'none' -} else if (psshs.length != 0) { - document.addEventListener('DOMContentLoaded', function () { - document.getElementById('noEME').style.display = 'none'; - document.getElementById('home').style.display = 'grid'; - document.getElementById('guess').addEventListener("click", guess); - document.getElementById('result').addEventListener("click", copyResult); - drawList(psshs, 'psshSearch', 'psshList', 'pssh'); - drawList(requests.map(r => r['url']), 'requestSearch', 'requestList', 'license'); - autoSelect(); - }); +} else if (psshs.length) { + document.getElementById('noEME').style.display = 'none'; + document.getElementById('home').style.display = 'grid'; + document.getElementById('guess').addEventListener("click", guess); + document.getElementById('result').addEventListener("click", copyResult); + drawList(psshs, 'psshSearch', 'psshList', 'pssh'); + drawList(requests.map(r => r['url']), 'requestSearch', 'requestList', 'license'); + autoSelect(); } diff --git a/popup_showHistory.js b/popup_showHistory.js index ba565f8..a1ccd6b 100644 --- a/popup_showHistory.js +++ b/popup_showHistory.js @@ -23,7 +23,7 @@ function backHistory(){ document.getElementById('toggleHistory').style.display='grid'; document.getElementById('selectRequest').style.display='none'; document.getElementById('requestList').style.display='none'; - if(psshs.length != 0){ + if(psshs.length){ document.getElementById('home').style.display='grid'; } else { document.getElementById('noEME').style.display='grid'; diff --git a/popup_updateNotice.js b/popup_updateNotice.js index 3926d86..68df4f8 100644 --- a/popup_updateNotice.js +++ b/popup_updateNotice.js @@ -1,10 +1,6 @@ document.addEventListener('DOMContentLoaded', async function() { - cManifest=JSON.parse( - (await fetch("manifest.json").then(r=>r.text())) - ); - rManifest=JSON.parse( - (await fetch("https://raw.githubusercontent.com/FoxRefire/wvg/next/manifest.json").then(r=>r.text())) - ); + cManifest=await fetch("manifest.json").then(r=>r.json()); + rManifest=await fetch("https://raw.githubusercontent.com/FoxRefire/wvg/next/manifest.json").then(r=>r.json()); if(cManifest.version < rManifest.version){ let notice = document.getElementById("updateNotice"); notice.style.display='block';