Added some comments to JS files
This commit is contained in:
parent
691573b45f
commit
6c4d897306
@ -1,3 +1,5 @@
|
||||
/* Enables the page action (i.e., the browser toolbar icon).
|
||||
*/
|
||||
chrome.runtime.onInstalled.addListener(() => {
|
||||
chrome.declarativeContent.onPageChanged.removeRules(undefined, () => {
|
||||
chrome.declarativeContent.onPageChanged.addRules([{
|
||||
@ -9,6 +11,13 @@ chrome.runtime.onInstalled.addListener(() => {
|
||||
});
|
||||
});
|
||||
|
||||
/* Toggle the toolbar icon based on whether stickies are, or are not, set to
|
||||
be killed on the current tab.
|
||||
|
||||
This listener receives a message from the content script (contentScript.js);
|
||||
the content script actually determines what the settings for the current
|
||||
tab are.
|
||||
*/
|
||||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
let icons = request.killingStickies ? {
|
||||
"16": "images/ASK_on_16.png",
|
||||
|
||||
@ -2,9 +2,27 @@
|
||||
/* HELPERS */
|
||||
/***********/
|
||||
|
||||
/* Given the result of a query to storage (for the matching and exclusion
|
||||
pattern lists, and the current mode - whitelist or blacklist), this function
|
||||
determines whether stickies should be killed on the currently loaded page.
|
||||
|
||||
Stickies are killed if the following is true:
|
||||
|
||||
(blacklist mode is active, AND
|
||||
at least one matching pattern matches the URL of the current page, AND
|
||||
zero exclusion patterns match the URL of the current page)
|
||||
OR
|
||||
(whitelist mode is active, AND
|
||||
zero exclusion matters match the URL of the current page)
|
||||
*/
|
||||
function checkForShouldKillSticky(result) {
|
||||
var shouldKillSticky = false;
|
||||
|
||||
|
||||
/* If whitelist mode is active, then the matching patterns list is treated
|
||||
as containing a single pattern which will match all possible URLs.
|
||||
Patterns that are empty strings (i.e., blank lines in the patterns
|
||||
lists) are ignored, as are any patterns that begin with a pound sign (#)
|
||||
(this allows for comments in the patterns lists). */
|
||||
let matchingPatterns = result.mode == "whitelist" ?
|
||||
[ ".*" ] :
|
||||
(typeof result.matchingPatterns != "undefined" ?
|
||||
@ -33,6 +51,10 @@ function checkForShouldKillSticky(result) {
|
||||
return shouldKillSticky;
|
||||
}
|
||||
|
||||
/* This function sends a message to the background script (background.js),
|
||||
which then updates the page action icon (i.e., the browser toolbar icon)
|
||||
to reflect whether killing stickies is enabled on the current page.
|
||||
*/
|
||||
function updateIcon(shouldKillSticky) {
|
||||
chrome.runtime.sendMessage({ "killingStickies" : shouldKillSticky });
|
||||
}
|
||||
|
||||
@ -34,6 +34,10 @@ String.prototype.hasPrefix = function (prefix) {
|
||||
/* HELPERS */
|
||||
/***********/
|
||||
|
||||
/* This is the code that actually does the sticky killing! It simply selects
|
||||
all elements whose 'position' CSS property has a computed value of either
|
||||
'sticky' or 'fixed', and removes those elements.
|
||||
*/
|
||||
function killSticky() {
|
||||
console.log("Killing all stickies!");
|
||||
document.querySelectorAll('body *').forEach(element => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user