1
0
Fork 0
mirror of https://github.com/gorhill/uMatrix.git synced 2024-06-01 18:10:17 +12:00

Firefox: improvements for content scripts

This commit is contained in:
Deathamns 2015-01-08 21:18:05 +01:00 committed by gorhill
parent 3646ecbeb2
commit 9317615bc7

View file

@ -19,51 +19,11 @@
Home: https://github.com/gorhill/uBlock
*/
/* globals addMessageListener, removeMessageListener */
/******************************************************************************/
// https://bugzil.la/673569
(function(frameScriptContext) {
'use strict';
/******************************************************************************/
let appName = Components.stack.filename.match(/:\/\/([^\/]+)/)[1];
let listeners = {};
Components.utils['import'](Components.stack.filename.replace('Script', 'Module'), {});
/******************************************************************************/
frameScriptContext[appName + '_addMessageListener'] = function(id, fn) {
frameScriptContext[appName + '_removeMessageListener'](id);
listeners[id] = function(msg) {
fn(msg.data);
};
addMessageListener(id, listeners[id]);
};
frameScriptContext[appName + '_removeMessageListener'] = function(id) {
if ( listeners[id] ) {
removeMessageListener(id, listeners[id]);
}
delete listeners[id];
};
/******************************************************************************/
addMessageListener(appName + ':broadcast', function(msg) {
for ( let id in listeners ) {
listeners[id](msg);
}
});
/******************************************************************************/
})(this);
Components.utils.import(
Components.stack.filename.replace('Script', 'Module'),
null
);
/******************************************************************************/