瀏覽代碼

Added option to disable count of blocked elements

Added another toggle to the options page to disable the count of blocked
sticky headers. This is modeled off the uBlock origin option which does
the same thing.
master
Rohit Patnaik 5 年之前
父節點
當前提交
49818bf8c2
共有 4 個文件被更改,包括 82 次插入12 次删除
  1. 19
    4
      src/contentScript.js
  2. 40
    0
      src/options.css
  3. 3
    3
      src/options.html
  4. 20
    5
      src/options.js

+ 19
- 4
src/contentScript.js 查看文件



function incrementKilledStickiesCount() { function incrementKilledStickiesCount() {
// console.log("incrementKilledStickiesCount"); // console.log("incrementKilledStickiesCount");
AKS.stickiesKilled++;
chrome.runtime.sendMessage({ newBadgeText: "" + AKS.stickiesKilled });
console.log("Hiding stickies: " + AKS.hideKillCount); //DEBUG
if (!AKS.hideKillCount) {
AKS.stickiesKilled++;
chrome.runtime.sendMessage({ newBadgeText: "" + AKS.stickiesKilled });
}
} }


/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
*/ */
function beginKillingStickies() { function beginKillingStickies() {
// console.log("beginKillingStickies"); // console.log("beginKillingStickies");
if (!window.AKS) window.AKS = { stickiesKilled: 0 };
if (!window.AKS) {
window.AKS = { stickiesKilled: 0 };
}
else {
window.AKS.stickiesKilled = 0;
}


window.requestIdleCallback(() => { window.requestIdleCallback(() => {
killSticky(); killSticky();


function initialize() { function initialize() {
// console.log("initialize"); // console.log("initialize");
chrome.storage.local.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => {
chrome.storage.local.get([ "matchingPatterns", "exclusionPatterns", "mode", "hideKillCount" ], (result) => {
let shouldKillSticky = checkForShouldKillSticky(result); let shouldKillSticky = checkForShouldKillSticky(result);
updateIcon(shouldKillSticky); updateIcon(shouldKillSticky);
const hideKillCount = result.hideKillCount ? true : false;
if (!window.AKS){
window.AKS = {hideKillCount: hideKillCount};
}
else {
window.AKS.hideKillCount = hideKillCount;
}
if (shouldKillSticky) { if (shouldKillSticky) {
if (document.readyState == "loading") { if (document.readyState == "loading") {
document.addEventListener("DOMContentLoaded", beginKillingStickies); document.addEventListener("DOMContentLoaded", beginKillingStickies);

+ 40
- 0
src/options.css 查看文件

border-bottom: 1px solid currentColor; border-bottom: 1px solid currentColor;
} }


/*********************/
/* KILL COUNT TOGGLE */
/*********************/

input#hide-kill-count {
display: block;
-webkit-appearance: none;
-moz-appearance: none;
border: 1px solid #000;
font-size: 1rem;
height: 2em;
width: 4em;
margin: 0 6px;
background-color: #000;
box-shadow:
-2em 0 0 1px #fff inset,
0 0 0 3px #fff inset;
}

input#hide-kill-count:checked {
border: 1px solid #fff;
background-color: #fff;
box-shadow:
2em 0 0 1px #000 inset,
0 0 0 3px #000 inset;
}

.enable-stickies-killed-count-container {
white-space: nowrap;
display: flex;
align-items: center;
align-self: flex-start;
border: 1px solid #ddd;
padding: 8px 10px;
cursor: default;
background-color: #fff;
margin-top: 15px;
}


/******************/ /******************/
/* WHITELIST MODE */ /* WHITELIST MODE */
/******************/ /******************/

+ 3
- 3
src/options.html 查看文件

<input type='checkbox' id='whitelist-mode'></input> <input type='checkbox' id='whitelist-mode'></input>
<span class='whitelist-mode-label'>Whitelist mode</span> <span class='whitelist-mode-label'>Whitelist mode</span>
</span> </span>
<span class='display-stickies-killed-container'>
<span class='enable-stickes-killed-count'>Show killed stickies count</span>
<input type='checkbox' id='display-kill-count'>
<span class='enable-stickies-killed-count-container'>
<span class='enable-stickies-killed-count'>Show killed stickies count</span>
<input type='checkbox' id='hide-kill-count'>
<span class='disable-stickies-killed-count'>Hide killed stickies count</span> <span class='disable-stickies-killed-count'>Hide killed stickies count</span>
</span> </span>
<span class='buttons'> <span class='buttons'>

+ 20
- 5
src/options.js 查看文件

/* /*
* Triggered when a click is received by the kill count display switch * Triggered when a click is received by the kill count display switch
*/ */
function showKillCountInputReceived() {
function hideKillCountInputReceived() {
setButtonsActive(true); setButtonsActive(true);
} }


document.querySelector("div#matchingPatterns textarea").disabled = (newMode == "whitelist"); document.querySelector("div#matchingPatterns textarea").disabled = (newMode == "whitelist");
} }


/*
* Sets the kill count selector state
* Used by resetChanges()
*/
function setHideKillCountSelectorState(hideKillCount) {
let checkbox = document.querySelector("input#hide-kill-count");
checkbox.checked = hideKillCount;
}

/* Saves the entered state in storage. /* Saves the entered state in storage.
De-activate the "Reset" and "Save" buttons. De-activate the "Reset" and "Save" buttons.
*/ */
let matchingPatterns = document.querySelector("#matchingPatterns textarea").value; let matchingPatterns = document.querySelector("#matchingPatterns textarea").value;
let exclusionPatterns = document.querySelector("#exclusionPatterns textarea").value; let exclusionPatterns = document.querySelector("#exclusionPatterns textarea").value;
let mode = document.querySelector("input#whitelist-mode").checked ? "whitelist" : "blacklist"; let mode = document.querySelector("input#whitelist-mode").checked ? "whitelist" : "blacklist";
let hideKillCount = document.querySelector("input#hide-kill-count").checked ? true : false;
console.log("In saveChanges, hideKillCount: " + hideKillCount); //DEBUG
chrome.storage.local.set({ chrome.storage.local.set({
"matchingPatterns": matchingPatterns, "matchingPatterns": matchingPatterns,
"exclusionPatterns": exclusionPatterns, "exclusionPatterns": exclusionPatterns,
"mode": mode
"mode": mode,
"hideKillCount": hideKillCount
}, () => { }, () => {
let error = chrome.runtime.lastError; let error = chrome.runtime.lastError;
if (error) { if (error) {
discarding the user's changes. discarding the user's changes.
*/ */
function resetChanges(callback) { function resetChanges(callback) {
chrome.storage.local.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => {
chrome.storage.local.get([ "matchingPatterns", "exclusionPatterns", "mode", "hideKillCount" ], (result) => {
AKS.matchingPatterns = result.matchingPatterns || ""; AKS.matchingPatterns = result.matchingPatterns || "";
AKS.exclusionPatterns = result.exclusionPatterns || "" AKS.exclusionPatterns = result.exclusionPatterns || ""
AKS.mode = result.mode || "blacklist"; AKS.mode = result.mode || "blacklist";
AKS.hideKillCount = result.hideKillCount || false;


document.querySelector("#matchingPatterns textarea").value = AKS.matchingPatterns; document.querySelector("#matchingPatterns textarea").value = AKS.matchingPatterns;
document.querySelector("#exclusionPatterns textarea").value = AKS.exclusionPatterns; document.querySelector("#exclusionPatterns textarea").value = AKS.exclusionPatterns;


toggleModeSelectorState(AKS.mode); toggleModeSelectorState(AKS.mode);
setHideKillCountSelectorState(AKS.hideKillCount);



// De-activate the "Reset" and "Save" buttons. // De-activate the "Reset" and "Save" buttons.
setButtonsActive(false); setButtonsActive(false);
}); });


//Listener for killcount display switch //Listener for killcount display switch
document.querySelector("input#display-kill-count").addEventListener("change", (event) => {
showKillCountInputReceived();
document.querySelector("input#hide-kill-count").addEventListener("change", (event) => {
hideKillCountInputReceived();
}); });


// Listener for open help button. // Listener for open help button.

Loading…
取消
儲存