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,35 +33,33 @@ 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) {
if (filters) { case `filters`:
// Must only run when there stored value. let filters = pref_data;
if (domain.trim()) { if (filters) {
// Function to loop through each object defined by their URL // Must only run when there stored value.
function reference(article) { if (domain.trim()) {
/* Skim through each one and set a matching find. // Loop through each filter
(Object.keys(filters)).forEach((article) => {
// Set the section in focus
let section = filters[article];
let qualified = false;
Parameters: // Determine validity
section: the URL to check if (section) {
*/
// Set the section in focus
let section = filters[article];
let qualified = false;
// Determine validity
if (section) {
// The filter must have a matching URL // The filter must have a matching URL
if (section[`URL`]) { if (section[`URL`]) {
// Now it's time to test it. // Now it's time to test it.
@ -71,28 +69,40 @@ export default class secretariat {
result = section; result = section;
}; };
}; };
};
});
} else {
// Get everything as instructed.
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];
}; };
});
}; };
// The keys break;
(Object.keys(filters)).forEach(reference);
} else {
// Get everything as instructed.
result = filters;
}
}; };
// 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);