| result.matchingPatterns.split("\n") : | result.matchingPatterns.split("\n") : | ||||
| [ ]); | [ ]); | ||||
| for (let pattern of matchingPatterns) { | for (let pattern of matchingPatterns) { | ||||
| if (pattern && location.href.match(new RegExp(pattern))) { | |||||
| if (pattern && | |||||
| !pattern.hasPrefix("#") && | |||||
| location.href.match(new RegExp(pattern))) { | |||||
| shouldKillSticky = true; | shouldKillSticky = true; | ||||
| break; | break; | ||||
| } | } | ||||
| result.exclusionPatterns.split("\n") : | result.exclusionPatterns.split("\n") : | ||||
| [ ]; | [ ]; | ||||
| for (let pattern of exclusionPatterns) { | for (let pattern of exclusionPatterns) { | ||||
| if (pattern && location.href.match(new RegExp(pattern))) { | |||||
| if (pattern && | |||||
| !pattern.hasPrefix("#") && | |||||
| location.href.match(new RegExp(pattern))) { | |||||
| shouldKillSticky = false; | shouldKillSticky = false; | ||||
| break; | break; | ||||
| } | } |
| this.removeEventListener("keyup", ael); | this.removeEventListener("keyup", ael); | ||||
| } | } | ||||
| /***********/ | |||||
| /* UTILITY */ | |||||
| /***********/ | |||||
| String.prototype.hasPrefix = function (prefix) { | |||||
| return (this.lastIndexOf(prefix, 0) === 0); | |||||
| } | |||||
| /***********/ | /***********/ | ||||
| /* HELPERS */ | /* HELPERS */ | ||||
| /***********/ | /***********/ | ||||
| } | } | ||||
| }); | }); | ||||
| } | } | ||||
| String.prototype.hasPrefix = function (prefix) { | |||||
| return (this.lastIndexOf(prefix, 0) === 0); | |||||
| } |
| let checkbox = document.querySelector("input#whitelist-mode"); | let checkbox = document.querySelector("input#whitelist-mode"); | ||||
| newMode = newMode || (container.classList.contains("whitelist") ? "blacklist" : "whitelist"); | newMode = newMode || (container.classList.contains("whitelist") ? "blacklist" : "whitelist"); | ||||
| container.classList.toggle("whitelist", (newMode == "whitelist")); | |||||
| checkbox.checked = (newMode == "whitelist"); | |||||
| container.classList.toggle("whitelist", (newMode == "whitelist")); | |||||
| checkbox.checked = (newMode == "whitelist"); | |||||
| container.querySelectorAll("span").forEach(span => { | container.querySelectorAll("span").forEach(span => { | ||||
| span.classList.toggle("disabled", false); | span.classList.toggle("disabled", false); | ||||
| }); | }); | ||||
| document.querySelector(`.${newMode}-mode-label`).classList.toggle("disabled", true); | document.querySelector(`.${newMode}-mode-label`).classList.toggle("disabled", true); | ||||
| document.querySelector("div#matchingPatterns").classList.toggle("disabled", (newMode == "whitelist")); | document.querySelector("div#matchingPatterns").classList.toggle("disabled", (newMode == "whitelist")); | ||||
| document.querySelector("div#matchingPatterns textarea").disabled = (newMode == "whitelist"); | document.querySelector("div#matchingPatterns textarea").disabled = (newMode == "whitelist"); | ||||
| } | } |
| /* Toggle the current state, as represented in the ASK object. (Nothing actually | /* Toggle the current state, as represented in the ASK object. (Nothing actually | ||||
| happens until the UI state is updated, killSticky() is called (if needed), | happens until the UI state is updated, killSticky() is called (if needed), | ||||
| and the new settings are saved in storage.) | and the new settings are saved in storage.) | ||||
| What “toggle the current state” actually means depends on the current mode. | What “toggle the current state” actually means depends on the current mode. | ||||
| [1] In blacklist mode, toggleState() does one of the following: | [1] In blacklist mode, toggleState() does one of the following: | ||||
| exclusion patterns; or, | exclusion patterns; or, | ||||
| (b) (if stickies are being killed on the current page) removes all | (b) (if stickies are being killed on the current page) removes all | ||||
| applicable matching patterns. | applicable matching patterns. | ||||
| [2] In whitelist mode, toggleState() does one of the following: | [2] In whitelist mode, toggleState() does one of the following: | ||||
| (a) (if stickies are not being killed on the current page) removes all | (a) (if stickies are not being killed on the current page) removes all | ||||
| ASK.pageMatched = false; | ASK.pageMatched = false; | ||||
| ASK.pageExcluded = false; | ASK.pageExcluded = false; | ||||
| for (let pattern of ASK.matchingPatterns) { | for (let pattern of ASK.matchingPatterns) { | ||||
| if (pattern && ASK.activeTabLocation.match(new RegExp(pattern))) { | |||||
| if (pattern && | |||||
| !pattern.hasPrefix("#") && | |||||
| ASK.activeTabLocation.match(new RegExp(pattern))) { | |||||
| ASK.pageMatched = true; | ASK.pageMatched = true; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| for (let pattern of ASK.exclusionPatterns) { | for (let pattern of ASK.exclusionPatterns) { | ||||
| if (pattern && ASK.activeTabLocation.match(new RegExp(pattern))) { | |||||
| if (pattern && | |||||
| !pattern.hasPrefix("#") && | |||||
| ASK.activeTabLocation.match(new RegExp(pattern))) { | |||||
| ASK.pageExcluded = true; | ASK.pageExcluded = true; | ||||
| break; | break; | ||||
| } | } |