8 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
s2
e73e806dca readme 2017-12-12 08:34:23 +01:00
s2
0a00b1c1f1 v0.0.2 2017-12-12 08:28:08 +01:00
s2
41d70eb3f0 handle other tab events 2017-12-12 08:27:40 +01:00
s2
724bec321b fix updateAllColorsOnAllTabs 2017-12-12 08:21:31 +01:00
s2
90f7108eee icons 2017-12-12 08:21:31 +01:00
s2
c56454a097 just text 2017-12-12 08:21:25 +01:00
6 changed files with 50 additions and 37 deletions

View File

@@ -2,6 +2,8 @@
## 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.
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.
@@ -12,4 +14,7 @@ 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.
**Please install [Tree Style Tab](https://addons.mozilla.org/firefox/addon/tree-style-tab/) before installing this extension, because this extension depends on it!**
But it will not work
- on pages that don't allow content scripts (amo for example)
- on pages that dynamically change the favicon
- a lot of other cases

View File

@@ -1,25 +1,21 @@
const kTST_ID = 'treestyletab@piro.sakura.ne.jp';
const MY_EXTENSION_NAME = 'tab-groupcolor';
var changeIcon = function(color) {
var getFavicon = function(){
var favicon = undefined;
var nodeList = document.getElementsByTagName("link");
for (var i = 0; i < nodeList.length; i++)
{
if ((nodeList[i].getAttribute("rel") == "icon") || (nodeList[i].getAttribute("rel") == "shortcut icon")) {
favicon = nodeList[i].getAttribute("href");
}
}
return favicon;
};
var changeIcon = function(color, currentIcon) {
var canvas = document.createElement('canvas');
canvas.width = 16;
canvas.height = 16;
var ctx = canvas.getContext('2d');
var img = new Image();
img.src = getFavicon();
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() {
ctx.drawImage(img, 0, 0);
ctx.fillStyle = color;
@@ -34,7 +30,7 @@ var changeIcon = function(color) {
};
var generateRandomColor = function(seed) {
var selectColor = function (colorNum, colors){
var selectColor = function (colorNum, colors) {
if (colors < 1) {
colors = 1; // defaults to one color - avoid divide by zero
}
@@ -68,7 +64,10 @@ var getTabParent = (tabs, id, currentTopLevelTabPos) => {
}
if (tabs[i].id === id) {
return currentTopLevelTabPos;
return {
parentIndex: currentTopLevelTabPos,
faviconUrl: tabs[i].favIconUrl
};
} else {
if (tabs[i].children && tabs[i].children.length > 0) {
let ret = getTabParent(tabs[i].children, id, currentTopLevelTabPos);
@@ -88,13 +87,27 @@ var updateAllColorsOnAllTabs = async () => {
window: w.id
});
for (let i = 0; i < tstTabs.length; i++) {
if (tstTabs[i].status === 'complete') {
browser.tabs.executeScript(tstTabs[i].id, {
code: '(' + changeIcon.toString() + ')("' + generateRandomColor(getTabParent(tstTabs, tstTabs[i].id)) + '")'
});
var changeTabs = (tabs) => {
for (let i = 0; i < tabs.length; i++) {
if (tabs[i].status === 'complete') {
let t = getTabParent(tstTabs, tabs[i].id);
browser.tabs.executeScript(tabs[i].id, {
code: '(' + changeIcon.toString() + ')' +
'("' + generateRandomColor(t.parentIndex) + '", "' + t.faviconUrl + '")'
});
}
if (tabs[i].children && tabs[i].children.length > 0) {
changeTabs(tabs[i].children);
}
}
}
};
changeTabs(tstTabs);
});
}
@@ -111,18 +124,13 @@ browser.runtime.onMessageExternal.addListener((aMessage, aSender) => {
}
});
//when a tab is created
browser.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
var tstTab = await browser.runtime.sendMessage(kTST_ID, {
type: 'get-tree',
window: tab.windowId
//when something happens with a tab
let tabEvents = ['onUpdated', 'onAttached', 'onDetached', 'onMoved', 'onRemoved']
tabEvents.forEach((ev) => {
browser.tabs[ev].addListener(async (tabId, changeInfo, tab) => {
updateAllColorsOnAllTabs();
});
if (tab.status === 'complete') {
browser.tabs.executeScript(tab.id, {
code: '(' + changeIcon.toString() + ')("' + generateRandomColor(getTabParent(tstTab, tab.id)) + '")'
});
}
});
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.0 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 435 KiB

After

Width:  |  Height:  |  Size: 432 KiB

View File

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