rename references of filter class
This commit is contained in:
parent
98b01c8380
commit
88f364137c
3 changed files with 47 additions and 45 deletions
|
@ -5,7 +5,7 @@ Check the tabs in the background, and check the filters.
|
||||||
|
|
||||||
// Filter importation
|
// Filter importation
|
||||||
import EntryManager from "/scripts/GUI/entrypoints/manager.js"
|
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";
|
import {background, global} from "/scripts/secretariat.js";
|
||||||
|
|
||||||
export default class BackgroundCheck {
|
export default class BackgroundCheck {
|
||||||
|
@ -19,15 +19,15 @@ export default class BackgroundCheck {
|
||||||
updater() {
|
updater() {
|
||||||
global.read([`settings`,`sync`]).then(async (DURATION_PREFERENCES) => {
|
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 () => {
|
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)) {
|
if (!(typeof DURATION_PREFERENCES).includes(`obj`) || !DURATION_PREFERENCES || Array.isArray(DURATION_PREFERENCES)) {
|
||||||
DURATION_PREFERENCES = {};
|
DURATION_PREFERENCES = {};
|
||||||
DURATION_PREFERENCES[`duration`] = 24;
|
DURATION_PREFERENCES[`duration`] = 24;
|
||||||
|
|
||||||
// Write it.
|
// Write it.
|
||||||
return(await global.write([`settings`, `sync`], DURATION_PREFERENCES, -1, {"silent": true}));
|
return(await global.write([`settings`, `sync`], DURATION_PREFERENCES, -1, {"silent": true}));
|
||||||
} else {return (true)};
|
} else {return (true)};
|
||||||
};
|
};
|
||||||
|
@ -35,7 +35,7 @@ export default class BackgroundCheck {
|
||||||
setDefaults().then((result) => {
|
setDefaults().then((result) => {
|
||||||
if (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() {
|
async function updater_check() {
|
||||||
let TIME = {};
|
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 () => {
|
const updater_run = async () => {
|
||||||
filter.update();
|
filter.update();
|
||||||
|
@ -58,60 +58,62 @@ export default class BackgroundCheck {
|
||||||
return(await global.write([`settings`,`sync`,`last`], Date.now(), -1));
|
return(await global.write([`settings`,`sync`,`last`], Date.now(), -1));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set the interval.
|
// Set the interval.
|
||||||
let updater_set = () => {
|
let updater_set = () => {
|
||||||
this.update[`checker`] = setInterval(async () => {
|
this.update[`checker`] = setInterval(async () => {
|
||||||
// Update the filters.
|
// Update the filters.
|
||||||
updater_run();
|
updater_run();
|
||||||
}, DURATION_PREFERENCES[`duration`]);
|
}, DURATION_PREFERENCES[`duration`]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Reset the interval.
|
Reset the interval.
|
||||||
*/
|
*/
|
||||||
const updater_reset = () => {
|
const updater_reset = () => {
|
||||||
// Cancel the interval.
|
// Cancel the interval.
|
||||||
(this.update[`checker`]) ? clearInterval(this.update[`checker`]) : false;
|
(this.update[`checker`]) ? clearInterval(this.update[`checker`]) : false;
|
||||||
|
|
||||||
// Run the updater, if necessary.
|
// Run the updater, if necessary.
|
||||||
(updater_check())
|
(updater_check())
|
||||||
? updater_run()
|
? updater_run()
|
||||||
: false;
|
: false;
|
||||||
|
|
||||||
// Start the new interval.
|
// Start the new interval.
|
||||||
updater_set();
|
updater_set();
|
||||||
}
|
}
|
||||||
|
|
||||||
const updater_background = () => {
|
const updater_background = () => {
|
||||||
this.update[`background`] = async () => {
|
this.update[`background`] = async () => {
|
||||||
if ((await global.read([`settings`, `sync`, `duration`])) ? (await global.read([`settings`, `sync`, `duration`] * (60 ** 2) * 1000 != DURATION_PREFERENCES[`duration`])) : false) {
|
if ((await global.read([`settings`, `sync`, `duration`])) ? (await global.read([`settings`, `sync`, `duration`] * (60 ** 2) * 1000 != DURATION_PREFERENCES[`duration`])) : false) {
|
||||||
// Get the new time.
|
if (await global.global.read([`settings`, `sync`, `duration`])) {
|
||||||
DURATION_PREFERENCES[`duration`] = await global.global.read([`settings`, `sync`, `duration`]) * (60 ** 2) * 1000;
|
// Get the new time.
|
||||||
|
DURATION_PREFERENCES[`duration`] = await global.global.read([`settings`, `sync`, `duration`]) * (60 ** 2) * 1000;
|
||||||
|
|
||||||
// Reset the updater.
|
// Reset the updater.
|
||||||
updater_reset();
|
updater_reset();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set the background checker.
|
// Set the background checker.
|
||||||
new background(() => {return(this.update.background())});
|
new background(() => {return(this.update.background())});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert DURATION_PREFERENCES[`duration`]) from hrs to milliseconds.
|
// Convert DURATION_PREFERENCES[`duration`]) from hrs to milliseconds.
|
||||||
DURATION_PREFERENCES[`duration`] = DURATION_PREFERENCES[`duration`] * (60 ** 2) * 1000;
|
DURATION_PREFERENCES[`duration`] = DURATION_PREFERENCES[`duration`] * (60 ** 2) * 1000;
|
||||||
|
|
||||||
// Set the filter management.
|
// Set the filter management.
|
||||||
let filter = new filters();
|
let filter = new FilterManager();
|
||||||
|
|
||||||
// When the browser is started, run the updater immediately only when the filters are not updated yet.
|
// When the browser is started, run the updater immediately only when the filters are not updated yet.
|
||||||
(updater_check())
|
(updater_check())
|
||||||
? updater_run()
|
? updater_run()
|
||||||
: false;
|
: false;
|
||||||
|
|
||||||
// Run the background.
|
// Run the background.
|
||||||
updater_background();
|
updater_background();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
import {global} from "/scripts/secretariat.js";
|
import {global} from "/scripts/secretariat.js";
|
||||||
import Page from "/scripts/pages/page.js";
|
import Page from "/scripts/pages/page.js";
|
||||||
import texts from "/scripts/mapping/read.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 logging from "/scripts/logging.js";
|
||||||
import {URLs} from "/scripts/utils/URLs.js";
|
import {URLs} from "/scripts/utils/URLs.js";
|
||||||
|
|
||||||
|
@ -25,13 +25,13 @@ class Page_Settings extends Page {
|
||||||
*/
|
*/
|
||||||
events() {
|
events() {
|
||||||
if ((Object.keys(this.window.elements[`interactive`][`action`])).length) {
|
if ((Object.keys(this.window.elements[`interactive`][`action`])).length) {
|
||||||
// Instantiate the filters module, since it's needed for some of the actions below.
|
// 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();
|
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});
|
global.write([`init`], true, 1, {"silent": true});
|
||||||
|
|
||||||
// Set the actions.
|
// Set the actions.
|
||||||
let ACTIONS = {};
|
let ACTIONS = {};
|
||||||
ACTIONS[`filters,update`] = async () => {this.data.filters.update(`*`);};
|
ACTIONS[`filters,update`] = async () => {this.data.filters.update(`*`);};
|
||||||
ACTIONS[`filters,add,one`] = () => {
|
ACTIONS[`filters,add,one`] = () => {
|
||||||
|
@ -44,7 +44,7 @@ class Page_Settings extends Page {
|
||||||
if (SOURCE ? SOURCE.trim() : false) {
|
if (SOURCE ? SOURCE.trim() : false) {
|
||||||
SOURCE = SOURCE.trim().split(`, `);
|
SOURCE = SOURCE.trim().split(`, `);
|
||||||
|
|
||||||
// Verify user inputs are valid.
|
// Verify user inputs are valid.
|
||||||
let VALID = true;
|
let VALID = true;
|
||||||
|
|
||||||
// Check if the URL is valid.
|
// Check if the URL is valid.
|
||||||
|
@ -66,18 +66,18 @@ class Page_Settings extends Page {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ACTIONS[`filters,update,one`] = () => {
|
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)
|
return((this.window.search.filters.selected) ? this.data.filters.update(this.window.search.filters.selected) : false)
|
||||||
};
|
};
|
||||||
ACTIONS[`filters,delete,one`] = () => {
|
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)
|
return((this.window.search.filters.selected) ? this.data.filters.remove(this.window.search.filters.selected) : false)
|
||||||
}
|
}
|
||||||
ACTIONS[`storage,clear`] = () => {
|
ACTIONS[`storage,clear`] = () => {
|
||||||
return(global.forget(`sites`));
|
return(global.forget(`sites`));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the event listeners.
|
// Add the event listeners.
|
||||||
(Object.keys(ACTIONS)).forEach((NAME) => {
|
(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] ? this.window.elements[`interactive`][`action`][NAME].length : false)
|
||||||
? this.window.elements[`interactive`][`action`][NAME].forEach((ELEMENT) => {
|
? 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`] ? this.window.elements[`linked`][`show`][`settings,general,showApplicable`].length : false)
|
||||||
? (this.window.elements[`linked`][`show`][`settings,general,showApplicable`]).forEach((ELEMENT) => {
|
? (this.window.elements[`linked`][`show`][`settings,general,showApplicable`]).forEach((ELEMENT) => {
|
||||||
ELEMENT.addEventListener(`change`, () => {
|
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.addEventListener(`change`, () => {
|
||||||
!(ELEMENT.checked)
|
!(ELEMENT.checked)
|
||||||
? new logging(texts.localized(`settings_restartToApply`), texts.localized(`settings_restartToApply_iconChange`), true)
|
? 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();
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
/*
|
/*
|
||||||
check.js
|
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 {
|
export default class check {
|
||||||
/*
|
/*
|
||||||
Check if an e-commerce platform is supported.
|
Check if an e-commerce platform is supported.
|
||||||
|
|
||||||
@param {string} URL
|
@param {string} URL
|
||||||
@returns {object} the support state
|
@returns {object} the support state
|
||||||
*/
|
*/
|
||||||
static async platform (URL = window.location.href) {
|
static async platform (URL = window.location.href) {
|
||||||
return (await ((new filters).select(URL)));
|
return (await ((new FilterManager).select(URL)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue