|
|
|
|
|
|
|
|
// Retrieve saved settings. |
|
|
// Retrieve saved settings. |
|
|
chrome.tabs.query({currentWindow: true, active: true}, (tabs) => { |
|
|
chrome.tabs.query({currentWindow: true, active: true}, (tabs) => { |
|
|
AKS.activeTabLocation = tabs[0].url; |
|
|
AKS.activeTabLocation = tabs[0].url; |
|
|
|
|
|
AKS.activeTabID = tabs[0].id; |
|
|
chrome.storage.sync.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { |
|
|
chrome.storage.sync.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { |
|
|
updateState(result); |
|
|
updateState(result); |
|
|
updateUIState(); |
|
|
updateUIState(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Listener for main button. |
|
|
// Listener for main button. |
|
|
document.querySelector("button.main-button").addActivateEvent((event) => { |
|
|
document.querySelector("button.main-button").addActivateEvent((event) => { |
|
|
|
|
|
/* This doesn’t actually kill the stickies yet; that’s below, in the |
|
|
|
|
|
callback to storage.sync.set. */ |
|
|
toggleState(); |
|
|
toggleState(); |
|
|
|
|
|
|
|
|
|
|
|
// Prepare the changes for saving. |
|
|
var changes = { |
|
|
var changes = { |
|
|
"exclusionPatterns": AKS.exclusionPatterns.join("\n"), |
|
|
"exclusionPatterns": AKS.exclusionPatterns.join("\n"), |
|
|
"mode": AKS.mode |
|
|
"mode": AKS.mode |
|
|
}; |
|
|
}; |
|
|
if (AKS.mode == "blacklist") |
|
|
if (AKS.mode == "blacklist") |
|
|
changes.matchingPatterns = AKS.matchingPatterns.join("\n"); |
|
|
changes.matchingPatterns = AKS.matchingPatterns.join("\n"); |
|
|
|
|
|
|
|
|
|
|
|
// Save the changes. |
|
|
chrome.storage.sync.set(changes, () => { |
|
|
chrome.storage.sync.set(changes, () => { |
|
|
|
|
|
// Update the UI, once changes are saved. |
|
|
updateUIState(); |
|
|
updateUIState(); |
|
|
let reloadButton = document.querySelector("button.reload-button"); |
|
|
let reloadButton = document.querySelector("button.reload-button"); |
|
|
|
|
|
|
|
|
|
|
|
/* If need be, actually kill stickies on the current page. |
|
|
|
|
|
Otherwise, show the reload button. */ |
|
|
|
|
|
let shouldKillSticky = AKS.pageMatched && !AKS.pageExcluded; |
|
|
if (AKS.pageMatched && !AKS.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 { |
|
|
reloadButton.classList.toggle("active", true); |
|
|
reloadButton.classList.toggle("active", true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Update the page action (toolbar) icon. |
|
|
|
|
|
updateIcon(shouldKillSticky, AKS.activeTabID); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|