1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-10-31 18:38:45 +01:00

Added badge

First draft for #233.
This commit is contained in:
kkapsner 2018-08-21 22:43:41 +02:00
parent c0563cd7d5
commit bfb959c290
7 changed files with 83 additions and 6 deletions

View File

@ -564,10 +564,6 @@
"message": "Page-Action Icon hervorheben", "message": "Page-Action Icon hervorheben",
"description": "" "description": ""
}, },
"highlightBrowserAction_description": {
"message": "",
"description": ""
},
"highlightPageAction_options.none": { "highlightPageAction_options.none": {
"message": "nicht hervorheben", "message": "nicht hervorheben",
"description": "" "description": ""
@ -580,6 +576,18 @@
"message": "blinken", "message": "blinken",
"description": "" "description": ""
}, },
"displayBadge_description": {
"message": "",
"description": ""
},
"displayBadge_title": {
"message": "Badge anzeigen",
"description": ""
},
"highlightBrowserAction_description": {
"message": "",
"description": ""
},
"highlightBrowserAction_title": { "highlightBrowserAction_title": {
"message": "Toolbar Icon bei Benachrichtigung ändern", "message": "Toolbar Icon bei Benachrichtigung ändern",
"description": "" "description": ""

View File

@ -576,6 +576,14 @@
"message": "blink", "message": "blink",
"description": "" "description": ""
}, },
"displayBadge_description": {
"message": "",
"description": ""
},
"displayBadge_title": {
"message": "Display badge",
"description": ""
},
"highlightBrowserAction_description": { "highlightBrowserAction_description": {
"message": "", "message": "",
"description": "" "description": ""

View File

@ -62,7 +62,7 @@
var url = new URL(port.sender.url); var url = new URL(port.sender.url);
port.onMessage.addListener(function(data){ port.onMessage.addListener(function(data){
if (data.hasOwnProperty("canvasBlocker-notify")){ if (data.hasOwnProperty("canvasBlocker-notify")){
notification.show(port.sender.tab.id, url); notification.show(port.sender.tab.id, url, data["canvasBlocker-notify"].api);
} }
if (data.hasOwnProperty("canvasBlocker-clear-page-action")){ if (data.hasOwnProperty("canvasBlocker-clear-page-action")){
notification.hide(port.sender.tab.id); notification.hide(port.sender.tab.id);

View File

@ -30,7 +30,12 @@
} }
}; };
scope.show = function showNotification(tabId, url){ browser.browserAction.setBadgeBackgroundColor({
color: "rgba(255, 0, 0, 0.6)"
});
const apiMap = new Map();
scope.show = function showNotification(tabId, url, api){
logging.notice("Show notification for tab", tabId); logging.notice("Show notification for tab", tabId);
if ( if (
settings.get("showNotifications", url) && settings.get("showNotifications", url) &&
@ -46,10 +51,33 @@
tabId: tabId, tabId: tabId,
path: paths.browserAction[settings.highlightBrowserAction] path: paths.browserAction[settings.highlightBrowserAction]
}); });
let apis = apiMap.get(tabId);
if (!apis){
apis = new Set();
}
apis.add(api);
apiMap.set(tabId, apis);
if (settings.get("displayBadge", url)){
browser.browserAction.setBadgeText({
tabId: tabId,
text: apis.size > 1? apis.size.toString(): api.charAt(0).toUpperCase()
});
}
let apiList = "";
apis.forEach(function(api){
apiList += "\n \u00B7 " + api;
});
browser.browserAction.setTitle({
tabId: tabId,
title: "CanvasBlocker" + apiList
});
}; };
scope.hide = function hideNotification(tabId){ scope.hide = function hideNotification(tabId){
logging.notice("Hide page action for tab", tabId); logging.notice("Hide page action for tab", tabId);
apiMap.delete(tabId);
browser.pageAction.hide(tabId); browser.pageAction.hide(tabId);
browser.pageAction.setIcon({ browser.pageAction.setIcon({
tabId: tabId, tabId: tabId,
@ -59,6 +87,14 @@
tabId: tabId, tabId: tabId,
path: paths.browserAction.none path: paths.browserAction.none
}); });
browser.browserAction.setBadgeText({
tabId: tabId,
text: ""
});
browser.browserAction.setTitle({
tabId: tabId,
title: "CanvasBlocker"
});
}; };
settings.on("showNotifications", function({newValue}){ settings.on("showNotifications", function({newValue}){
@ -71,4 +107,21 @@
}); });
} }
}); });
browser.tabs.onRemoved.addListener(function(tabId){
apiMap.delete(tabId);
});
settings.on("displayBadge", function({newValue}){
if (!newValue){
logging.message("badge was disabled -> hide all badges");
browser.tabs.query({}).then(function(tabs){
tabs.forEach(function(tab){
browser.browserAction.setBadgeText({
tabId: tab.id,
text: ""
});
});
});
}
});
}()); }());

View File

@ -166,6 +166,10 @@
options: ["none", "color", "blink"], options: ["none", "color", "blink"],
urlSpecific: true urlSpecific: true
}, },
{
name: "displayBadge",
defaultValue: true
},
{ {
name: "storeImageForInspection", name: "storeImageForInspection",
defaultValue: false defaultValue: false

View File

@ -202,6 +202,9 @@
} }
] ]
}, },
{
"name": "displayBadge"
},
{ {
"name": "highlightBrowserAction" "name": "highlightBrowserAction"
}, },

View File

@ -9,6 +9,7 @@ Version 0.5.3:
- added option to highlight page action icon - added option to highlight page action icon
- added option to control browser action icon on notifications - added option to control browser action icon on notifications
- added theme for browser action popup - added theme for browser action popup
- added badge
fixes: fixes:
- CSP did not work properly for worker-src - CSP did not work properly for worker-src