/***********/ /* HELPERS */ /***********/ function checkForShouldKillSticky(result) { var shouldKillSticky = false; 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; } function updateIcon(shouldKillSticky) { chrome.runtime.sendMessage({ "killingStickies" : shouldKillSticky }); } /******************/ /* INITIALIZATION */ /******************/ function initialize() { chrome.storage.sync.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { let shouldKillSticky = checkForShouldKillSticky(result); updateIcon(shouldKillSticky); window.onload = () => { if (shouldKillSticky) killSticky(); }; }); } initialize();