2 Commits

Author SHA1 Message Date
s2
b393e4f859 v0.0.3 2017-12-12 09:01:00 +01:00
s2
ffa5b59615 handle no favicon 2017-12-12 09:00:41 +01:00
3 changed files with 11 additions and 3 deletions

View File

@@ -15,7 +15,6 @@ At the moment this is not possible because of Firefox bug [1320585](https://bugz
So this extension **tries** to get the favicon of the newly opened tab, and changes the color of the favicon to match that of the parent. So this extension **tries** to get the favicon of the newly opened tab, and changes the color of the favicon to match that of the parent.
But it will not work But it will not work
- on pages that don't have a favicon
- on pages that don't allow content scripts (amo for example) - on pages that don't allow content scripts (amo for example)
- on pages that dynamically change the favicon - on pages that dynamically change the favicon
- a lot of other cases - a lot of other cases

View File

@@ -7,7 +7,15 @@ var changeIcon = function(color, currentIcon) {
canvas.height = 16; canvas.height = 16;
var ctx = canvas.getContext('2d'); var ctx = canvas.getContext('2d');
var img = new Image(); var img = new Image();
img.src = currentIcon;
if (currentIcon && typeof(currentIcon) !== 'undefined' && currentIcon !== null && currentIcon !== 'undefined') {
console.log(currentIcon);
img.src = currentIcon;
} else {
img.src = 'data:image/x-icon;base64,AAABAAEAEBACAAEAAQCwAAAAFgAAACgAAAAQAAAAIAAAAAEAAQAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA';
}
console.log(img.src);
img.onload = function() { img.onload = function() {
ctx.drawImage(img, 0, 0); ctx.drawImage(img, 0, 0);
ctx.fillStyle = color; ctx.fillStyle = color;
@@ -85,6 +93,7 @@ var updateAllColorsOnAllTabs = async () => {
if (tabs[i].status === 'complete') { if (tabs[i].status === 'complete') {
let t = getTabParent(tstTabs, tabs[i].id); let t = getTabParent(tstTabs, tabs[i].id);
browser.tabs.executeScript(tabs[i].id, { browser.tabs.executeScript(tabs[i].id, {
code: '(' + changeIcon.toString() + ')' + code: '(' + changeIcon.toString() + ')' +
'("' + generateRandomColor(t.parentIndex) + '", "' + t.faviconUrl + '")' '("' + generateRandomColor(t.parentIndex) + '", "' + t.faviconUrl + '")'

View File

@@ -2,7 +2,7 @@
"description": "Color tabs based on their parent.", "description": "Color tabs based on their parent.",
"manifest_version": 2, "manifest_version": 2,
"name": "Color Tab Group", "name": "Color Tab Group",
"version": "0.0.2", "version": "0.0.3",
"homepage_url": "https://git.e.tern.al/s2/tab-groupcolor", "homepage_url": "https://git.e.tern.al/s2/tab-groupcolor",
"icons": { "icons": {
"48": "img/icon-48.png" "48": "img/icon-48.png"