3 Commits

Author SHA1 Message Date
s2
81f731ad77 bo 2017-12-11 22:29:30 +01:00
s2
e13a5b4c3b nicyties 2017-12-11 21:28:27 +01:00
s2
23564b3c29 just text 2017-12-11 21:27:14 +01:00
2 changed files with 17 additions and 21 deletions

View File

@@ -1,25 +1,13 @@
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();
img.src = currentIcon;
img.onload = function() {
ctx.drawImage(img, 0, 0);
ctx.fillStyle = color;
@@ -34,7 +22,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 +56,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);
@@ -90,8 +81,10 @@ var updateAllColorsOnAllTabs = async () => {
for (let i = 0; i < tstTabs.length; i++) {
if (tstTabs[i].status === 'complete') {
let t = getTabParent(tstTabs, tstTabs[i].id);
browser.tabs.executeScript(tstTabs[i].id, {
code: '(' + changeIcon.toString() + ')("' + generateRandomColor(getTabParent(tstTabs, tstTabs[i].id)) + '")'
code: '(' + changeIcon.toString() + ')' +
'("' + generateRandomColor(t.parentIndex) + '", "' + t.faviconUrl + '")'
});
}
}
@@ -113,14 +106,17 @@ 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, {
var tstTabs = await browser.runtime.sendMessage(kTST_ID, {
type: 'get-tree',
window: tab.windowId
});
if (tab.status === 'complete') {
var t = getTabParent(tstTabs, tab.id);
browser.tabs.executeScript(tab.id, {
code: '(' + changeIcon.toString() + ')("' + generateRandomColor(getTabParent(tstTab, tab.id)) + '")'
code: '(' + changeIcon.toString() + ')' +
'("' + generateRandomColor(t.parentIndex) + '", "' + t.faviconUrl + '")'
});
}
});

View File

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