1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-04 20:46:39 +02:00

Added highlighting options for notification icons

Fixes #225.
This commit is contained in:
kkapsner 2018-08-20 21:48:05 +02:00
parent 15feed6445
commit c25e95f845
11 changed files with 550 additions and 34 deletions

View file

@ -7,9 +7,9 @@
const settings = require("./settings");
const logging = require("./logging");
const {error, warning, message, notice, verbose, } = logging;
const lists = require("./lists");
logging.setPrefix("main script");
const persistentRndStorage = require("./persistentRndStorage");
const notification = require("./notification");
message("start of background script");
message("waiting for settings to be loaded");
@ -62,30 +62,10 @@
var url = new URL(port.sender.url);
port.onMessage.addListener(function(data){
if (data.hasOwnProperty("canvasBlocker-notify")){
if (
settings.get("showNotifications", url) &&
!lists.get("ignore").match(url)
){
browser.pageAction.show(port.sender.tab.id);
browser.browserAction.setIcon({
tabId: port.sender.tab.id,
path: {
"19": "icons/browserAction-printed.svg",
"38": "icons/browserAction-printed.svg"
}
});
}
notification.show(port.sender.tab.id, url);
}
if (data.hasOwnProperty("canvasBlocker-clear-page-action")){
notice("Hide page action for tab", port.sender.tab.id);
browser.pageAction.hide(port.sender.tab.id);
browser.browserAction.setIcon({
tabId: port.sender.tab.id,
path: {
"19": "icons/browserAction-notPrinted.svg",
"38": "icons/browserAction-notPrinted.svg"
}
});
notification.hide(port.sender.tab.id);
}
verbose("got data", data, "from port", port);
});
@ -93,17 +73,6 @@
message("register storage change event listener");
settings.on("showNotifications", function({newValue}){
if (!newValue){
message("notifications were disabled -> hide all page actions");
browser.tabs.query({}).then(function(tabs){
tabs.forEach(function(tab){
browser.pageAction.hide(tab.id);
});
});
}
});
if (browser.contentScripts){
let unregister = function(){};
let lastRegistering;

74
lib/notification.js Normal file
View file

@ -0,0 +1,74 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
(function(){
"use strict";
var scope;
if ((typeof exports) !== "undefined"){
scope = exports;
}
else {
scope = {};
window.scope.notification = scope;
}
const settings = require("./settings");
const lists = require("./lists");
const logging = require("./logging");
const paths = {
pageAction: {
none: "icons/pageAction-printed.svg",
color: "icons/pageAction-printedHighlight.svg",
blink: "icons/pageAction-printedBlink.svg"
},
browserAction: {
none: "icons/browserAction-notPrinted.svg",
color: "icons/browserAction-printed.svg",
blink: "icons/browserAction-printedBlink.svg"
}
};
scope.show = function showNotification(tabId, url){
logging.notice("Show notification for tab", tabId);
if (
settings.get("showNotifications", url) &&
!lists.get("ignore").match(url)
){
browser.pageAction.show(tabId);
browser.pageAction.setIcon({
tabId: tabId,
path: paths.pageAction[settings.highlightPageAction]
});
}
browser.browserAction.setIcon({
tabId: tabId,
path: paths.browserAction[settings.highlightBrowserAction]
});
};
scope.hide = function hideNotification(tabId){
logging.notice("Hide page action for tab", tabId);
browser.pageAction.hide(tabId);
browser.pageAction.setIcon({
tabId: tabId,
path: paths.pageAction.none
});
browser.browserAction.setIcon({
tabId: tabId,
path: paths.browserAction.none
});
};
settings.on("showNotifications", function({newValue}){
if (!newValue){
logging.message("notifications were disabled -> hide all page actions");
browser.tabs.query({}).then(function(tabs){
tabs.forEach(function(tab){
browser.pageAction.hide(tab.id);
});
});
}
});
}());

View file

@ -154,6 +154,18 @@
defaultValue: true,
urlSpecific: true
},
{
name: "highlightPageAction",
defaultValue: "none",
options: ["none", "color", "blink"],
urlSpecific: true
},
{
name: "highlightBrowserAction",
defaultValue: "color",
options: ["none", "color", "blink"],
urlSpecific: true
},
{
name: "storeImageForInspection",
defaultValue: false