From 94d596d52564a9f78ed8540a1e633675e9b070ab Mon Sep 17 00:00:00 2001 From: achmizs Date: Thu, 31 Jan 2019 11:15:41 -0500 Subject: [PATCH] Added support for comments in pattern lists --- contentScript.js | 8 ++++++-- functions.js | 12 ++++++++---- options.js | 6 +++--- popup.js | 12 ++++++++---- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/contentScript.js b/contentScript.js index df74669..193dcdd 100644 --- a/contentScript.js +++ b/contentScript.js @@ -15,7 +15,9 @@ function killStickyIfMatch(result) { result.matchingPatterns.split("\n") : [ ]); 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; break; } @@ -24,7 +26,9 @@ function killStickyIfMatch(result) { result.exclusionPatterns.split("\n") : [ ]; 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; break; } diff --git a/functions.js b/functions.js index 7987a0d..3aefe7e 100644 --- a/functions.js +++ b/functions.js @@ -22,6 +22,14 @@ Element.prototype.removeActivateEvent = function() { this.removeEventListener("keyup", ael); } +/***********/ +/* UTILITY */ +/***********/ + +String.prototype.hasPrefix = function (prefix) { + return (this.lastIndexOf(prefix, 0) === 0); +} + /***********/ /* HELPERS */ /***********/ @@ -35,7 +43,3 @@ function killSticky() { } }); } - -String.prototype.hasPrefix = function (prefix) { - return (this.lastIndexOf(prefix, 0) === 0); -} diff --git a/options.js b/options.js index 1dc3ffb..cf82ee9 100644 --- a/options.js +++ b/options.js @@ -17,13 +17,13 @@ function toggleModeSelectorState(newMode) { let checkbox = document.querySelector("input#whitelist-mode"); 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 => { span.classList.toggle("disabled", false); }); document.querySelector(`.${newMode}-mode-label`).classList.toggle("disabled", true); - + document.querySelector("div#matchingPatterns").classList.toggle("disabled", (newMode == "whitelist")); document.querySelector("div#matchingPatterns textarea").disabled = (newMode == "whitelist"); } diff --git a/popup.js b/popup.js index 2cdadad..a91f09d 100644 --- a/popup.js +++ b/popup.js @@ -5,7 +5,7 @@ /* Toggle the current state, as represented in the ASK object. (Nothing actually happens until the UI state is updated, killSticky() is called (if needed), and the new settings are saved in storage.) - + What “toggle the current state” actually means depends on the current mode. [1] In blacklist mode, toggleState() does one of the following: @@ -15,7 +15,7 @@ exclusion patterns; or, (b) (if stickies are being killed on the current page) removes all applicable matching patterns. - + [2] In whitelist mode, toggleState() does one of the following: (a) (if stickies are not being killed on the current page) removes all @@ -69,13 +69,17 @@ function recalculatePatternEffects() { ASK.pageMatched = false; ASK.pageExcluded = false; 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; break; } } 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; break; }