aboutsummaryrefslogtreecommitdiff
path: root/js/firefox/background-shim.js
diff options
context:
space:
mode:
authorEinar Egilsson <einar@einaregilsson.com>2015-09-21 14:44:37 +0000
committerEinar Egilsson <einar@einaregilsson.com>2015-09-21 14:44:37 +0000
commit720c2643cd4bcfbc63b67d7d74c476496c805b8b (patch)
tree311ad09d1b71ebd10ff9500065c55eabb42a71de /js/firefox/background-shim.js
parentb2ba3216ea5dbe6a74fdfa75611fce95c1481316 (diff)
Mostly working on Firefox
Diffstat (limited to 'js/firefox/background-shim.js')
-rw-r--r--js/firefox/background-shim.js50
1 files changed, 31 insertions, 19 deletions
diff --git a/js/firefox/background-shim.js b/js/firefox/background-shim.js
index fb08039..453feff 100644
--- a/js/firefox/background-shim.js
+++ b/js/firefox/background-shim.js
@@ -16,8 +16,8 @@ var button = ToggleButton({
id: "redirector",
label: "Redirector",
icon: {
- "16": makeUrl("images/icon16active.png"),
- "32": makeUrl("images/icon32active.png")
+ "16": makeUrl("images/icon-active-16.png"),
+ "32": makeUrl("images/icon-active-32.png")
},
onChange: function(state) {
if (state.checked) {
@@ -26,15 +26,6 @@ var button = ToggleButton({
}
});
-var panel = panels.Panel({
- width: 200,
- height: 130,
- contentURL: makeUrl('popup.html'),
- contentScriptFile : makeUrl('js/firefox/content-script-proxy.js'),
- onHide: function() {
- button.state('window', {checked: false});
- }
-});
var extensionId = require('../../package.json').id;
@@ -66,37 +57,58 @@ var chrome = {
browserAction : {
setIcon : function(data, callback) {
-
+ var icon = {};
+ for (var key in data.path) {
+ icon[key] = makeUrl(data.path[key]);
+ }
+ button.icon = icon;
}
}
};
var pageMod = require("sdk/page-mod");
+var panel = panels.Panel({
+ width: 200,
+ height: 130,
+ contentURL: makeUrl('popup.html'),
+ contentScriptFile : makeUrl('js/firefox/content-script-proxy.js'),
+ onHide: function() {
+ button.state('window', {checked: false});
+ }
+});
+
function attachedPage(worker) {
+ function sendReply(originalMessage, reply) {
+ if (JSON.stringify(reply) == "{}") {
+ throw 'fuck';
+ }
+ var msg = {messageId:originalMessage.messageId, payload:reply};
+ console.info('background sending message: ' + JSON.stringify(msg));
+ worker.port.emit('message', msg);
+ }
worker.port.on('message', function(message) {
console.info('background got message: ' + JSON.stringify(message));
if (message.messageType == 'storage.get') {
console.info('Getting from storage');
chrome.storage.local.get(message.payload, function(data) {
- var resultMsg = { messageId: message.messageId, payload: data };
- console.info('background sending message: ' + JSON.stringify(resultMsg));
- worker.port.emit('message', resultMsg);
+ sendReply(message, data);
});
} else if (message.messageType == 'storage.set') {
chrome.storage.local.set(message.payload, function(data) {
- var resultMsg = { messageId: message.messageId, payload: data };
- console.info('background sending message: ' + JSON.stringify(resultMsg));
- worker.port.emit('message', resultMsg);
+ sendReply(message, data);
});
- }
+ }
});
}
+attachedPage(panel);
+
pageMod.PageMod({
include: makeUrl('redirector.html'),
contentScriptFile: makeUrl('js/firefox/content-script-proxy.js'),
+ contentScriptWhen: 'start',
onAttach : attachedPage
});