1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 12:50:36 +01: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

@ -556,6 +556,46 @@
"message": "Benachrichtigungen anzeigen",
"description": ""
},
"highlightPageAction_description": {
"message": "Page-Action Icon für eine erhöhte Sichtbarkeit hervorheben.",
"description": ""
},
"highlightPageAction_title": {
"message": "Page-Action Icon hervorheben",
"description": ""
},
"highlightBrowserAction_description": {
"message": "",
"description": ""
},
"highlightPageAction_options.none": {
"message": "nicht hervorheben",
"description": ""
},
"highlightPageAction_options.color": {
"message": "Farbe",
"description": ""
},
"highlightPageAction_options.blink": {
"message": "blinken",
"description": ""
},
"highlightBrowserAction_title": {
"message": "Toolbar Icon bei Benachrichtigung ändern",
"description": ""
},
"highlightBrowserAction_options.none": {
"message": "nichts ändern",
"description": ""
},
"highlightBrowserAction_options.color": {
"message": "Farbe ändern",
"description": ""
},
"highlightBrowserAction_options.blink": {
"message": "blinken",
"description": ""
},
"notificationDisplayTime_description": {
"message": "Anzahl der Sekunden, die die Benachrichtigungen angezeigt werden sollen. (Null eingeben, um die Benachrichtigungen nicht automatisch zu schließen.)",
"description": ""

View File

@ -556,6 +556,46 @@
"message": "Show notifications",
"description": ""
},
"highlightPageAction_description": {
"message": "Highlight the page action icon for better visibility.",
"description": ""
},
"highlightPageAction_title": {
"message": "Highlight page action icon",
"description": ""
},
"highlightPageAction_options.none": {
"message": "no highlight",
"description": ""
},
"highlightPageAction_options.color": {
"message": "color",
"description": ""
},
"highlightPageAction_options.blink": {
"message": "blink",
"description": ""
},
"highlightBrowserAction_description": {
"message": "",
"description": ""
},
"highlightBrowserAction_title": {
"message": "Change toolbar icon on notification",
"description": ""
},
"highlightBrowserAction_options.none": {
"message": "change nothing",
"description": ""
},
"highlightBrowserAction_options.color": {
"message": "change color",
"description": ""
},
"highlightBrowserAction_options.blink": {
"message": "blink",
"description": ""
},
"notificationDisplayTime_description": {
"message": "Number of seconds the notifications are shown. (Enter zero to disable automatic closing.)",
"description": ""

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 15 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 15 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 14 KiB

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

View File

@ -16,6 +16,7 @@
"lib/lists.js",
"lib/persistentRndStorage.js",
"lib/dataUrls.js",
"lib/notification.js",
"lib/main.js"
]
},

View File

@ -194,6 +194,17 @@
{
"name": "showNotifications"
},
{
"name": "highlightPageAction",
"displayDependencies": [
{
"showNotifications": [true]
}
]
},
{
"name": "highlightBrowserAction"
},
{
"name": "storeImageForInspection",
"displayDependencies": [

View File

@ -6,6 +6,8 @@ Version 0.5.3:
- display version in options page
- added link to open options page in separate tab
- added option "Don't show again on update." for options page
- added option to highlight page action icon
- added option to control browser action icon on notifications
fixes:
- CSP did not work properly for worker-src