mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +01:00
Functional notifications in right tab!
This commit is contained in:
parent
8524301655
commit
460da0f642
@ -49,6 +49,33 @@
|
||||
return bytes;
|
||||
}());
|
||||
|
||||
// parse calling stack
|
||||
function errorToCallingStackMsg(error){
|
||||
var msg = "";
|
||||
var callers = error.stack.trim().split("\n");
|
||||
//console.log(callers);
|
||||
var findme = callers.shift(); // Remove us from the stack
|
||||
findme = findme.replace(/(:[0-9]+){1,2}$/, ""); // rm line & column
|
||||
// Eliminate squashed stack. stack may contain 2+ stacks, but why...
|
||||
var inDoubleStack = false;
|
||||
callers = callers.filter(function(caller){
|
||||
var doubleStackStart = caller.search(findme) !== -1;
|
||||
inDoubleStack = inDoubleStack || doubleStackStart;
|
||||
return !inDoubleStack;
|
||||
});
|
||||
msg += "\n\n" + _("sourceOutput") + ": ";
|
||||
if (settings.showCompleteCallingStack){
|
||||
msg += callers.reduce(function(stack, c){
|
||||
return stack + "\n\t" + _("stackEntryOutput", parseStackEntry(c));
|
||||
}, "");
|
||||
}
|
||||
else{
|
||||
msg += _("stackEntryOutput", parseStackEntry(callers[0]));
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
// Check canvas appearance
|
||||
function canvasAppearance(context){
|
||||
var oldBorder = false;
|
||||
@ -159,6 +186,7 @@
|
||||
configureable: false,
|
||||
get: exportFunction(function(){
|
||||
var status = changedFunction.mode.status;
|
||||
var callingStackMsg = errorToCallingStackMsg(new Error());
|
||||
if (status === "ask"){
|
||||
var askStatus = changedFunction.mode.askStatus;
|
||||
var appearance = canvasAppearance(this);
|
||||
@ -170,26 +198,7 @@
|
||||
//console.log("asking");
|
||||
var msg = _(changedFunction.mode.askText[appearance.text]);
|
||||
if (settings.showCallingFile){
|
||||
var callers = new Error().stack.trim().split("\n");
|
||||
//console.log(callers);
|
||||
var findme = callers.shift(); // Remove us from the stack
|
||||
findme = findme.replace(/(:[0-9]+){1,2}$/, ""); // rm line & column
|
||||
// Eliminate squashed stack. stack may contain 2+ stacks, but why...
|
||||
var inDoubleStack = false;
|
||||
callers = callers.filter(function(caller){
|
||||
var doubleStackStart = caller.search(findme) !== -1;
|
||||
inDoubleStack = inDoubleStack || doubleStackStart;
|
||||
return !inDoubleStack;
|
||||
});
|
||||
msg += "\n\n" + _("sourceOutput") + ": ";
|
||||
if (settings.showCompleteCallingStack){
|
||||
msg += callers.reduce(function(stack, c){
|
||||
return stack + "\n\t" + _("stackEntryOutput", parseStackEntry(c));
|
||||
}, "");
|
||||
}
|
||||
else{
|
||||
msg += _("stackEntryOutput", parseStackEntry(callers[0]));
|
||||
}
|
||||
msg += callingStackMsg;
|
||||
}
|
||||
status = window.confirm(msg) ? "allow": "block";
|
||||
askStatus.alreadyAsked[appearance.text] = true;
|
||||
@ -198,7 +207,7 @@
|
||||
appearance.reset();
|
||||
}
|
||||
}
|
||||
self.port.emit("accessed " + changedFunction.mode.name, status);
|
||||
self.port.emit("accessed " + changedFunction.mode.name, status, callingStackMsg);
|
||||
switch (status){
|
||||
case "allow":
|
||||
return original;
|
||||
|
15
lib/main.js
15
lib/main.js
@ -185,7 +185,7 @@
|
||||
checkWorker(worker);
|
||||
|
||||
// display notifications
|
||||
worker.port.on("accessed readAPI", function(status){
|
||||
worker.port.on("accessed readAPI", function(status, callingStackMsg){
|
||||
function log(title, object){
|
||||
console.log(title);
|
||||
for (var name in object){
|
||||
@ -203,18 +203,21 @@
|
||||
var tab = tabUtils.getTabForId(worker.tab.id);
|
||||
var tabBrowser = tabUtils.getTabBrowserForTab(tab);
|
||||
var browser = tabUtils.getBrowserForTab(tab);
|
||||
var ownerBrowser = windowUtils.getOwnerBrowserWindow(tab);
|
||||
|
||||
// var notifyBox = ownerBrowser.gBrowser.getNotificationBox();
|
||||
var notifyBox = tabBrowser.getNotificationBox();
|
||||
// log(" chrome window", require("sdk/windows").browserWindows);
|
||||
// var notifyBox = windowUtils.getXULWindow(browser.contentWindow).XULBrowserWindow.getNotificationBox(browser.contentWindow);
|
||||
var notifyBox = tabBrowser.getNotificationBox(browser);
|
||||
var notification = notifyBox.getNotificationWithValue("fake-readout");
|
||||
if (notification){
|
||||
notification.label = message;
|
||||
}
|
||||
else {
|
||||
var buttons = [
|
||||
{
|
||||
label: _("displayCallingStack"),
|
||||
accessKey: "",
|
||||
callback: function(){
|
||||
browser.contentWindow.alert(callingStackMsg);
|
||||
}
|
||||
},
|
||||
{
|
||||
label: _("whitelistURL"),
|
||||
accessKey: "",
|
||||
|
Loading…
x
Reference in New Issue
Block a user