mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-05-29 09:28:06 +02:00
Page action message display and buttons.
This commit is contained in:
parent
b6dd2ff011
commit
5576b54883
|
@ -81,7 +81,7 @@
|
||||||
case "fake":
|
case "fake":
|
||||||
setRandomSupplyByType(prefs("rng"));
|
setRandomSupplyByType(prefs("rng"));
|
||||||
var fake = changedFunction.fakeGenerator(prefs, function(messageId){
|
var fake = changedFunction.fakeGenerator(prefs, function(messageId){
|
||||||
notify({url, errorStack: error.stack, messageId, timestamp: new Date()});
|
notify({url, errorStack: error.stack, messageId, timestamp: new Date(), functionName: name});
|
||||||
}, window, original);
|
}, window, original);
|
||||||
switch (fake){
|
switch (fake){
|
||||||
case true:
|
case true:
|
||||||
|
|
25
lib/main.js
25
lib/main.js
|
@ -13,10 +13,33 @@
|
||||||
console.log("got port", port);
|
console.log("got port", port);
|
||||||
port.postMessage({tabId: port.sender.tab.id});
|
port.postMessage({tabId: port.sender.tab.id});
|
||||||
port.onMessage.addListener(function(data){
|
port.onMessage.addListener(function(data){
|
||||||
browser.pageAction.show(port.sender.tab.id);
|
browser.storage.local.get("showNotifications").then(function(data){
|
||||||
|
// TODO: handle ignore list
|
||||||
|
if (!data.hasOwnProperty("showNotifications") || data.showNotifications){
|
||||||
|
browser.pageAction.show(port.sender.tab.id);
|
||||||
|
}
|
||||||
|
})
|
||||||
console.log("got data", data, "from port", port);
|
console.log("got data", data, "from port", port);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// hide all page actions when showNotifications is set to false
|
||||||
|
browser.storage.onChanged.addListener(function(change, area){
|
||||||
|
if (area === "local" && change.hasOwnProperty("showNotifications") && !change.showNotifications.newValue){
|
||||||
|
browser.tabs.query({}).then(function(tabs){
|
||||||
|
tabs.forEach(function(tab){
|
||||||
|
browser.pageAction.hide(tab.id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// hide page action when a tab is refreshed
|
||||||
|
browser.tabs.onUpdated.addListener(function(tabId, data){
|
||||||
|
if (data.status === "loading"){
|
||||||
|
browser.pageAction.hide(tabId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
console.log("end main script");
|
console.log("end main script");
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -15,7 +15,7 @@ function require(module){
|
||||||
on: function(key, callback){
|
on: function(key, callback){
|
||||||
browser.storage.onChanged.addListener(function(changes, area){
|
browser.storage.onChanged.addListener(function(changes, area){
|
||||||
if (area === "local"){
|
if (area === "local"){
|
||||||
if (changes[key]){
|
if (changes.hasOwnProperty(key)){
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
.template {
|
.actions {
|
||||||
display: none;
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#prints {
|
#prints {
|
||||||
min-width: 400px;
|
list-style: none;
|
||||||
}
|
padding: 0;
|
||||||
.print {
|
margin: 0;
|
||||||
white-space: pre;
|
|
||||||
}
|
}
|
|
@ -3,10 +3,16 @@
|
||||||
<head>
|
<head>
|
||||||
<title>CanvasBlocker page action</title>
|
<title>CanvasBlocker page action</title>
|
||||||
<link href="pageAction.css" rel="stylesheet" type="text/css">
|
<link href="pageAction.css" rel="stylesheet" type="text/css">
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<ul id="prints">
|
<ul id="prints">
|
||||||
|
<li>...</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<script src="../lib/require.js"></script>
|
||||||
|
<script src="../lib/defaultSettings.js"></script>
|
||||||
|
<script src="../lib/lists.js"></script>
|
||||||
|
<script src="../lib/callingStack.js"></script>
|
||||||
<script src="pageAction.js"></script>
|
<script src="pageAction.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,16 +1,128 @@
|
||||||
// console.log(window, browser, browser.runtime);
|
// console.log(window, browser, browser.runtime);
|
||||||
browser.tabs.query({active: true, currentWindow: true}).then(function(tabs){
|
function modalPrompt(message, defaultValue){
|
||||||
|
return new Promise(function(resolve, reject){
|
||||||
|
document.body.innerHTML = "";
|
||||||
|
document.body.appendChild(document.createTextNode(message));
|
||||||
|
var input = document.createElement("input");
|
||||||
|
input.value = defaultValue;
|
||||||
|
document.body.appendChild(input);
|
||||||
|
var button = document.createElement("button");
|
||||||
|
button.textContent = "OK";
|
||||||
|
button.addEventListener("click", function(){
|
||||||
|
resolve(input.value);
|
||||||
|
});
|
||||||
|
document.body.appendChild(button);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Promise.all([
|
||||||
|
browser.tabs.query({active: true, currentWindow: true}),
|
||||||
|
browser.storage.local.get().then(function(data){
|
||||||
|
Object.keys(data).forEach(function(key){
|
||||||
|
settings[key] = data[key];
|
||||||
|
});
|
||||||
|
return settings;
|
||||||
|
})
|
||||||
|
]).then(function([tabs, settings]){
|
||||||
if (!tabs.length){
|
if (!tabs.length){
|
||||||
throw new Error("noTabsFound");
|
throw new Error("noTabsFound");
|
||||||
}
|
}
|
||||||
|
else if (tabs.length > 1){
|
||||||
|
console.error(tabs);
|
||||||
|
throw new Error("tooManyTabsFound");
|
||||||
|
}
|
||||||
|
|
||||||
|
const lists = require("./lists");
|
||||||
|
const {parseErrorStack} = require("./callingStack");
|
||||||
|
var actionsCallbacks = {
|
||||||
|
displayFullURL: function({url}){
|
||||||
|
alert(url.href);
|
||||||
|
},
|
||||||
|
displayCallingStack: function({errorStack}){
|
||||||
|
alert(parseErrorStack(errorStack));
|
||||||
|
},
|
||||||
|
ignorelistDomain: function({url}){
|
||||||
|
var domain = url.host;
|
||||||
|
modalPrompt(
|
||||||
|
browser.i18n.getMessage("inputIgnoreDomain"),
|
||||||
|
url.host
|
||||||
|
).then(function(domain){
|
||||||
|
if (domain){
|
||||||
|
lists.appendTo("ignore", domain);
|
||||||
|
}
|
||||||
|
window.close();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
whitelistURL: function({url}){
|
||||||
|
modalPrompt(
|
||||||
|
browser.i18n.getMessage("inputWhitelistDomain"),
|
||||||
|
"^" + url.href.replace(/([\\\+\*\?\[\^\]\$\(\)\{\}\=\!\|\.])/g, "\\$1") + "$"
|
||||||
|
).then(function(url){
|
||||||
|
if (url){
|
||||||
|
lists.appendTo("white", url);
|
||||||
|
}
|
||||||
|
window.close();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
whitelistDomain: function({url}){
|
||||||
|
modalPrompt(
|
||||||
|
browser.i18n.getMessage("inputWhitelistURL"),
|
||||||
|
url.host
|
||||||
|
).then(function(domain){
|
||||||
|
if (domain){
|
||||||
|
lists.appendTo("white", domain);
|
||||||
|
}
|
||||||
|
window.close();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
disableNotifications: function(notification){
|
||||||
|
browser.storage.local.set({showNotifications: false});
|
||||||
|
window.close();
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
var tab = tabs[0];
|
var tab = tabs[0];
|
||||||
browser.runtime.onMessage.addListener(function(data){
|
browser.runtime.onMessage.addListener(function(data){
|
||||||
if (Array.isArray(data["canvasBlocker-notifications"])){
|
if (Array.isArray(data["canvasBlocker-notifications"])){
|
||||||
var ul = document.getElementById("prints");
|
var ul = document.getElementById("prints");
|
||||||
|
ul.innerHTML = "";
|
||||||
data["canvasBlocker-notifications"].forEach(function(notification){
|
data["canvasBlocker-notifications"].forEach(function(notification){
|
||||||
|
console.log(notification);
|
||||||
|
|
||||||
|
var url = new URL(notification.url);
|
||||||
var li = document.createElement("li");
|
var li = document.createElement("li");
|
||||||
li.className = "print";
|
li.className = "print";
|
||||||
li.textContent = notification.url + ": " + notification.messageId + " (" + notification.timestamp + ")" + "\n" + notification.errorStack;
|
|
||||||
|
|
||||||
|
li.appendChild(document.createTextNode(" "));
|
||||||
|
|
||||||
|
var messageSpan = document.createElement("span");
|
||||||
|
var messageParts = browser.i18n.getMessage(notification.messageId).split(/\{url\}/g);
|
||||||
|
messageSpan.appendChild(document.createTextNode(messageParts.shift()));
|
||||||
|
while (messageParts.length){
|
||||||
|
var urlSpan = document.createElement("span");
|
||||||
|
urlSpan.textContent = url.hostname;
|
||||||
|
urlSpan.title = url.href;
|
||||||
|
messageSpan.appendChild(urlSpan);
|
||||||
|
messageSpan.appendChild(document.createTextNode(messageParts.shift()));
|
||||||
|
}
|
||||||
|
messageSpan.title = notification.timestamp + ": " + notification.functionName;
|
||||||
|
li.appendChild(messageSpan);
|
||||||
|
|
||||||
|
li.appendChild(document.createTextNode(" "));
|
||||||
|
|
||||||
|
var actions = document.createElement("span");
|
||||||
|
actions.className = "actions";
|
||||||
|
var data = {url, errorStack: notification.errorStack, notification};
|
||||||
|
Object.keys(actionsCallbacks).forEach(function(key){
|
||||||
|
var button = document.createElement("button");
|
||||||
|
button.textContent = browser.i18n.getMessage(key);
|
||||||
|
button.addEventListener("click", function(){actionsCallbacks[key](data);});
|
||||||
|
actions.appendChild(button);
|
||||||
|
});
|
||||||
|
li.appendChild(actions);
|
||||||
|
|
||||||
ul.appendChild(li);
|
ul.appendChild(li);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
Version 0.4.0:
|
Version 0.4.0:
|
||||||
todos:
|
todos:
|
||||||
- import settings in content script (have to wait for the new API to register content scripts)
|
- import settings in content script (have to wait for the new API to register content scripts)
|
||||||
- add notification actions to page action popup
|
|
||||||
changes:
|
changes:
|
||||||
- switched to webExtension
|
- switched to webExtension
|
||||||
- notifications are now done via page action
|
- notifications are now done via page action
|
||||||
|
|
||||||
new features:
|
new features:
|
||||||
-
|
- information of all fake events in one tab are visible
|
||||||
|
|
||||||
fixes:
|
fixes:
|
||||||
- ask mode did not work for input types
|
- ask mode did not work for input types
|
||||||
|
|
Loading…
Reference in New Issue
Block a user