rename references of filter class

This commit is contained in:
buzz-lightsnack-2007 2024-05-24 23:59:49 +08:00
parent 98b01c8380
commit 88f364137c
3 changed files with 47 additions and 45 deletions

View file

@ -5,7 +5,7 @@ Check the tabs in the background, and check the filters.
// Filter importation
import EntryManager from "/scripts/GUI/entrypoints/manager.js"
import filters from "../filters.js";
import FilterManager from "../filters.js";
import {background, global} from "/scripts/secretariat.js";
export default class BackgroundCheck {
@ -19,15 +19,15 @@ export default class BackgroundCheck {
updater() {
global.read([`settings`,`sync`]).then(async (DURATION_PREFERENCES) => {
/*
Set the default options if they don't exist yet.
Set the default options if they don't exist yet.
*/
const setDefaults = async () => {
// Forcibly create the preference if it doesn't exist. It's required!
// Forcibly create the preference if it doesn't exist. It's required!
if (!(typeof DURATION_PREFERENCES).includes(`obj`) || !DURATION_PREFERENCES || Array.isArray(DURATION_PREFERENCES)) {
DURATION_PREFERENCES = {};
DURATION_PREFERENCES[`duration`] = 24;
// Write it.
// Write it.
return(await global.write([`settings`, `sync`], DURATION_PREFERENCES, -1, {"silent": true}));
} else {return (true)};
};
@ -35,7 +35,7 @@ export default class BackgroundCheck {
setDefaults().then((result) => {
if (result) {
/*
Check if it's time to update the filters through comparing the difference of the current time and the last updated time to the expected duration.
Check if it's time to update the filters through comparing the difference of the current time and the last updated time to the expected duration.
*/
async function updater_check() {
let TIME = {};
@ -47,9 +47,9 @@ export default class BackgroundCheck {
};
/*
Run the update.
Run the update.
@return {Promise} the promise that, once resolved, contains the last update status.
@return {Promise} the promise that, once resolved, contains the last update status.
*/
const updater_run = async () => {
filter.update();
@ -58,60 +58,62 @@ export default class BackgroundCheck {
return(await global.write([`settings`,`sync`,`last`], Date.now(), -1));
};
// Set the interval.
// Set the interval.
let updater_set = () => {
this.update[`checker`] = setInterval(async () => {
// Update the filters.
// Update the filters.
updater_run();
}, DURATION_PREFERENCES[`duration`]);
};
/*
Reset the interval.
Reset the interval.
*/
const updater_reset = () => {
// Cancel the interval.
// Cancel the interval.
(this.update[`checker`]) ? clearInterval(this.update[`checker`]) : false;
// Run the updater, if necessary.
// Run the updater, if necessary.
(updater_check())
? updater_run()
: false;
// Start the new interval.
// Start the new interval.
updater_set();
}
const updater_background = () => {
this.update[`background`] = async () => {
if ((await global.read([`settings`, `sync`, `duration`])) ? (await global.read([`settings`, `sync`, `duration`] * (60 ** 2) * 1000 != DURATION_PREFERENCES[`duration`])) : false) {
// Get the new time.
DURATION_PREFERENCES[`duration`] = await global.global.read([`settings`, `sync`, `duration`]) * (60 ** 2) * 1000;
if (await global.global.read([`settings`, `sync`, `duration`])) {
// Get the new time.
DURATION_PREFERENCES[`duration`] = await global.global.read([`settings`, `sync`, `duration`]) * (60 ** 2) * 1000;
// Reset the updater.
updater_reset();
// Reset the updater.
updater_reset();
}
};
};
// Set the background checker.
// Set the background checker.
new background(() => {return(this.update.background())});
}
// Convert DURATION_PREFERENCES[`duration`]) from hrs to milliseconds.
DURATION_PREFERENCES[`duration`] = DURATION_PREFERENCES[`duration`] * (60 ** 2) * 1000;
// Set the filter management.
let filter = new filters();
// Set the filter management.
let filter = new FilterManager();
// When the browser is started, run the updater immediately only when the filters are not updated yet.
(updater_check())
? updater_run()
: false;
// Run the background.
// Run the background.
updater_background();
}
});
})
}
};
};

View file

@ -6,7 +6,7 @@
import {global} from "/scripts/secretariat.js";
import Page from "/scripts/pages/page.js";
import texts from "/scripts/mapping/read.js";
import filters from "/scripts/filters.js";
import FilterManager from "/scripts/filters.js";
import logging from "/scripts/logging.js";
import {URLs} from "/scripts/utils/URLs.js";
@ -25,13 +25,13 @@ class Page_Settings extends Page {
*/
events() {
if ((Object.keys(this.window.elements[`interactive`][`action`])).length) {
// Instantiate the filters module, since it's needed for some of the actions below.
this.data.filters = (this.data.filters) ? this.data.filters : new filters();
// Instantiate the filters module, since it's needed for some of the actions below.
this.data.filters = (this.data.filters) ? this.data.filters : new FilterManager();
// Bypass the OOBE page since the user opened the settings page.
// Bypass the OOBE page since the user opened the settings page.
global.write([`init`], true, 1, {"silent": true});
// Set the actions.
// Set the actions.
let ACTIONS = {};
ACTIONS[`filters,update`] = async () => {this.data.filters.update(`*`);};
ACTIONS[`filters,add,one`] = () => {
@ -44,7 +44,7 @@ class Page_Settings extends Page {
if (SOURCE ? SOURCE.trim() : false) {
SOURCE = SOURCE.trim().split(`, `);
// Verify user inputs are valid.
// Verify user inputs are valid.
let VALID = true;
// Check if the URL is valid.
@ -66,18 +66,18 @@ class Page_Settings extends Page {
}
};
ACTIONS[`filters,update,one`] = () => {
// Update the selected filter.
// Update the selected filter.
return((this.window.search.filters.selected) ? this.data.filters.update(this.window.search.filters.selected) : false)
};
ACTIONS[`filters,delete,one`] = () => {
// Remove the selected filter.
// Remove the selected filter.
return((this.window.search.filters.selected) ? this.data.filters.remove(this.window.search.filters.selected) : false)
}
ACTIONS[`storage,clear`] = () => {
return(global.forget(`sites`));
}
// Add the event listeners.
// Add the event listeners.
(Object.keys(ACTIONS)).forEach((NAME) => {
(this.window.elements[`interactive`][`action`][NAME] ? this.window.elements[`interactive`][`action`][NAME].length : false)
? this.window.elements[`interactive`][`action`][NAME].forEach((ELEMENT) => {
@ -91,7 +91,7 @@ class Page_Settings extends Page {
(this.window.elements[`linked`][`show`][`settings,general,showApplicable`] ? this.window.elements[`linked`][`show`][`settings,general,showApplicable`].length : false)
? (this.window.elements[`linked`][`show`][`settings,general,showApplicable`]).forEach((ELEMENT) => {
ELEMENT.addEventListener(`change`, () => {
// The extension icon cache doesn't clear by itself.
// The extension icon cache doesn't clear by itself.
ELEMENT.addEventListener(`change`, () => {
!(ELEMENT.checked)
? new logging(texts.localized(`settings_restartToApply`), texts.localized(`settings_restartToApply_iconChange`), true)
@ -104,4 +104,4 @@ class Page_Settings extends Page {
}
}
new Page_Settings();
new Page_Settings();

View file

@ -1,19 +1,19 @@
/*
check.js
Check if a website is supported.
Check if a website is supported.
*/
import filters from '/scripts/filters.js';
import FilterManager from '/scripts/filters.js';
export default class check {
/*
Check if an e-commerce platform is supported.
/*
Check if an e-commerce platform is supported.
@param {string} URL
@returns {object} the support state
*/
static async platform (URL = window.location.href) {
return (await ((new filters).select(URL)));
return (await ((new FilterManager).select(URL)));
}
}
}