fixed class referencing
This commit is contained in:
parent
6a1ea8eb7d
commit
543fe2f913
9 changed files with 383 additions and 377 deletions
|
@ -2,7 +2,7 @@
|
|||
This does not stand for "FamiCom" but instead on Finalization and Completion. This script provides installation run scripts.
|
||||
*/
|
||||
|
||||
import { read, write, init } from "./secretariat.js";
|
||||
import { init } from "./secretariat.js";
|
||||
|
||||
let config = chrome.runtime.getURL("config/config.json");
|
||||
|
||||
|
|
|
@ -2,102 +2,121 @@
|
|||
Manage filters.
|
||||
*/
|
||||
|
||||
/* Select the most appropriate filter based on a URL.
|
||||
|
||||
@param {string} URL the current URL
|
||||
*/
|
||||
export async function select(URL = window.location.href) {}
|
||||
|
||||
/* Update all filters or just one.
|
||||
|
||||
@param {string} URL the URL to update
|
||||
@return {boolean} the state
|
||||
*/
|
||||
export async function update(URL) {
|
||||
// Import the updater.
|
||||
const secretariat = await import(
|
||||
chrome.runtime.getURL("scripts/secretariat.js")
|
||||
);
|
||||
const net = await import(chrome.runtime.getURL("scripts/net.js"));
|
||||
const texts = await import(chrome.runtime.getURL("gui/scripts/read.js"));
|
||||
|
||||
// Apparently, JS doesn't have a native queueing system, but it might best work here.
|
||||
class Queue {
|
||||
constructor() {
|
||||
this.elements = [];
|
||||
}
|
||||
|
||||
enqueue(element) {
|
||||
this.elements.push(element);
|
||||
}
|
||||
|
||||
dequeue() {
|
||||
return this.elements.shift();
|
||||
}
|
||||
|
||||
isEmpty() {
|
||||
return this.elements.length <= 0;
|
||||
}
|
||||
export default class filters {
|
||||
constructor() {
|
||||
this.all = {};
|
||||
}
|
||||
|
||||
// Create a queue of the filters.
|
||||
let filters = new Queue();
|
||||
/* Select the most appropriate filter based on a URL.
|
||||
|
||||
if (URL) {
|
||||
// Check if the URL is in a valid protocol
|
||||
if (URL.includes(`://`)) {
|
||||
// Append that to the queue.
|
||||
filters.enqueue(URL);
|
||||
}
|
||||
} else {
|
||||
// Add every item to the queue based on what was loaded first.
|
||||
if ((await Promise.all([secretariat.read(`filters`, -1)]))[0]) {
|
||||
Object.keys(
|
||||
(await Promise.all([secretariat.read(`filters`, -1)]))[0],
|
||||
).every((filter_URL) => {
|
||||
if (filter_URL.includes(`://`)) {
|
||||
filters.enqueue(filter_URL);
|
||||
}
|
||||
});
|
||||
}
|
||||
@param {string} URL the current URL
|
||||
*/
|
||||
static select(URL = window.location.href) {
|
||||
this.one = {};
|
||||
}
|
||||
|
||||
if (!filters.isEmpty()) {
|
||||
while (!filters.isEmpty()) {
|
||||
let filter_URL = filters.dequeue();
|
||||
/* Update all filters or just one.
|
||||
|
||||
// Inform the user of download state.
|
||||
console.log(
|
||||
texts.read(`settings_filters_update_status`, null, [filter_URL]),
|
||||
@param {string} URL the URL to update
|
||||
@return {boolean} the state
|
||||
*/
|
||||
static update(URL) {
|
||||
(async () => {
|
||||
// Import the updater.
|
||||
const secretariat = await import(
|
||||
chrome.runtime.getURL("scripts/secretariat.js")
|
||||
);
|
||||
const net = await import(chrome.runtime.getURL("scripts/net.js"));
|
||||
const texts = (await import(chrome.runtime.getURL("gui/scripts/read.js")))
|
||||
.default;
|
||||
const alerts = (
|
||||
await import(chrome.runtime.getURL("gui/scripts/alerts.js"))
|
||||
).default;
|
||||
|
||||
// Create promise of downloading.
|
||||
let filter_download = net.download(filter_URL);
|
||||
filter_download
|
||||
.then((result) => {
|
||||
// Only work when the filter is valid.
|
||||
if (result) {
|
||||
// Write the filter to storage.
|
||||
secretariat.write(["filters", filter_URL], result, -1);
|
||||
console.log(
|
||||
texts.read(`settings_filters_update_status_complete`, null, [
|
||||
filter_URL,
|
||||
]),
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
// Inform the user of the download failure.
|
||||
console.log(
|
||||
texts.read(`settings_filters_update_status_failure`, null, [
|
||||
error,
|
||||
// Apparently, JS doesn't have a native queueing system, but it might best work here.
|
||||
class Queue {
|
||||
constructor() {
|
||||
this.elements = [];
|
||||
}
|
||||
|
||||
enqueue(element) {
|
||||
this.elements.push(element);
|
||||
}
|
||||
|
||||
dequeue() {
|
||||
return this.elements.shift();
|
||||
}
|
||||
|
||||
isEmpty() {
|
||||
return this.elements.length <= 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Create a queue of the filters.
|
||||
let filters = new Queue();
|
||||
|
||||
if (URL) {
|
||||
// Check if the URL is in a valid protocol
|
||||
if (URL.includes(`://`)) {
|
||||
// Append that to the queue.
|
||||
filters.enqueue(URL);
|
||||
}
|
||||
} else {
|
||||
// Add every item to the queue based on what was loaded first.
|
||||
if ((await Promise.all([secretariat.read(`filters`, -1)]))[0]) {
|
||||
Object.keys(
|
||||
(await Promise.all([secretariat.read(`filters`, -1)]))[0],
|
||||
).every((filter_URL) => {
|
||||
if (filter_URL.includes(`://`)) {
|
||||
filters.enqueue(filter_URL);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!filters.isEmpty()) {
|
||||
while (!filters.isEmpty()) {
|
||||
let filter_URL = filters.dequeue();
|
||||
|
||||
// Inform the user of download state.
|
||||
alerts.log(
|
||||
texts.localized(`settings_filters_update_status`, null, [
|
||||
filter_URL,
|
||||
]),
|
||||
);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Inform the user of the download being unnecessary.
|
||||
console.log(texts.read(`settings_filters_update_stop`));
|
||||
|
||||
// Create promise of downloading.
|
||||
let filter_download = net.download(filter_URL);
|
||||
filter_download
|
||||
.then((result) => {
|
||||
// Only work when the filter is valid.
|
||||
if (result) {
|
||||
// Write the filter to storage.
|
||||
secretariat.write(["filters", filter_URL], result, -1);
|
||||
console.log(
|
||||
texts.localized(
|
||||
`settings_filters_update_status_complete`,
|
||||
null,
|
||||
[filter_URL],
|
||||
),
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
// Inform the user of the download failure.
|
||||
console.log(
|
||||
texts.localized(
|
||||
`settings_filters_update_status_failure`,
|
||||
null,
|
||||
[error, filter_URL],
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Inform the user of the download being unnecessary.
|
||||
alerts.warn(texts.localized(`settings_filters_update_stop`));
|
||||
}
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,11 +27,11 @@ export async function read(DATA_NAME, CLOUD = 0, PARAMETER_TEST = null) {
|
|||
}
|
||||
|
||||
/*
|
||||
Find the data now.
|
||||
Get all dataset.
|
||||
|
||||
@param {number} SOURCE the data source
|
||||
*/
|
||||
function read_database(SOURCE = -1) {
|
||||
@param {number} SOURCE the data source
|
||||
*/
|
||||
async function read_database(SOURCE = -1) {
|
||||
let data = {};
|
||||
let data_returned;
|
||||
|
||||
|
@ -75,10 +75,10 @@ export async function read(DATA_NAME, CLOUD = 0, PARAMETER_TEST = null) {
|
|||
|
||||
/* Recursively find through each data, returning either that value or null when the object is not found.
|
||||
|
||||
@param {dictionary} DATA_ALL the data
|
||||
@param {object} DATA_PATH the path of the data
|
||||
@return {object} the data
|
||||
*/
|
||||
@param {dictionary} DATA_ALL the data
|
||||
@param {object} DATA_PATH the path of the data
|
||||
@return {object} the data
|
||||
*/
|
||||
function find_data(DATA_ALL, DATA_PATH, PARAMETER_TEST) {
|
||||
// Pull the data out.
|
||||
let DATA_PATH_SELECTED = String(DATA_PATH.shift()).trim();
|
||||
|
@ -185,9 +185,9 @@ export function write(PATH, DATA, CLOUD = -1) {
|
|||
|
||||
/* Forcibly write the data to chrome database
|
||||
|
||||
@param {object} DATA the data
|
||||
@param {number} CLOUD the storage
|
||||
*/
|
||||
@param {object} DATA the data
|
||||
@param {number} CLOUD the storage
|
||||
*/
|
||||
function write_database(DATA, CLOUD = 0) {
|
||||
// If CLOUD is set to 0, it should automatically determine where the previous source of data was taken from.
|
||||
|
||||
|
@ -200,11 +200,11 @@ export function write(PATH, DATA, CLOUD = -1) {
|
|||
|
||||
/* Appropriately nest and merge the data.
|
||||
|
||||
@param {object} EXISTING the original data
|
||||
@param {object} PATH the subpath
|
||||
@param {object} VALUE the value
|
||||
@return {object} the updated data
|
||||
*/
|
||||
@param {object} EXISTING the original data
|
||||
@param {object} PATH the subpath
|
||||
@param {object} VALUE the value
|
||||
@return {object} the updated data
|
||||
*/
|
||||
function nest(EXISTING, SUBPATH, VALUE) {
|
||||
let DATABASE = EXISTING;
|
||||
|
||||
|
@ -263,7 +263,9 @@ export function forget(preference, subpreference, CLOUD = 0) {
|
|||
|
||||
(async () => {
|
||||
// Import alerts module.
|
||||
let alerts = await import(chrome.runtime.getURL(`gui/scripts/alerts.js`));
|
||||
let alerts = (await import(chrome.runtime.getURL(`gui/scripts/alerts.js`)))[
|
||||
`alerts`
|
||||
];
|
||||
|
||||
// Confirm the action.
|
||||
let forget_action = alerts.confirm_action();
|
||||
|
@ -388,7 +390,7 @@ Run a script when the browser storage has been changed.
|
|||
|
||||
@param {object} reaction the function to run
|
||||
*/
|
||||
export async function observe(reaction) {
|
||||
export function observe(reaction) {
|
||||
chrome.storage.onChanged.addListener((changes, namespace) => {
|
||||
reaction(changes, namespace);
|
||||
});
|
||||
|
|
|
@ -7,8 +7,10 @@ Be sensitive to changes and update the state.
|
|||
let secretariat = await import(
|
||||
chrome.runtime.getURL("scripts/secretariat.js")
|
||||
);
|
||||
let filters = await import(chrome.runtime.getURL("scripts/filters.js"));
|
||||
let reader = await import(chrome.runtime.getURL("scripts/reader.js"));
|
||||
let filters = (await import(chrome.runtime.getURL("scripts/filters.js")))[
|
||||
`filters`
|
||||
];
|
||||
// let reader = await import(chrome.runtime.getURL("scripts/reader.js"));
|
||||
|
||||
class watchman {
|
||||
/* Check the current URL.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue