25 Commits

Author SHA1 Message Date
s2
922de5d1d1 v0.0.14 2017-12-13 16:47:04 +01:00
s2
f15fa07880 remove console log 2017-12-13 16:44:59 +01:00
s2
2452acf440 use fixed colors 2017-12-13 15:54:20 +01:00
s2
e675bc4372 v0.0.13 2017-12-13 13:48:07 +01:00
s2
a1c8f5bb6e use 7 colors 2017-12-13 13:46:15 +01:00
s2
19571e036f v0.0.12 2017-12-13 11:35:48 +01:00
s2
7911e8a898 handle "null" favicon 2017-12-13 11:34:39 +01:00
s2
5c4ed146e6 default for ignore value 2017-12-13 11:31:13 +01:00
s2
dcd76d7240 v0.0.11 2017-12-13 11:21:36 +01:00
s2
3dc143c9d8 pffff 2017-12-13 11:21:25 +01:00
s2
21dd898d44 v0.0.10 2017-12-13 11:19:35 +01:00
s2
757adc4722 need to test more 2017-12-13 11:19:20 +01:00
s2
26e7b44b36 v0.0.9 2017-12-13 11:15:59 +01:00
s2
675900d0c8 move screenshots folder 2017-12-13 11:15:37 +01:00
s2
34d0f821a0 actually persist hosts option 2017-12-13 11:15:06 +01:00
s2
75e6a73f7f v0.0.8 2017-12-13 10:31:28 +01:00
s2
bd501edba3 ignore hosts option 2017-12-13 10:30:18 +01:00
s2
52e7e13957 v0.0.7 2017-12-13 09:04:28 +01:00
s2
e3fc267821 fix favicon size 2017-12-13 09:04:14 +01:00
s2
2c81a30231 v0.0.6 2017-12-13 08:24:16 +01:00
s2
352131be4f ws 2017-12-13 08:23:50 +01:00
s2
65aadb4624 don't clutter the page with favicons 2017-12-13 08:22:37 +01:00
s2
ebeeab9ed5 v0.0.5 2017-12-12 22:31:55 +01:00
s2
1f8fb529d6 fix icons 2017-12-12 22:28:29 +01:00
s2
56c58896b8 reformat 2017-12-12 15:00:45 +01:00
6 changed files with 56 additions and 30 deletions

View File

Before

Width:  |  Height:  |  Size: 257 KiB

After

Width:  |  Height:  |  Size: 257 KiB

View File

