From 6c4d897306d7624b17b6b51a20c7debce357f579 Mon Sep 17 00:00:00 2001 From: achmizs Date: Fri, 1 Feb 2019 00:47:11 -0500 Subject: [PATCH] Added some comments to JS files --- background.js | 9 +++++++++ contentScript.js | 24 +++++++++++++++++++++++- functions.js | 4 ++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/background.js b/background.js index 04cbabf..4e61808 100644 --- a/background.js +++ b/background.js @@ -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", diff --git a/contentScript.js b/contentScript.js index 759d12e..1b86eea 100644 --- a/contentScript.js +++ b/contentScript.js @@ -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 }); } diff --git a/functions.js b/functions.js index 3aefe7e..525c62d 100644 --- a/functions.js +++ b/functions.js @@ -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 => {