Selaa lähdekoodia

Added some comments to JS files

master
Said Achmiz 6 vuotta sitten
vanhempi
commit
6c4d897306
3 muutettua tiedostoa jossa 36 lisäystä ja 1 poistoa
  1. 9
    0
      background.js
  2. 23
    1
      contentScript.js
  3. 4
    0
      functions.js

+ 9
- 0
background.js Näytä tiedosto

/* Enables the page action (i.e., the browser toolbar icon).
*/
chrome.runtime.onInstalled.addListener(() => { chrome.runtime.onInstalled.addListener(() => {
chrome.declarativeContent.onPageChanged.removeRules(undefined, () => { chrome.declarativeContent.onPageChanged.removeRules(undefined, () => {
chrome.declarativeContent.onPageChanged.addRules([{ chrome.declarativeContent.onPageChanged.addRules([{
}); });
}); });


/* 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) => { chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
let icons = request.killingStickies ? { let icons = request.killingStickies ? {
"16": "images/ASK_on_16.png", "16": "images/ASK_on_16.png",

+ 23
- 1
contentScript.js Näytä tiedosto

/* HELPERS */ /* 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) { function checkForShouldKillSticky(result) {
var shouldKillSticky = false; 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" ? let matchingPatterns = result.mode == "whitelist" ?
[ ".*" ] : [ ".*" ] :
(typeof result.matchingPatterns != "undefined" ? (typeof result.matchingPatterns != "undefined" ?
return shouldKillSticky; 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) { function updateIcon(shouldKillSticky) {
chrome.runtime.sendMessage({ "killingStickies" : shouldKillSticky }); chrome.runtime.sendMessage({ "killingStickies" : shouldKillSticky });
} }

+ 4
- 0
functions.js Näytä tiedosto

/* HELPERS */ /* 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() { function killSticky() {
console.log("Killing all stickies!"); console.log("Killing all stickies!");
document.querySelectorAll('body *').forEach(element => { document.querySelectorAll('body *').forEach(element => {

Loading…
Peruuta
Tallenna