mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +01:00
Added Numbers in pageAction icon and added content script.
This commit is contained in:
parent
25b0d400be
commit
753dbcf616
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
*.svg
|
||||
printed.png
|
@ -1,16 +1,57 @@
|
||||
console.log("background");
|
||||
var getPageActionIcon = function(){
|
||||
var faktor = 2;
|
||||
var canvas = document.createElement("canvas");
|
||||
canvas.width = canvas.height = 19 * faktor;
|
||||
var context = canvas.getContext("2d");
|
||||
var img = document.createElement("img");
|
||||
img.src = "icons/printed" + (19 * faktor) + ".png"
|
||||
|
||||
|
||||
return function getPageActionIcon(c){
|
||||
context.clearRect(0, 0, canvas.width, canvas.height);
|
||||
context.drawImage(img, 0, 0, canvas.width, canvas.height);
|
||||
if (c > 1){
|
||||
context.fillStyle = "#000000";
|
||||
context.fillRect(9 * faktor, 9 * faktor, 10 * faktor, 10 * faktor);
|
||||
context.strokeStyle = context.fillStyle = "#FFFFFF";
|
||||
context.textAlign = "center";
|
||||
context.textBaseline = "middle";
|
||||
context.font = "Bold " + (10 * faktor) + "px Arial";
|
||||
context.fillText(c < 10? c: ">", 14 * faktor, 15 * faktor);
|
||||
}
|
||||
return context.getImageData(0, 0, canvas.width, canvas.height);
|
||||
}
|
||||
}();
|
||||
|
||||
function updatePageActionIcon(tabId, c){
|
||||
if (c === 0){
|
||||
browser.pageAction.hide(tabId);
|
||||
}
|
||||
else {
|
||||
browser.pageAction.show(tabId);
|
||||
browser.pageAction.setIcon({
|
||||
tabId: tabId,
|
||||
imageData: getPageActionIcon(c)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var c = 0;
|
||||
|
||||
browser.tabs.query({}).then(function(tabs){
|
||||
console.log("tabs", tabs);
|
||||
tabs.forEach(function(tab){
|
||||
console.log("tab", tab);
|
||||
browser.pageAction.show(tab.id).then(function(){console.log("success");}, function(){console.log("error");});
|
||||
browser.pageAction.show(tab.id);
|
||||
});
|
||||
});
|
||||
|
||||
browser.tabs.onActivated.addListener(function(tab){
|
||||
browser.pageAction.show(tab.id);
|
||||
browser.tabs.onActivated.addListener(function(activeInfo){
|
||||
c += 1;
|
||||
// console.log(c);
|
||||
updatePageActionIcon(activeInfo.tabId , c);
|
||||
});
|
||||
browser.tabs.onUpdate.addistener(function(tab){
|
||||
browser.pageAction.show(tab.id);
|
||||
browser.tabs.onUpdated.addListener(function(tabId){
|
||||
// c += 1;
|
||||
//console.log(c);
|
||||
// updatePageActionIcon(tabId, c);
|
||||
});
|
||||
|
8
webextension/contentScript.js
Normal file
8
webextension/contentScript.js
Normal file
@ -0,0 +1,8 @@
|
||||
var oldAlert = alert;
|
||||
exportFunction(
|
||||
function(str){
|
||||
oldAlert("From page script: " + str);
|
||||
},
|
||||
window,
|
||||
{defineAs:'alert'}
|
||||
);
|
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.7 KiB |
@ -14,6 +14,13 @@
|
||||
},
|
||||
"default_popup": "pageAction/index.html"
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": ["<all_urls>"],
|
||||
"js": ["contentScript.js"],
|
||||
"run_at": "document_start"
|
||||
}
|
||||
],
|
||||
|
||||
"applications": {
|
||||
"gecko": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user