diff --git a/manifest.json b/manifest.json index a754cb5..d34cb46 100644 --- a/manifest.json +++ b/manifest.json @@ -16,7 +16,7 @@ }, "background": { - "service_worker": "scripts/shopAI.js", "type": "module" + "service_worker": "scripts/background/shopAI.js", "type": "module" }, "content_scripts": [ diff --git a/scripts/actions.js b/scripts/actions.js new file mode 100644 index 0000000..25a8934 --- /dev/null +++ b/scripts/actions.js @@ -0,0 +1,14 @@ +import Tabs from "/scripts/GUI/tabs.js"; +import EntryManager from "/scripts/external/entries/manager.js" + +export default class user_actions { + static init() { + chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: true }).catch((error) => console.error(error)); + + user_actions.tabs(); + }; + + static tabs() { + new EntryManager(); + } +}; \ No newline at end of file diff --git a/scripts/actions/tabs.js b/scripts/actions/tabs.js deleted file mode 100644 index 2fde241..0000000 --- a/scripts/actions/tabs.js +++ /dev/null @@ -1,8 +0,0 @@ -import Tabs from "/scripts/GUI/tabs.js"; -import EntryManager from "/scripts/external/entries/manager.js" - -export default class Watcher_Tabs { - constructor () { - new EntryManager(); - }; -} \ No newline at end of file diff --git a/scripts/actions/user_actions.js b/scripts/actions/user_actions.js deleted file mode 100644 index 9438d6b..0000000 --- a/scripts/actions/user_actions.js +++ /dev/null @@ -1,9 +0,0 @@ -import Watcher_Tabs from "./tabs.js"; - -export default class user_actions { - static init() { - chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: true }).catch((error) => console.error(error)); - - new Watcher_Tabs(); - }; -}; \ No newline at end of file diff --git a/scripts/background/fc.js b/scripts/background/fc.js new file mode 100644 index 0000000..262c1f8 --- /dev/null +++ b/scripts/background/fc.js @@ -0,0 +1,109 @@ +/* fc.js +This script provides installation run scripts. +*/ + +import { init, read, write, observe } from "../secretariat.js"; +import filters from "../filters.js"; +let config = chrome.runtime.getURL("config/config.json"); + +export default class fc { + // Start the out of the box experience. + static hello() { + // the OOBE must be in the config. + fetch(config) + .then((response) => response.json()) + .then((jsonData) => { + let configuration = jsonData[`OOBE`]; + + if (configuration) { + configuration.forEach((item) => { + chrome.tabs.create({ url: item }, function (tab) {}); + }); + } + }) + .catch((error) => { + console.error(error); + }); + } + + // Initialize the configuration. + static setup() { + // the OOBE must be in the config. + fetch(config) + .then((response) => response.json()) + .then(async (jsonData) => { + let configuration = jsonData; + + // Run the storage initialization. + delete configuration[`OOBE`]; + init(configuration); + + // Update the filters to sync with synchronized storage data. + (new filters).update(); + }) + .catch((error) => { + console.error(error); + }); + } + + static trigger() { + chrome.runtime.onInstalled.addListener(function (details) { + (details.reason == chrome.runtime.OnInstalledReason.INSTALL) ? fc.hello() : null; + fc.setup(); + }); + } + + // main function + static run() { + fc.trigger(); + fc.every(); + } + + static async every() { + read([`settings`,`sync`]).then(async (DURATION_PREFERENCES) => { + // Forcibly create the preference if it doesn't exist. It's required! + if (!(typeof DURATION_PREFERENCES).includes(`obj`) || DURATION_PREFERENCES == null || Array.isArray(DURATION_PREFERENCES)) { + DURATION_PREFERENCES = {}; + DURATION_PREFERENCES[`duration`] = 24; + + // Write it. + await write([`settings`, `sync`], DURATION_PREFERENCES, -1); + }; + + if (((typeof DURATION_PREFERENCES).includes(`obj`) && DURATION_PREFERENCES != null && !Array.isArray(DURATION_PREFERENCES)) ? ((DURATION_PREFERENCES[`duration`]) ? (DURATION_PREFERENCES[`duration`] > 0) : false) : false) { + // Convert DURATION_PREFERENCES[`duration`]) from hrs to milliseconds. + DURATION_PREFERENCES[`duration`] = DURATION_PREFERENCES[`duration`] * (60 ** 2) * 1000; + let filter = new filters; + + // Now, set the interval. + let updater_set = () => { + setInterval(async () => { + // Update the filters. + filter.update(); + }, DURATION_PREFERENCES[`duration`]); + }; + + // Provide a way to cancel the interval. + let updater_cancel = (updater) => { + clearInterval(updater); + }; + + let UPDATER = updater_set(); + + let updater_interval = async () => { + + if ((await read([`settings`, `sync`, `duration`])) ? (await read([`settings`, `sync`, `duration`] * (60 ** 2) * 1000 != DURATION_PREFERENCES[`duration`])) : false) { + DURATION_PREFERENCES[`duration`] = await read([`settings`, `sync`, `duration`]) * (60 ** 2) * 1000; + + // Reset the updater. + updater_cancel(UPDATER); + UPDATER = updater_set(); + } + }; + + observe(updater_cancel); + }; + }) + + }; +} diff --git a/scripts/background/shopAI.js b/scripts/background/shopAI.js new file mode 100644 index 0000000..8d7b619 --- /dev/null +++ b/scripts/background/shopAI.js @@ -0,0 +1,9 @@ +/* ShopAI +Shop wisely with AI! +*/ + +import fc from './fc.js'; +import user_actions from "../actions.js"; + +fc.run(); +user_actions.init(); \ No newline at end of file diff --git a/scripts/fc.js b/scripts/fc.js deleted file mode 100644 index 3209a20..0000000 --- a/scripts/fc.js +++ /dev/null @@ -1,109 +0,0 @@ -/* fc.js -This does not stand for "FamiCom" but instead on Finalization and Completion. This script provides installation run scripts. -*/ - -import { init, read, write, observe } from "./secretariat.js"; -import filters from "./filters.js"; -let config = chrome.runtime.getURL("config/config.json"); - -export default class fc { - // Start the out of the box experience. - static hello() { - // the OOBE must be in the config. - fetch(config) - .then((response) => response.json()) - .then((jsonData) => { - let configuration = jsonData[`OOBE`]; - - if (configuration) { - configuration.forEach((item) => { - chrome.tabs.create({ url: item }, function (tab) {}); - }); - } - }) - .catch((error) => { - console.error(error); - }); - } - - // Initialize the configuration. - static setup() { - // the OOBE must be in the config. - fetch(config) - .then((response) => response.json()) - .then(async (jsonData) => { - let configuration = jsonData; - - // Run the storage initialization. - delete configuration[`OOBE`]; - init(configuration); - - // Update the filters to sync with synchronized storage data. - (new filters).update(); - }) - .catch((error) => { - console.error(error); - }); - } - - static trigger() { - chrome.runtime.onInstalled.addListener(function (details) { - (details.reason == chrome.runtime.OnInstalledReason.INSTALL) ? fc.hello() : null; - fc.setup(); - }); - } - - // main function - static run() { - fc.trigger(); - fc.every(); - } - - static async every() { - read([`settings`,`sync`]).then(async (DURATION_PREFERENCES) => { - // Forcibly create the preference if it doesn't exist. It's required! - if (!(typeof DURATION_PREFERENCES).includes(`obj`) || DURATION_PREFERENCES == null || Array.isArray(DURATION_PREFERENCES)) { - DURATION_PREFERENCES = {}; - DURATION_PREFERENCES[`duration`] = 24; - - // Write it. - await write([`settings`, `sync`], DURATION_PREFERENCES, -1); - }; - - if (((typeof DURATION_PREFERENCES).includes(`obj`) && DURATION_PREFERENCES != null && !Array.isArray(DURATION_PREFERENCES)) ? ((DURATION_PREFERENCES[`duration`]) ? (DURATION_PREFERENCES[`duration`] > 0) : false) : false) { - // Convert DURATION_PREFERENCES[`duration`]) from hrs to milliseconds. - DURATION_PREFERENCES[`duration`] = DURATION_PREFERENCES[`duration`] * (60 ** 2) * 1000; - let filter = new filters; - - // Now, set the interval. - let updater_set = () => { - setInterval(async () => { - // Update the filters. - filter.update(); - }, DURATION_PREFERENCES[`duration`]); - }; - - // Provide a way to cancel the interval. - let updater_cancel = (updater) => { - clearInterval(updater); - }; - - let UPDATER = updater_set(); - - let updater_interval = async () => { - - if ((await read([`settings`, `sync`, `duration`])) ? (await read([`settings`, `sync`, `duration`] * (60 ** 2) * 1000 != DURATION_PREFERENCES[`duration`])) : false) { - DURATION_PREFERENCES[`duration`] = await read([`settings`, `sync`, `duration`]) * (60 ** 2) * 1000; - - // Reset the updater. - updater_cancel(UPDATER); - UPDATER = updater_set(); - } - }; - - observe(updater_cancel); - }; - }) - - }; -} diff --git a/scripts/shopAI.js b/scripts/shopAI.js deleted file mode 100644 index 1917881..0000000 --- a/scripts/shopAI.js +++ /dev/null @@ -1,9 +0,0 @@ -/* ShopAI -Shop wisely with AI! -*/ - -import fc from './fc.js'; -import user_actions from "./actions/user_actions.js"; - -fc.run(); -user_actions.init(); \ No newline at end of file