| @@ -2,7 +2,7 @@ | |||
| /* HELPERS */ | |||
| /***********/ | |||
| /* Toggle the current state, as represented in the ASK object. (Nothing actually | |||
| /* Toggle the current state, as represented in the AKS object. (Nothing actually | |||
| happens until the UI state is updated, killSticky() is called (if needed), | |||
| and the new settings are saved in storage.) | |||
| @@ -24,30 +24,30 @@ | |||
| pattern. | |||
| */ | |||
| function toggleState() { | |||
| if (ASK.mode == "blacklist") { | |||
| if (!ASK.pageMatched || ASK.pageExcluded) { | |||
| if (AKS.mode == "blacklist") { | |||
| if (!AKS.pageMatched || AKS.pageExcluded) { | |||
| /* In this case, stickies are NOT being killed. We must add a matching | |||
| pattern, and remove all applicable exclusion patterns. */ | |||
| if (!ASK.pageMatched) { | |||
| addPatternForCurrentTab(ASK.matchingPatterns); | |||
| if (!AKS.pageMatched) { | |||
| addPatternForCurrentTab(AKS.matchingPatterns); | |||
| } | |||
| if (ASK.pageExcluded) { | |||
| disablePatternsForCurrentTab(ASK.exclusionPatterns); | |||
| if (AKS.pageExcluded) { | |||
| disablePatternsForCurrentTab(AKS.exclusionPatterns); | |||
| } | |||
| } else { | |||
| /* In this case, stickies ARE being killed. We must remove all | |||
| applicable matching patterns. */ | |||
| disablePatternsForCurrentTab(ASK.matchingPatterns); | |||
| disablePatternsForCurrentTab(AKS.matchingPatterns); | |||
| } | |||
| } else { // if whitelist mode | |||
| if (ASK.pageExcluded) { | |||
| if (AKS.pageExcluded) { | |||
| /* In this case, stickies are NOT being killed. We must remove all | |||
| applicable exclusion patterns. */ | |||
| disablePatternsForCurrentTab(ASK.exclusionPatterns); | |||
| disablePatternsForCurrentTab(AKS.exclusionPatterns); | |||
| } else { | |||
| /* In this case, stickies ARE being killed. We must add an exclusion | |||
| pattern. */ | |||
| addPatternForCurrentTab(ASK.exclusionPatterns); | |||
| addPatternForCurrentTab(AKS.exclusionPatterns); | |||
| } | |||
| } | |||
| recalculatePatternEffects(); | |||
| @@ -62,7 +62,7 @@ function addPatternForCurrentTab(patterns) { | |||
| // Strip the leading comment characters and whitespace. | |||
| let uncommentedPattern = patterns[i].replace(/^#[#\s]*/, ""); | |||
| // Check if the pattern matches the active tab’s URL. | |||
| if (ASK.activeTabLocation.match(new RegExp(uncommentedPattern))) { | |||
| if (AKS.activeTabLocation.match(new RegExp(uncommentedPattern))) { | |||
| // If so, replace the commented pattern. | |||
| patterns[i] = uncommentedPattern; | |||
| existingPatternsFound = true; | |||
| @@ -75,53 +75,53 @@ function addPatternForCurrentTab(patterns) { | |||
| got to add a new pattern. */ | |||
| let dtf = new Intl.DateTimeFormat([], | |||
| { month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric' }); | |||
| patterns.push("## " + dtf.format(new Date()) + " - " + ASK.activeTabLocation); | |||
| patterns.push("## " + dtf.format(new Date()) + " - " + AKS.activeTabLocation); | |||
| patterns.push(regExpForCurrentTab()); | |||
| patterns.push(""); | |||
| } | |||
| function disablePatternsForCurrentTab(patterns) { | |||
| for (var i = 0; i < patterns.length; i++) { | |||
| if (patterns[i] && ASK.activeTabLocation.match(new RegExp(patterns[i]))) | |||
| if (patterns[i] && AKS.activeTabLocation.match(new RegExp(patterns[i]))) | |||
| patterns[i] = "# " + patterns[i]; | |||
| } | |||
| } | |||
| function regExpForCurrentTab() { | |||
| let a = document.createElement("A"); | |||
| a.href = ASK.activeTabLocation; | |||
| a.href = AKS.activeTabLocation; | |||
| return ".*" + a.host.replace(/\./g, "\\.") + ".*"; | |||
| } | |||
| function recalculatePatternEffects() { | |||
| ASK.pageMatched = false; | |||
| ASK.pageExcluded = false; | |||
| for (let pattern of ASK.matchingPatterns) { | |||
| AKS.pageMatched = false; | |||
| AKS.pageExcluded = false; | |||
| for (let pattern of AKS.matchingPatterns) { | |||
| if (pattern && | |||
| !pattern.hasPrefix("#") && | |||
| ASK.activeTabLocation.match(new RegExp(pattern))) { | |||
| ASK.pageMatched = true; | |||
| AKS.activeTabLocation.match(new RegExp(pattern))) { | |||
| AKS.pageMatched = true; | |||
| break; | |||
| } | |||
| } | |||
| for (let pattern of ASK.exclusionPatterns) { | |||
| for (let pattern of AKS.exclusionPatterns) { | |||
| if (pattern && | |||
| !pattern.hasPrefix("#") && | |||
| ASK.activeTabLocation.match(new RegExp(pattern))) { | |||
| ASK.pageExcluded = true; | |||
| AKS.activeTabLocation.match(new RegExp(pattern))) { | |||
| AKS.pageExcluded = true; | |||
| break; | |||
| } | |||
| } | |||
| } | |||
| function updateState(result) { | |||
| ASK.mode = result.mode || "blacklist"; | |||
| ASK.matchingPatterns = (ASK.mode == "whitelist") ? | |||
| AKS.mode = result.mode || "blacklist"; | |||
| AKS.matchingPatterns = (AKS.mode == "whitelist") ? | |||
| [ ".*" ] : | |||
| (typeof result.matchingPatterns != "undefined" ? | |||
| result.matchingPatterns.split("\n") : | |||
| [ ]); | |||
| ASK.exclusionPatterns = typeof result.exclusionPatterns != "undefined" ? | |||
| AKS.exclusionPatterns = typeof result.exclusionPatterns != "undefined" ? | |||
| result.exclusionPatterns.split("\n") : | |||
| [ ]; | |||
| recalculatePatternEffects(); | |||
| @@ -132,14 +132,14 @@ function updateUIState() { | |||
| let info = document.querySelector(".info"); | |||
| let statusLabel = document.querySelector(".info .status-display"); | |||
| var active, whitelist; | |||
| if (ASK.mode == "blacklist") { | |||
| if (ASK.pageMatched && !ASK.pageExcluded) { | |||
| if (AKS.mode == "blacklist") { | |||
| if (AKS.pageMatched && !AKS.pageExcluded) { | |||
| active = true; | |||
| } else { | |||
| active = false; | |||
| } | |||
| } else { | |||
| if (!ASK.pageExcluded) { | |||
| if (!AKS.pageExcluded) { | |||
| active = false; | |||
| } else { | |||
| active = true; | |||
| @@ -149,8 +149,8 @@ function updateUIState() { | |||
| mainButton.classList.toggle("active", active); | |||
| statusLabel.classList.toggle("active", active); | |||
| mainButton.classList.toggle("whitelist", (ASK.mode == "whitelist")); | |||
| info.classList.toggle("whitelist", (ASK.mode == "whitelist")); | |||
| mainButton.classList.toggle("whitelist", (AKS.mode == "whitelist")); | |||
| info.classList.toggle("whitelist", (AKS.mode == "whitelist")); | |||
| } | |||
| /******************/ | |||
| @@ -158,14 +158,14 @@ function updateUIState() { | |||
| /******************/ | |||
| function initialize() { | |||
| window.ASK = { }; | |||
| window.AKS = { }; | |||
| // Update version. | |||
| document.querySelector(".info-header .version").innerHTML = chrome.runtime.getManifest().version; | |||
| // Retrieve saved settings. | |||
| chrome.tabs.query({currentWindow: true, active: true}, (tabs) => { | |||
| ASK.activeTabLocation = tabs[0].url; | |||
| AKS.activeTabLocation = tabs[0].url; | |||
| chrome.storage.sync.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { | |||
| updateState(result); | |||
| updateUIState(); | |||
| @@ -177,15 +177,15 @@ function initialize() { | |||
| toggleState(); | |||
| var changes = { | |||
| "exclusionPatterns": ASK.exclusionPatterns.join("\n"), | |||
| "mode": ASK.mode | |||
| "exclusionPatterns": AKS.exclusionPatterns.join("\n"), | |||
| "mode": AKS.mode | |||
| }; | |||
| if (ASK.mode == "blacklist") | |||
| changes.matchingPatterns = ASK.matchingPatterns.join("\n"); | |||
| if (AKS.mode == "blacklist") | |||
| changes.matchingPatterns = AKS.matchingPatterns.join("\n"); | |||
| chrome.storage.sync.set(changes, () => { | |||
| updateUIState(); | |||
| let reloadButton = document.querySelector("button.reload-button"); | |||
| if (ASK.pageMatched && !ASK.pageExcluded) { | |||
| if (AKS.pageMatched && !AKS.pageExcluded) { | |||
| chrome.tabs.executeScript(null, { code: 'killSticky()' }); | |||
| reloadButton.classList.toggle("active", false); | |||
| } else { | |||
| @@ -206,7 +206,7 @@ function initialize() { | |||
| // Listener for reload button (appears when sticky-killing is toggled OFF). | |||
| document.querySelector("button.reload-button").addActivateEvent(() => { | |||
| chrome.tabs.update(null, { url: ASK.activeTabLocation }); | |||
| chrome.tabs.update(null, { url: AKS.activeTabLocation }); | |||
| window.close(); | |||
| }); | |||
| } | |||