Compare commits
3 Commits
v0.0.3
...
81f731ad77
Author | SHA1 | Date | |
---|---|---|---|
81f731ad77 | |||
e13a5b4c3b | |||
23564b3c29 |
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
## What it does
|
## What it does
|
||||||
|
|
||||||
**Please install [Tree Style Tab](https://addons.mozilla.org/firefox/addon/tree-style-tab/) before installing this extension, because this extension depends on it!**
|
|
||||||
|
|
||||||
This addon would like to color tabs based on the parent tab that opened the tab.
|
This addon would like to color tabs based on the parent tab that opened the tab.
|
||||||
So say I am at work searching for a solution to a javascript problem on stackoverflow, so I open a bunch of tabs with possible solutions. Then I get distracted, and I start looking for honey badger images on google images, I open a bunch of tabs with honey badger images.
|
So say I am at work searching for a solution to a javascript problem on stackoverflow, so I open a bunch of tabs with possible solutions. Then I get distracted, and I start looking for honey badger images on google images, I open a bunch of tabs with honey badger images.
|
||||||
Now all my tabs are mixed up with javascript snippets and honey badgers.
|
Now all my tabs are mixed up with javascript snippets and honey badgers.
|
||||||
@@ -14,7 +12,4 @@ 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
|
**Please install [Tree Style Tab](https://addons.mozilla.org/firefox/addon/tree-style-tab/) before installing this extension, because this extension depends on it!**
|
||||||
- on pages that don't allow content scripts (amo for example)
|
|
||||||
- on pages that dynamically change the favicon
|
|
||||||
- a lot of other cases
|
|
||||||
|
50
src/bg.js
50
src/bg.js
@@ -7,15 +7,7 @@ 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();
|
||||||
|
|
||||||
if (currentIcon && typeof(currentIcon) !== 'undefined' && currentIcon !== null && currentIcon !== 'undefined') {
|
|
||||||
console.log(currentIcon);
|
|
||||||
img.src = 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;
|
||||||
@@ -66,7 +58,7 @@ var getTabParent = (tabs, id, currentTopLevelTabPos) => {
|
|||||||
if (tabs[i].id === id) {
|
if (tabs[i].id === id) {
|
||||||
return {
|
return {
|
||||||
parentIndex: currentTopLevelTabPos,
|
parentIndex: currentTopLevelTabPos,
|
||||||
faviconUrl: tabs[i].favIconUrl
|
faviconUrl: tabs[i].faviconUrl
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
if (tabs[i].children && tabs[i].children.length > 0) {
|
if (tabs[i].children && tabs[i].children.length > 0) {
|
||||||
@@ -87,27 +79,15 @@ var updateAllColorsOnAllTabs = async () => {
|
|||||||
window: w.id
|
window: w.id
|
||||||
});
|
});
|
||||||
|
|
||||||
var changeTabs = (tabs) => {
|
for (let i = 0; i < tstTabs.length; i++) {
|
||||||
|
if (tstTabs[i].status === 'complete') {
|
||||||
for (let i = 0; i < tabs.length; i++) {
|
let t = getTabParent(tstTabs, tstTabs[i].id);
|
||||||
|
browser.tabs.executeScript(tstTabs[i].id, {
|
||||||
if (tabs[i].status === 'complete') {
|
|
||||||
let t = getTabParent(tstTabs, 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 + '")'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tabs[i].children && tabs[i].children.length > 0) {
|
|
||||||
changeTabs(tabs[i].children);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
changeTabs(tstTabs);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -124,13 +104,21 @@ browser.runtime.onMessageExternal.addListener((aMessage, aSender) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//when something happens with a tab
|
//when a tab is created
|
||||||
let tabEvents = ['onUpdated', 'onAttached', 'onDetached', 'onMoved', 'onRemoved']
|
browser.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
|
||||||
tabEvents.forEach((ev) => {
|
var tstTabs = await browser.runtime.sendMessage(kTST_ID, {
|
||||||
browser.tabs[ev].addListener(async (tabId, changeInfo, tab) => {
|
type: 'get-tree',
|
||||||
updateAllColorsOnAllTabs();
|
window: tab.windowId
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (tab.status === 'complete') {
|
||||||
|
var t = getTabParent(tstTabs, tab.id);
|
||||||
|
|
||||||
|
browser.tabs.executeScript(tab.id, {
|
||||||
|
code: '(' + changeIcon.toString() + ')' +
|
||||||
|
'("' + generateRandomColor(t.parentIndex) + '", "' + t.faviconUrl + '")'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
registerToTST(); // aggressive registration on initial installation
|
registerToTST(); // aggressive registration on initial installation
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.0 KiB |
BIN
src/img/icon.png
BIN
src/img/icon.png
Binary file not shown.
Before Width: | Height: | Size: 432 KiB After Width: | Height: | Size: 435 KiB |
@@ -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.3",
|
"version": "0.0.1",
|
||||||
"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"
|
||||||
|
Reference in New Issue
Block a user