mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-09 13:15:00 +01:00
First function notifications
may open notification on wrong tab...
This commit is contained in:
parent
0a88d47609
commit
f0e3a6a874
41
lib/main.js
41
lib/main.js
@ -52,6 +52,8 @@
|
|||||||
var prefs = preferences.prefs;
|
var prefs = preferences.prefs;
|
||||||
var URL = require("sdk/url").URL;
|
var URL = require("sdk/url").URL;
|
||||||
var _ = require("sdk/l10n").get;
|
var _ = require("sdk/l10n").get;
|
||||||
|
var tabUtils = require("sdk/tabs/utils");
|
||||||
|
var windowUtils = require("sdk/window/utils");
|
||||||
|
|
||||||
// preferences
|
// preferences
|
||||||
Object.keys(prefs).forEach(function(pref){
|
Object.keys(prefs).forEach(function(pref){
|
||||||
@ -184,23 +186,49 @@
|
|||||||
|
|
||||||
// display notifications
|
// display notifications
|
||||||
worker.port.on("accessed readAPI", function(status){
|
worker.port.on("accessed readAPI", function(status){
|
||||||
|
function log(title, object){
|
||||||
|
console.log(title);
|
||||||
|
for (var name in object){
|
||||||
|
console.log(name, object[name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
switch (status){
|
switch (status){
|
||||||
case "fake":
|
case "fake":
|
||||||
|
|
||||||
var contentURL = new URL(worker.contentURL);
|
var contentURL = new URL(worker.contentURL);
|
||||||
var url = contentURL.href;
|
var url = contentURL.href;
|
||||||
var domain = contentURL.hostname;
|
var domain = contentURL.hostname;
|
||||||
var message = "Faked readout on " + url;
|
var message = "Faked readout on " + url;
|
||||||
|
|
||||||
|
// log(" worker.tab", worker.tab);
|
||||||
|
// log(" windowUtils", windowUtils);
|
||||||
|
// log(" ", windowUtils.windows("navigator:browser", {includePrivate: true})[0][0]);
|
||||||
|
// log(" ", windowUtils.windows("navigator:browser", {includePrivate: true})[0][1]);
|
||||||
|
// log(" ", windowUtils.windows("navigator:browser", {includePrivate: true})[0][2]);
|
||||||
|
// log(" tabs", tabUtils.getTabs());
|
||||||
|
// console.log(worker.tab.id);
|
||||||
|
// for each (let tab in tabUtils.getTabs()){
|
||||||
|
// console.log(tabUtils.getTabId(tab));
|
||||||
|
// }
|
||||||
|
|
||||||
var notifyBox = gWindow.getNotificationBox();
|
var tab = tabUtils.getTabForId(worker.tab.id);
|
||||||
var notification = notifiyBox.getNotificationBoxWithValue("fake-readout");
|
var tabBrowser = tabUtils.getTabBrowserForTab(tab);
|
||||||
|
var browser = tabUtils.getBrowserForTab(tab);
|
||||||
|
var ownerBrowser = windowUtils.getOwnerBrowserWindow(tab);
|
||||||
|
|
||||||
|
// var notifyBox = ownerBrowser.gBrowser.getNotificationBox();
|
||||||
|
var notifyBox = tabBrowser.getNotificationBox();
|
||||||
|
// log(" chrome window", require("sdk/windows").browserWindows);
|
||||||
|
// var notifyBox = windowUtils.getXULWindow(browser.contentWindow).XULBrowserWindow.getNotificationBox(windowUtils.getDOMWindow(browser.contentWindow));
|
||||||
|
var notification = notifyBox.getNotificationWithValue("fake-readout");
|
||||||
if (notification){
|
if (notification){
|
||||||
notification.label = message;
|
notification.label = message;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var buttons = [
|
var buttons = [
|
||||||
{
|
{
|
||||||
label: 'whitelist URL',
|
label: "whitelist URL",
|
||||||
|
accessKey: "",
|
||||||
callback: function(){
|
callback: function(){
|
||||||
prefs.whiteList += "," + url;
|
prefs.whiteList += "," + url;
|
||||||
prefService.set("extensions.CanvasBlocker@kkapsner.de.whiteList", prefs.whiteList);
|
prefService.set("extensions.CanvasBlocker@kkapsner.de.whiteList", prefs.whiteList);
|
||||||
@ -209,7 +237,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'whitelist domain',
|
label: "whitelist domain",
|
||||||
|
accessKey: "",
|
||||||
callback: function(){
|
callback: function(){
|
||||||
prefs.whiteList += "," + domain;
|
prefs.whiteList += "," + domain;
|
||||||
prefService.set("extensions.CanvasBlocker@kkapsner.de.whiteList", prefs.whiteList);
|
prefService.set("extensions.CanvasBlocker@kkapsner.de.whiteList", prefs.whiteList);
|
||||||
@ -219,8 +248,8 @@
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
let priority = box.PRIORITY_WARNING_MEDIUM;
|
let priority = notifyBox.PRIORITY_WARNING_MEDIUM;
|
||||||
box.appendNotification(
|
notifyBox.appendNotification(
|
||||||
message,
|
message,
|
||||||
'fake-readout',
|
'fake-readout',
|
||||||
'chrome://browser/skin/Info.png',
|
'chrome://browser/skin/Info.png',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user