From e21820576ec3c1d011586d4a4d36b9927269c67c Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Sun, 14 Apr 2024 23:24:04 +0800 Subject: [PATCH] call the external processor --- scripts/outside/watchman.js | 102 +++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 49 deletions(-) diff --git a/scripts/outside/watchman.js b/scripts/outside/watchman.js index f4bfa8c..3a36af1 100644 --- a/scripts/outside/watchman.js +++ b/scripts/outside/watchman.js @@ -2,60 +2,64 @@ Be sensitive to changes and update the state. */ -(async () => { - // Import modules. - let secretariat = await import( - chrome.runtime.getURL("scripts/secretariat.js") - ); - let filters = new ((await import(chrome.runtime.getURL("scripts/filters.js"))).default); - // let reader = await import(chrome.runtime.getURL("scripts/reader.js")); +let main = (async () => { + // Import modules. + let filters = new ((await import(chrome.runtime.getURL("scripts/filters.js"))).default); + const processor = (await import(chrome.runtime.getURL("scripts/outside/processor.js"))).default; - class watchman { - /* Check the current URL. + class watchman { + /* Check the current URL. - @param {string} URL the page URL; default value is the current webpage - @return {dictionary} the filter to follow - */ - static async observe(URL = window.location.href) { - // Create the variable to determine the corresponding key. - let activity = false; - - activity = await filters.select(URL); + @param {string} URL the page URL; default value is the current webpage + @return {dictionary} the filter to follow + */ + static async observe(URL = window.location.href) { + // Create the variable to determine the corresponding key. + let activity = await filters.select(URL); - return activity; - } + return activity; + } - /* Act on the page. + /* Act on the page. - @param {dictionary} filters the filter to work with - @return {boolean} the state - */ - static act(filters) { - console.log( - "ShopAI works here! Click on the button in the toolbar or website to start.", - ); - secretariat.write("state", true); - // TODO - } + @param {dictionary} filters the filter to work with + @return {boolean} the state + */ + static act(matches) { + console.log("ShopAI works here! Click on the button in the toolbar or website to start."); + // Show loading screen while the load is incomplete. + + // Set the icon to indicate that it's active. - /* Set the program to standby utnil next load. - */ - static standby() { - // Set the icon to indicate that it's not active. - secretariat.write("state", false); - } + // Begin. + let PROC = new processor(matches); - static async job() { - /* The main action. */ - (watchman.observe()).then((job_task) => { - if (job_task && Object.keys(job_task).length !== 0) { - watchman.act(job_task); - } else { - watchman.standby(); - } - }); - } - } + window.addEventListener(`load`, (event) => { + // Remove the loading screen. + }); + } - watchman.job(); -})(); + /* Set the program to standby utnil next load. + */ + static standby() { + // Set the icon to indicate that it's not active. + } + + static async job() { + /* The main action. */ + + (watchman.observe()).then((RULES) => { + if (RULES && Object.keys(RULES).length !== 0) { + watchman.act(RULES); + } else { + watchman.standby(); + } + }); + } + } + + watchman.job(); +}); + + +main();