From 09e1c5c784391343524563eea5e3ad24d8d49d00 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 26 Sep 2022 16:22:17 +1000 Subject: refactoring editHtml. Separating out functions. --- main_background.js | 183 +++++++++++++++++++++++++++++------------------------ 1 file changed, 100 insertions(+), 83 deletions(-) diff --git a/main_background.js b/main_background.js index 030cdc2..4fe55d5 100644 --- a/main_background.js +++ b/main_background.js @@ -533,7 +533,7 @@ var ResponseHandler = { */ async post(response) { const { type } = response.request; - const handle_it = type === 'script' ? handle_script : handle_html; + const handle_it = type === 'script' ? handleScript : handle_html; return await handle_it(response, response.whitelisted); } } @@ -541,7 +541,7 @@ var ResponseHandler = { /** * Here we handle external script requests */ -async function handle_script(response, whitelisted) { +async function handleScript(response, whitelisted) { const { text, request } = response; const { url, tabId } = request; return await checkScriptAndUpdateReport(text, ListStore.urlItem(url), tabId, whitelisted, isExternal = true); @@ -660,118 +660,135 @@ function readMetadata(metaElement) { * Returns string or null. */ async function editHtml(html, documentUrl, tabId, frameId, whitelisted) { - const htmlDoc = new DOMParser().parseFromString(html, 'text/html'); - // moves external licenses reference, if any, before any