update reading command
read filters or existing data
This commit is contained in:
parent
3f2f5e21a3
commit
c038ed9812
2 changed files with 43 additions and 33 deletions
|
@ -33,29 +33,27 @@ export default class secretariat {
|
|||
return(pref_data);
|
||||
};
|
||||
|
||||
static rules(domain = window.location.href) {
|
||||
/* List the matching rule for a particular domain.
|
||||
static specifics(WHERE, domain = window.location.href) {
|
||||
/* List the matching rule or memory for a particular domain.
|
||||
|
||||
Parameters:
|
||||
WHERE: the data source
|
||||
domain: the website to check, which --- by default --- is the current website
|
||||
Returns: (dictionary) the rules
|
||||
*/
|
||||
|
||||
let result;
|
||||
|
||||
let pref_data = read(WHERE);
|
||||
// Read the filters.
|
||||
let filters = read(`filters`);
|
||||
switch (domain) {
|
||||
case `filters`:
|
||||
let filters = pref_data;
|
||||
if (filters) {
|
||||
// Must only run when there stored value.
|
||||
if (domain.trim()) {
|
||||
// Function to loop through each object defined by their URL
|
||||
function reference(article) {
|
||||
/* Skim through each one and set a matching find.
|
||||
|
||||
Parameters:
|
||||
section: the URL to check
|
||||
*/
|
||||
|
||||
// Loop through each filter
|
||||
(Object.keys(filters)).forEach((article) => {
|
||||
// Set the section in focus
|
||||
let section = filters[article];
|
||||
let qualified = false;
|
||||
|
@ -72,27 +70,39 @@ export default class secretariat {
|
|||
};
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
// The keys
|
||||
(Object.keys(filters)).forEach(reference);
|
||||
});
|
||||
|
||||
} 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];
|
||||
};
|
||||
});
|
||||
};
|
||||
break;
|
||||
};
|
||||
|
||||
// Return the result.
|
||||
return(result);
|
||||
}
|
||||
|
||||
static amend(website, rules) {
|
||||
static amend(WHERE, website, datas) {
|
||||
/* Update the rules.
|
||||
|
||||
Parameters:
|
||||
WHERE: the data set to update
|
||||
website: RegEx pattern of the website or the domain
|
||||
rules: the rules in JSON
|
||||
datas: the data in JSON
|
||||
Returns: (boolean) the update status
|
||||
*/
|
||||
|
||||
|
@ -147,8 +157,8 @@ export function read(prefname) {
|
|||
return(secretariat.read(prefname));
|
||||
};
|
||||
|
||||
export function rules(domain = window.location.href) {
|
||||
return(secretariat.rules(domain));
|
||||
export function specifics(WHERE, domain = window.location.href) {
|
||||
return(secretariat.specifics(WHERE, domain));
|
||||
}
|
||||
|
||||
export function amend(website, rules) {
|
||||
|
|
|
@ -18,7 +18,7 @@ Be sensitive to changes and update the state.
|
|||
|
||||
// Create the variable to determine the corresponding key.
|
||||
let activity = false;
|
||||
let filters = secretariat.rules(URL);
|
||||
let filters = secretariat.specifics(`filters`, URL);
|
||||
|
||||
// Check if the filters exist.
|
||||
activity = (filters);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue