| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- /***********/
- /* HELPERS */
- /***********/
-
- /* Given the result of a query to storage (for the matching and exclusion
- pattern lists, and the current mode - whitelist or blacklist), this function
- determines whether stickies should be killed on the currently loaded page.
-
- Stickies are killed if the following is true:
-
- (blacklist mode is active, AND
- at least one matching pattern matches the URL of the current page, AND
- zero exclusion patterns match the URL of the current page)
- OR
- (whitelist mode is active, AND
- zero exclusion matters match the URL of the current page)
- */
- function checkForShouldKillSticky(result) {
- var shouldKillSticky = false;
-
- /* If whitelist mode is active, then the matching patterns list is treated
- as containing a single pattern which will match all possible URLs.
- Patterns that are empty strings (i.e., blank lines in the patterns
- lists) are ignored, as are any patterns that begin with a pound sign (#)
- (this allows for comments in the patterns lists). */
- let matchingPatterns = result.mode == "whitelist" ?
- [ ".*" ] :
- (typeof result.matchingPatterns != "undefined" ?
- result.matchingPatterns.split("\n") :
- [ ]);
- for (let pattern of matchingPatterns) {
- if (pattern &&
- !pattern.hasPrefix("#") &&
- location.href.match(new RegExp(pattern))) {
- shouldKillSticky = true;
- break;
- }
- }
- let exclusionPatterns = typeof result.exclusionPatterns != "undefined" ?
- result.exclusionPatterns.split("\n") :
- [ ];
- for (let pattern of exclusionPatterns) {
- if (pattern &&
- !pattern.hasPrefix("#") &&
- location.href.match(new RegExp(pattern))) {
- shouldKillSticky = false;
- break;
- }
- }
-
- return shouldKillSticky;
- }
-
- /******************/
- /* INITIALIZATION */
- /******************/
-
- function initialize() {
- chrome.storage.sync.get([ "matchingPatterns", "exclusionPatterns", "mode" ],
- (result) => {
- let shouldKillSticky = checkForShouldKillSticky(result);
- updateIcon(shouldKillSticky);
- window.onload = () => {
- if (shouldKillSticky) killSticky();
- };
- });
- }
- initialize();
|