| /* In this case, stickies are NOT being killed. We must add a matching | /* In this case, stickies are NOT being killed. We must add a matching | ||||
| pattern, and remove all applicable exclusion patterns. */ | pattern, and remove all applicable exclusion patterns. */ | ||||
| if (!ASK.pageMatched) { | if (!ASK.pageMatched) { | ||||
| ASK.matchingPatterns.push(regExpForCurrentTab()); | |||||
| addPatternForCurrentTab(ASK.matchingPatterns); | |||||
| } | } | ||||
| if (ASK.pageExcluded) { | if (ASK.pageExcluded) { | ||||
| ASK.exclusionPatterns = ASK.exclusionPatterns.filter(pattern => | |||||
| !ASK.activeTabLocation.match(new RegExp(pattern)) | |||||
| ); | |||||
| disablePatternsForCurrentTab(ASK.exclusionPatterns); | |||||
| } | } | ||||
| } else { | } else { | ||||
| /* In this case, stickies ARE being killed. We must remove all | /* In this case, stickies ARE being killed. We must remove all | ||||
| applicable matching patterns. */ | applicable matching patterns. */ | ||||
| ASK.matchingPatterns = ASK.matchingPatterns.filter(pattern => | |||||
| !ASK.activeTabLocation.match(new RegExp(pattern)) | |||||
| ); | |||||
| disablePatternsForCurrentTab(ASK.matchingPatterns); | |||||
| } | } | ||||
| } else { // if whitelist mode | } else { // if whitelist mode | ||||
| if (ASK.pageExcluded) { | if (ASK.pageExcluded) { | ||||
| /* In this case, stickies are NOT being killed. We must remove all | /* In this case, stickies are NOT being killed. We must remove all | ||||
| applicable exclusion patterns. */ | applicable exclusion patterns. */ | ||||
| ASK.exclusionPatterns = ASK.exclusionPatterns.filter(pattern => | |||||
| !ASK.activeTabLocation.match(new RegExp(pattern)) | |||||
| ); | |||||
| disablePatternsForCurrentTab(ASK.exclusionPatterns); | |||||
| } else { | } else { | ||||
| /* In this case, stickies ARE being killed. We must add an exclusion | /* In this case, stickies ARE being killed. We must add an exclusion | ||||
| pattern. */ | pattern. */ | ||||
| ASK.exclusionPatterns.push(regExpForCurrentTab()); | |||||
| addPatternForCurrentTab(ASK.exclusionPatterns); | |||||
| } | } | ||||
| } | } | ||||
| recalculatePatternEffects(); | recalculatePatternEffects(); | ||||
| } | } | ||||
| function addPatternForCurrentTab(patterns) { | |||||
| /* First, we see if there are already any existing but commented-out | |||||
| patterns that match the active tab. If so, we enable them all. */ | |||||
| var existingPatternsFound = false; | |||||
| for (var i = 0; i < patterns.length; i++) { | |||||
| if (patterns[i] && patterns[i].hasPrefix("#")) { | |||||
| // 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 so, replace the commented pattern. | |||||
| patterns[i] = uncommentedPattern; | |||||
| existingPatternsFound = true; | |||||
| } | |||||
| } | |||||
| } | |||||
| if (existingPatternsFound) return; | |||||
| /* If no existing but commented-out patterns have been found, then we’ve | |||||
| 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(regExpForCurrentTab()); | |||||
| patterns.push(""); | |||||
| } | |||||
| function disablePatternsForCurrentTab(patterns) { | |||||
| for (var i = 0; i < patterns.length; i++) { | |||||
| if (patterns[i] && ASK.activeTabLocation.match(new RegExp(patterns[i]))) | |||||
| patterns[i] = "# " + patterns[i]; | |||||
| } | |||||
| } | |||||
| function regExpForCurrentTab() { | function regExpForCurrentTab() { | ||||
| let a = document.createElement("A"); | let a = document.createElement("A"); | ||||
| a.href = ASK.activeTabLocation; | a.href = ASK.activeTabLocation; |