From cbe7ea60426e8f1ebc57bcfc3c3401ba443ed431 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Sun, 28 Apr 2024 23:56:29 +0800 Subject: [PATCH] prepare for receiving re-analysis requests --- scripts/external/watch.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/scripts/external/watch.js b/scripts/external/watch.js index e24ad09..04b31cb 100644 --- a/scripts/external/watch.js +++ b/scripts/external/watch.js @@ -24,19 +24,28 @@ export default class watch { new logging((new texts(`message_external_supported`)).localized); // Begin only when the page is fully loaded. - window.addEventListener(`DOMContentLoaded`, (event) => { - // Begin processing. - let PROC = new processor(filter); - }); + document.onreadystatechange = () => { + if (document.readyState == 'complete') { + let PROC = new processor(filter); + } + }; } static main() { - /* The main action. */ - (check.platform()).then((RULES) => { - if (RULES && Object.keys(RULES).length > 0) { - watch.process(RULES); + (check.platform()).then((FILTER_RESULT) => { + if (FILTER_RESULT && Object.keys(FILTER_RESULT).length > 0) { + watch.process(FILTER_RESULT); watch.callGUI(); + + // Create a listener for messages indicating re-processing. + chrome.runtime.onMessage.addListener(async (message, sender, sendResponse) => { + // Get the tabId where this content script is running. + + + (((typeof message).includes(`obj`) && !Array.isArray(message)) ? message[`refresh`] : false) ? watch.process(FILTER_RESULT) : false; + }); } }); + } } \ No newline at end of file