Added pageAction to display the notifications.

This commit is contained in:
kkapsner 2017-06-29 07:21:36 +02:00
parent cba5680406
commit 5cec9781c2
10 changed files with 84 additions and 3 deletions

View File

@ -36,10 +36,21 @@
prefs
});
}
var port = browser.runtime.connect();
var tabId;
port.onMessage.addListener(function(data){
if (data.hasOwnProperty("tabId")){
console.log("my tab id is", data.tabId);
tabId = data.tabId;
}
});
var notifications = [];
function notify(data){
browser.runtime.sendMessage({"canvasBlocker-notify": data});
notifications.push(data);
port.postMessage({"canvasBlocker-notify": data});
}
const preferences = require("sdk/simple-prefs");
function prefs(name){
return preferences.prefs[name];
@ -99,5 +110,11 @@
if (data["canvasBlocker-unload"]){
enabled = false;
}
if (data["canvasBlocker-sendNotifications"] === tabId){
browser.runtime.sendMessage({
sender: tabId,
"canvasBlocker-notifications": notifications
});
}
});
}());

View File

@ -81,7 +81,7 @@
case "fake":
setRandomSupplyByType(prefs("rng"));
var fake = changedFunction.fakeGenerator(prefs, function(messageId){
notify({url, errorStack: error.stack, messageId});
notify({url, errorStack: error.stack, messageId, timestamp: new Date()});
}, window, original);
switch (fake){
case true:

View File

@ -10,8 +10,14 @@
console.log("got data", data);
});
browser.runtime.onConnect.addListener(function(port){
console.log("got port");
console.log("got port", port);
port.postMessage({tabId: port.sender.tab.id});
port.onMessage.addListener(function(data){
browser.pageAction.show(port.sender.tab.id);
console.log("got data", data, "from port", port);
});
});
console.log("end main script");
return null;
require("./stylePreferencePane");

View File

@ -34,6 +34,14 @@
"browser_style": true,
"page": "options/options.html"
},
"page_action": {
"browser_style": true,
"default_icon": {
"19": "pageAction/printed19.png",
"38": "pageAction/printed38.png"
},
"default_popup": "pageAction/pageAction.html"
},
"author": "Korbinian Kapsner",
"license": "MPL 2.0",
"permissions": [

10
pageAction/pageAction.css Normal file
View File

@ -0,0 +1,10 @@
.template {
display: none;
}
#prints {
min-width: 400px;
}
.print {
white-space: pre;
}

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>CanvasBlocker page action</title>
<link href="pageAction.css" rel="stylesheet" type="text/css">
</head>
<body>
<ul id="prints">
</ul>
<script src="pageAction.js"></script>
</body>
</html>

26
pageAction/pageAction.js Normal file
View File

@ -0,0 +1,26 @@
// console.log(window, browser, browser.runtime);
browser.tabs.query({active: true, currentWindow: true}).then(function(tabs){
if (!tabs.length){
throw new Error("noTabsFound");
}
var tab = tabs[0];
browser.runtime.onMessage.addListener(function(data){
if (Array.isArray(data["canvasBlocker-notifications"])){
var ul = document.getElementById("prints");
data["canvasBlocker-notifications"].forEach(function(notification){
var li = document.createElement("li");
li.className = "print";
li.textContent = notification.url + ": " + notification.messageId + " (" + notification.timestamp + ")" + "\n" + notification.errorStack;
ul.appendChild(li);
});
}
});
browser.tabs.sendMessage(
tab.id,
{
"canvasBlocker-sendNotifications": tab.id
}
);
}).catch(function(e){
console.error(e);
});

BIN
pageAction/printed19.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
pageAction/printed38.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -2,8 +2,10 @@ Version 0.4.0:
todos:
- import settings in content script (have to wait for the new API to register content scripts)
- check if webGL is still working
- add notification actions to page action popup
changes:
- switched to webExtension
- notifications are now done via page action
new features:
-