update reading command

read filters or existing data
This commit is contained in:
buzzcode2007 2024-03-22 19:19:38 +08:00
parent 3f2f5e21a3
commit c038ed9812
2 changed files with 43 additions and 33 deletions

View file

@ -33,29 +33,27 @@ export default class secretariat {
return(pref_data); return(pref_data);
}; };
static rules(domain = window.location.href) { static specifics(WHERE, domain = window.location.href) {
/* List the matching rule for a particular domain. /* List the matching rule or memory for a particular domain.
Parameters: Parameters:
WHERE: the data source
domain: the website to check, which --- by default --- is the current website domain: the website to check, which --- by default --- is the current website
Returns: (dictionary) the rules Returns: (dictionary) the rules
*/ */
let result; let result;
let pref_data = read(WHERE);
// Read the filters. // Read the filters.
let filters = read(`filters`); switch (domain) {
case `filters`:
let filters = pref_data;
if (filters) { if (filters) {
// Must only run when there stored value. // Must only run when there stored value.
if (domain.trim()) { if (domain.trim()) {
// Function to loop through each object defined by their URL // Loop through each filter
function reference(article) { (Object.keys(filters)).forEach((article) => {
/* Skim through each one and set a matching find.
Parameters:
section: the URL to check
*/
// Set the section in focus // Set the section in focus
let section = filters[article]; let section = filters[article];
let qualified = false; let qualified = false;
@ -72,27 +70,39 @@ export default class secretariat {
}; };
}; };
}; };
});
};
// The keys
(Object.keys(filters)).forEach(reference);
} else { } else {
// Get everything as instructed. // Get everything as instructed.
result = filters; result = filters;
} }
}; };
break;
default:
// In the default mode, the keys refer to the product itself
if (pref_data) {
(Object.keys(pref_data)).forEach((product_URL) => {
// Get the first matching
if ((domain.trim()).includes(product_URL)) {
// Do not modify the data
result = pref_data[product_URL];
};
});
};
break;
};
// Return the result. // Return the result.
return(result); return(result);
} }
static amend(website, rules) { static amend(WHERE, website, datas) {
/* Update the rules. /* Update the rules.
Parameters: Parameters:
WHERE: the data set to update
website: RegEx pattern of the website or the domain website: RegEx pattern of the website or the domain
rules: the rules in JSON datas: the data in JSON
Returns: (boolean) the update status Returns: (boolean) the update status
*/ */
@ -147,8 +157,8 @@ export function read(prefname) {
return(secretariat.read(prefname)); return(secretariat.read(prefname));
}; };
export function rules(domain = window.location.href) { export function specifics(WHERE, domain = window.location.href) {
return(secretariat.rules(domain)); return(secretariat.specifics(WHERE, domain));
} }
export function amend(website, rules) { export function amend(website, rules) {

View file

@ -18,7 +18,7 @@ Be sensitive to changes and update the state.
// Create the variable to determine the corresponding key. // Create the variable to determine the corresponding key.
let activity = false; let activity = false;
let filters = secretariat.rules(URL); let filters = secretariat.specifics(`filters`, URL);
// Check if the filters exist. // Check if the filters exist.
activity = (filters); activity = (filters);