handle no favicon

This commit is contained in:
s2
2017-12-12 09:00:41 +01:00
parent e73e806dca
commit ffa5b59615
2 changed files with 10 additions and 2 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 + '")'