1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-07-01 23:38:56 +02:00
CanvasBlocker/lib/main.js

84 lines
2.6 KiB
JavaScript
Raw Normal View History

2015-09-08 11:41:33 +02:00
/* jslint moz: true */
2015-01-16 13:01:01 +01:00
/* 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/. */
2014-08-20 10:21:38 +02:00
(function(){
2014-10-14 01:06:11 +02:00
"use strict";
require("./stylePreferencePane");
2014-10-11 00:07:51 +02:00
2016-02-13 12:28:36 +01:00
const {when: unload} = require("sdk/system/unload");
const {check, checkStack} = require("./check.js");
2016-02-13 12:28:36 +01:00
const {notify} = require("./notifications");
const _ = require("sdk/l10n").get;
const lists = require("./lists");
const preferences = require("sdk/simple-prefs");
2016-02-13 12:28:36 +01:00
const prefService = require("sdk/preferences/service");
const prefs = preferences.prefs;
2014-12-15 18:43:47 +01:00
2016-02-13 12:28:36 +01:00
const notificationPref = {
doShow: function(){
return prefs.showNotifications;
},
setShow: function(value){
prefs.showNotifications = value;
prefService.set("extensions.CanvasBlocker@kkapsner.de.showNotifications", prefs.showNotifications);
},
displayTime: function(){
return prefs.notificationDisplayTime;
}
2016-02-13 12:28:36 +01:00
};
2015-04-24 01:04:14 +02:00
2016-02-13 12:28:36 +01:00
const {Cc, Ci} = require("chrome");
var globalMM = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
var frameURL = require("sdk/self").data.url("frame.js?" + Math.random());
globalMM.loadFrameScript(frameURL, true);
2016-02-13 12:28:36 +01:00
var listeners = [];
function addMessageListener(name, func){
listeners.push({name, func});
globalMM.addMessageListener(name, func);
}
unload(function(){
2016-02-13 12:28:36 +01:00
globalMM.removeDelayedFrameScript(frameURL);
globalMM.broadcastAsyncMessage("canvasBlocker-unload");
listeners.forEach(function(listener){
globalMM.removeMessageListener(listener.name, listener.func);
});
});
// messages from the frame.js
addMessageListener("canvasBlocker-check", function(ev){
var status = check(ev.data);
return status;
});
addMessageListener("canvasBlocker-checkStack", function(ev){
return checkStack(ev.data);
});
2016-02-13 12:28:36 +01:00
addMessageListener("canvasBlocker-notify", function(ev){
var browser = ev.target;
notify(ev.data, {lists, _, notificationPref, browser});
});
addMessageListener("canvasBlocker-pref-get", function(ev){
return prefs[ev.data];
});
addMessageListener("canvasBlocker-pref-set", function(ev){
prefs[ev.data.name] = ev.data.value;
prefService.set("extensions.CanvasBlocker@kkapsner.de." + ev.data.name, ev.data.value);
2014-08-20 10:21:38 +02:00
});
2016-02-13 12:28:36 +01:00
addMessageListener("canvasBlocker-list-match", function(ev){
return lists.get(ev.data.list).match(ev.data.url);
});
addMessageListener("canvasBlocker-list-appendTo", function(ev){
return lists.appendTo(ev.data.list, ev.data.entry);
});
addMessageListener("canvasBlocker-translate", function(ev){
return _(ev.data);
});
2014-08-20 10:21:38 +02:00
}());