read filters
can identify an appropriate filter for a website
This commit is contained in:
parent
a55b0af151
commit
1505ca7fb2
2 changed files with 120 additions and 65 deletions
|
@ -33,29 +33,58 @@ export default class secretariat {
|
|||
return(pref_data);
|
||||
};
|
||||
|
||||
static rules(domain = ``) {
|
||||
/* Load all of the rules or a rule from a particular domain.
|
||||
static rules(domain = window.location.href) {
|
||||
/* List the matching rule for a particular domain.
|
||||
|
||||
Parameters:
|
||||
domain: the RegEx of the domain
|
||||
domain: the website to check, which --- by default --- is the current website
|
||||
Returns: (dictionary) the rules
|
||||
*/
|
||||
|
||||
let result;
|
||||
|
||||
// Read the filters.
|
||||
let filters = read(`filters`);
|
||||
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
|
||||
*/
|
||||
|
||||
// Load the data.
|
||||
// Set the section in focus
|
||||
let section = filters[article];
|
||||
let qualified = false;
|
||||
|
||||
/*
|
||||
if (domain) {
|
||||
// Determine validity
|
||||
if (section) {
|
||||
// The filter must have a matching URL
|
||||
if (section[`URL`]) {
|
||||
// Now it's time to test it.
|
||||
qualified = (new RegExp(section[`URL`])).test(domain);
|
||||
if (qualified && section[`filters`]) {
|
||||
// Read that out.
|
||||
result = section;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
} else {
|
||||
};
|
||||
// The keys
|
||||
(Object.keys(filters)).forEach(reference);
|
||||
|
||||
}*/
|
||||
} else {
|
||||
// Get everything as instructed.
|
||||
result = filters;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
console.log(`Rules are being loaded...`);
|
||||
// Return the result.
|
||||
return(result);
|
||||
}
|
||||
|
||||
static amend(website, rules) {
|
||||
|
@ -68,6 +97,7 @@ export default class secretariat {
|
|||
*/
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
static write(prefname, data) {
|
||||
|
@ -84,6 +114,8 @@ export default class secretariat {
|
|||
static forget(domain) {
|
||||
/* Dangerous: Resets all data or a domain's data.
|
||||
|
||||
Parameters:
|
||||
domain: the external source of the filter
|
||||
Returns: the user's confirmation
|
||||
*/
|
||||
|
||||
|
@ -97,8 +129,13 @@ export default class secretariat {
|
|||
let forget_action = alerts.confirm_action();
|
||||
|
||||
if (forget_action) {
|
||||
// Clear the data storage.
|
||||
chrome.storage.local.clear();
|
||||
if (domain) {
|
||||
|
||||
} else {
|
||||
// Clear the data storage.
|
||||
chrome.storage.local.clear();
|
||||
chrome.storage.sync.clear();
|
||||
};
|
||||
};
|
||||
})();
|
||||
|
||||
|
@ -110,10 +147,9 @@ export function read(prefname) {
|
|||
return(secretariat.read(prefname));
|
||||
};
|
||||
|
||||
export function rules(domain = ``) {
|
||||
export function rules(domain = window.location.href) {
|
||||
return(secretariat.rules(domain));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
export function amend(website, rules) {
|
||||
return (secretariat.amend(website, rules));
|
||||
|
@ -122,4 +158,3 @@ export function amend(website, rules) {
|
|||
export function forget(domain) {
|
||||
return (secretariat.forget(domain));
|
||||
};
|
||||
|
||||
|
|
|
@ -13,22 +13,42 @@ Be sensitive to changes and update the state.
|
|||
|
||||
Parameters:
|
||||
URL: the page URL; default value is the current webpage
|
||||
Returns: (boolean) status
|
||||
Returns: (dictionary) the filter to follow
|
||||
*/
|
||||
|
||||
// Create the variable to determine the corresponding key.
|
||||
let key;
|
||||
let activity = false;
|
||||
let filters = secretariat.rules(URL);
|
||||
|
||||
secretariat.rules(URL);
|
||||
// Check if the filters exist.
|
||||
activity = (filters);
|
||||
|
||||
return (key);
|
||||
return (activity);
|
||||
};
|
||||
|
||||
static act() {
|
||||
static act(filters) {
|
||||
/* Act on the page.
|
||||
|
||||
Parameters:
|
||||
filters: the filter to work with
|
||||
Returns: the state
|
||||
*/
|
||||
|
||||
console.log("ShopAI works here! Click on the button in the toolbar or website to start.");
|
||||
// TODO
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
static job() {
|
||||
/* The main action. */
|
||||
let job_task = watchman.observe();
|
||||
if (job_task) {
|
||||
watchman.act(job_task);
|
||||
} else {
|
||||
console.log("ShopAI doesn't work here (yet). Expecting something? Try checking your filters. If you know what you're doing, feel free to create a filter yourself.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
watchman.job();
|
||||
|
||||
watchman.observe();
|
||||
watchman.act();
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue