1
0
Fork 0
mirror of https://github.com/gorhill/uMatrix.git synced 2024-06-14 00:05:08 +12:00

Firefox: implement toolbar button and popup

This commit is contained in:
Deathamns 2014-12-16 13:44:34 +01:00 committed by gorhill
parent 41f3579461
commit bc199316be

View file

@ -1,20 +1,27 @@
/* globals Services, sendAsyncMessage, addMessageListener, removeMessageListener */
(function(frameScriptContext) {
'use strict';
let appName = 'ublock';
let appName;
let listeners = {};
let frameModule = Components.utils['import']('chrome://' + appName + '/content/frameModule.js', {});
this.ublock_addMessageListener = function(id, fn) {
ublock_removeMessageListener(id);
try { throw new Error; } catch (ex) {
appName = ex.fileName.match(/:\/\/([^\/]+)/)[1];
}
Components.utils['import']('chrome://' + appName + '/content/frameModule.js', {});
frameScriptContext[appName + '_addMessageListener'] = function(id, fn) {
frameScriptContext[appName + '_removeMessageListener'](id);
listeners[id] = function(msg) {
fn(msg.data);
};
addMessageListener(id, listeners[id]);
};
this.ublock_removeMessageListener = function(id) {
frameScriptContext[appName + '_removeMessageListener'] = function(id) {
if (listeners[id]) {
removeMessageListener(id, listeners[id]);
}
@ -27,3 +34,5 @@ addMessageListener(appName + ':broadcast', function(msg) {
listeners[id](msg);
}
});
})(this);