From c1ab94f73793fda7f32b236ebab80ec884a33e33 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Wed, 8 May 2024 22:07:22 +0800 Subject: [PATCH] events called from the GUI, aside from openiing the popup, are manual --- scripts/external/watch.js | 44 ++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/scripts/external/watch.js b/scripts/external/watch.js index b08e5c4..56a493f 100644 --- a/scripts/external/watch.js +++ b/scripts/external/watch.js @@ -7,22 +7,9 @@ import processor from "/scripts/external/processor.js"; import logging from "/scripts/logging.js"; import texts from "/scripts/mapping/read.js"; import {global} from "/scripts/secretariat.js"; +import nested from "/scripts/utils/nested.js" export default class watch { - /* Act on the page. - - @param {object} filter the filter to work with - @param {object} options the options - */ - static async process(filter, options = {}) { - document.onreadystatechange = async () => { - if (document.readyState == 'complete' && (await global.read([`settings`, `behavior`, `autoRun`]) || ((((typeof options).includes(`object`) && options) ? Object.hasOwn(options, `override`) : false) ? options[`override`] : false))) { - new logging((new texts(`scrape_msg_ready`)).localized); - this.processed = (((options && typeof options == `object`) ? options[`override`] : false) || this.processed == null) ? new processor(filter) : this.processed; - } - } - } - static async main() { let FILTER_RESULT = await check.platform(); @@ -31,13 +18,28 @@ export default class watch { new logging((new texts(`message_external_supported`)).localized); watch.process(FILTER_RESULT); - - // Create a listener for messages indicating re-processing. - chrome.runtime.onMessage.addListener(async (message, sender, sendResponse) => { - (((typeof message).includes(`obj`) && !Array.isArray(message)) ? message[`refresh`] : false) - ? watch.process(FILTER_RESULT, {"override": true}) - : false; - }); } } + + /* Act on the page. + + @param {object} filter the filter to work with + @param {object} options the options + */ + static async process(filter) { + let PROCESSOR = new processor(filter, window.location.href, {"automatic": false}); + + const perform = (options) => { + (document.readyState == `complete`) ? PROCESSOR.run(options) : document.onreadystatechange = async () => {(document.readyState == `complete`) ? PROCESSOR.run(options) : PROCESSOR.product.status.done = .125;}; + } + + (await global.read([`settings`, `behavior`, `autoRun`])) ? document.onreadystatechange = async () => {perform();} : false; + + // Create a listener for messages indicating re-processing. + chrome.runtime.onMessage.addListener(async (message, sender, sendResponse) => { + if (((typeof message).includes(`obj`) && !Array.isArray(message)) ? message[`refresh`] : false) { + perform((message[`refresh`] == `manual`) ? {"analysis": {"override": true}} : null); + }; + }); + }; } \ No newline at end of file