Corrected 'ASK' to 'AKS' in code

This commit is contained in:
Said Achmiz 2019-02-01 00:27:05 -05:00
parent 52d68df2d7
commit 691573b45f

View File

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