@@ -1,46 +1,51 @@
const kTST_ID = 'treestyletab@piro.sakura.ne.jp';
const MY_EXTENSION_NAME = 'tab-groupcolor';
let tabIcons = {};
var changeIcon = function(color, currentIcon, options) {
var canvas = document.createElement('canvas');
canvas.width = 16;
canvas.height = 16;
var ctx = canvas.getContext('2d');
var img = new Image();
if (currentIcon && typeof(currentIcon) !== 'undefined' && currentIcon !== null && currentIcon !== 'undefined') {
if (currentIcon && typeof(currentIcon) !== 'undefined' && currentIcon !== null && currentIcon !== "null" && currentIcon !== 'undefined') {
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';
}
img.onload = function() {
canvas.width = this.naturalWidth;
canvas.height = this.naturalHeight;
ctx.drawImage(img, 0, 0);
ctx.fillStyle = color;
if (options.globals.orientation === 'vertical') {
ctx.fillRect(0, 0, options.globals.width, 16);
ctx.fillRect(0, 0, (options.globals.width / 16) * canvas.width, canvas.height);
} else {
ctx.fillRect(0, 0, 16, options.globals.width);
ctx.fillRect(0, 0, canvas.width, (options.globals.width / 16) * canvas.height);
}
var link = document.createElement('link');
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
link.href = canvas.toDataURL("image/x-icon");
link.id = 'tab-groupcolor' + '-favicon';
var oldicon = document.getElementById('tab-groupcolor' + '-favicon');
if (oldicon) {
oldicon.outerHTML = '';
delete oldicon;
}
document.getElementsByTagName('head')[0].appendChild(link);
}
};
var generateRandomColor = function(seed) {
var selectColor = function (colorNum, colors) {
if (colors < 1) {
colors = 1; // defaults to one color - avoid divide by zero
}
return "hsl(" + (colorNum * (360 / colors) % 360) + ",100%,50%)";
var colors = ['#e6194b', '#3cb44b', '#ffe119', '#0082c8', '#f58231', '#FFFFFF'];
var selectColor = function (colorNum) {
return colors[seed % colors.length]
}
return selectColor(seed, 8);
return selectColor(seed);
};
var registerToTST = async function() {
@@ -58,21 +63,21 @@ var registerToTST = async function() {
};
//returns the index of the tabs array object that contains the tab with the passed id
var getTabParent = async (tabs, id, currentTopLevelTabPos) => {
var getTabParent = (tabs, id, currentTopLevelTabPos) => {
for (let i = 0; i < tabs.length; i++) {
//on a root node because there is no opener
if (typeof(tabs[i].openerTabId) === 'undefined' || tabs[i].openerTabId === tabs[i].id) {
if (!tabs[i].openerTabId || typeof(tabs[i].openerTabId) === 'undefined' || tabs[i].openerTabId === tabs[i].id) {
currentTopLevelTabPos = i;
}
if (tabs[i].id === id) {
//get original favicon for this tab
let orginalFavIconUrl = await browser.sessions.getTabValue(id, 'orginalFavIconUrl');
let orginalFavIconUrl = tabIcons[id];
if (!orginalFavIconUrl) {
orginalFavIconUrl = tabs[i].favIconUrl;
await browser.sessions.setTabValue(id, 'orginalFavIconUrl', orginalFavIconUrl);
tabIcons[id] = orginalFavIconUrl;
}
return {
@@ -81,7 +86,7 @@ var getTabParent = async (tabs, id, currentTopLevelTabPos) => {
};
} else {
if (tabs[i].children && tabs[i].children.length > 0) {
let ret = await getTabParent(tabs[i].children, id, currentTopLevelTabPos);
let ret = getTabParent(tabs[i].children, id, currentTopLevelTabPos);
if (ret) {
return ret;
}
@@ -95,7 +100,7 @@ var updateAllColorsOnAllTabs = async () => {
allWindows.forEach(async w => {
var tstTabs = await browser.runtime.sendMessage(kTST_ID, {
type: 'get-tree',
window: w.id
window: w.id
});
var changeTabs = async (tabs) => {
@@ -103,14 +108,18 @@ var updateAllColorsOnAllTabs = async () => {
for (let i = 0; i < tabs.length; i++) {
if (tabs[i].status === 'complete') {
let t = await getTabParent(tstTabs, tabs[i].id);
loadOptions().then((options) => {
let t = getTabParent(tstTabs, tabs[i].id);
let options = await loadOptions();
let tabHost = new URL(tabs[i].url).host;
if (tabHost) {
tabHost = tabHost.toLowerCase();
}
if (!(options.globals.ignore && options.globals.ignore.split('\n').includes(tabHost))) {
browser.tabs.executeScript(tabs[i].id, {
code: '(' + changeIcon.toString() + ')' +
'("' + generateRandomColor(t.parentIndex) + '", "' + t.faviconUrl + '", ' + JSON.stringify(options) + ')'
'("' + generateRandomColor(t.parentIndex) + '", "' + t.faviconUrl + '", ' + JSON.stringify(options) + ')'
});
});
}
}
if (tabs[i].children && tabs[i].children.length > 0) {
@@ -138,13 +147,20 @@ browser.runtime.onMessageExternal.addListener((aMessage, aSender) => {
});
//when something happens with a tab
let tabEvents = ['onUpdated', 'onAttached', 'onDetached', 'onMoved', 'onRemoved']
let tabEvents = ['onAttached', 'onDetached', 'onMoved', 'onRemoved']
tabEvents.forEach((ev) => {
browser.tabs[ev].addListener(async (tabId, changeInfo, tab) => {
browser.tabs[ev].addListener((tabId, changeInfo, tab) => {
updateAllColorsOnAllTabs();
});
});
//when a tab reloads
browser.webNavigation.onCompleted.addListener((details) => {
delete tabIcons[details.tabId];
updateAllColorsOnAllTabs();
});
//when the options are updated
browser.storage.onChanged.addListener((changes) => {
updateAllColorsOnAllTabs();

View File

@@ -2,7 +2,7 @@
"description": "Color tabs based on their parent.",
"manifest_version": 2,
"name": "Color Tab Group",
"version": "0.0.4",
"version": "0.0.14",
"homepage_url": "https://git.e.tern.al/s2/tab-groupcolor",
"icons": {
"48": "img/icon-48.png"
@@ -18,7 +18,7 @@
},
"permissions": [
"storage",
"sessions",
"webNavigation",
"<all_urls>"
],
"options_ui": {

View File

@@ -26,6 +26,13 @@
</select>
</div>
<div class="panel-formElements-item browser-style">
<label for="ignore">Ignore hosts (one per line - ex.: google.com):</label>
</div>
<div class="panel-formElements-item browser-style">
<textarea id="ignore"></textarea>
</div>
</div>
</section>

View File

@@ -3,7 +3,8 @@ function persistOptions() {
globals = {
width: document.querySelector('#indicator-width').value,
orientation: document.querySelector('#indicator-orientation').value
orientation: document.querySelector('#indicator-orientation').value,
ignore: document.querySelector('#ignore').value
};
return browser.storage.local.set({
@@ -15,10 +16,11 @@ document.addEventListener('DOMContentLoaded', () => {
loadOptions().then((options) => {
document.querySelector('#indicator-width').value = options.globals.width;
document.querySelector('#indicator-orientation').value = options.globals.orientation;
document.querySelector('#ignore').value = options.globals.ignore;
});
});
var list = document.querySelectorAll('select,input');
var list = document.querySelectorAll('select,input,textarea');
for (var i = 0; i < list.length; i++) {
list[i].addEventListener('change', (ev) => {
persistOptions();

View File

@@ -2,7 +2,8 @@ function loadOptions() {
return browser.storage.local.get({
globals: {
width: 3,
orientation: 'vertical'
orientation: 'vertical',
ignore: ''
}
});
}