Compare commits
30 Commits
Author | SHA1 | Date | |
---|---|---|---|
bc067d663e | |||
922de5d1d1 | |||
f15fa07880 | |||
2452acf440 | |||
e675bc4372 | |||
a1c8f5bb6e | |||
19571e036f | |||
7911e8a898 | |||
5c4ed146e6 | |||
dcd76d7240 | |||
3dc143c9d8 | |||
21dd898d44 | |||
757adc4722 | |||
26e7b44b36 | |||
675900d0c8 | |||
34d0f821a0 | |||
75e6a73f7f | |||
bd501edba3 | |||
52e7e13957 | |||
e3fc267821 | |||
2c81a30231 | |||
352131be4f | |||
65aadb4624 | |||
ebeeab9ed5 | |||
1f8fb529d6 | |||
56c58896b8 | |||
ac83798388 | |||
ad4af7871a | |||
01aa8eba44 | |||
594e53b38f |
BIN
screenshots/firefox.png
Normal file
BIN
screenshots/firefox.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 257 KiB |
86
src/bg.js
86
src/bg.js
@@ -1,43 +1,51 @@
|
|||||||
const kTST_ID = 'treestyletab@piro.sakura.ne.jp';
|
const kTST_ID = 'treestyletab@piro.sakura.ne.jp';
|
||||||
const MY_EXTENSION_NAME = 'tab-groupcolor';
|
const MY_EXTENSION_NAME = 'tab-groupcolor';
|
||||||
|
let tabIcons = {};
|
||||||
|
|
||||||
var changeIcon = function(color, currentIcon) {
|
var changeIcon = function(color, currentIcon, options) {
|
||||||
var canvas = document.createElement('canvas');
|
var canvas = document.createElement('canvas');
|
||||||
canvas.width = 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') {
|
if (currentIcon && typeof(currentIcon) !== 'undefined' && currentIcon !== null && currentIcon !== "null" && currentIcon !== 'undefined') {
|
||||||
console.log(currentIcon);
|
|
||||||
img.src = currentIcon;
|
img.src = currentIcon;
|
||||||
} else {
|
} 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.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() {
|
||||||
|
canvas.width = this.naturalWidth;
|
||||||
|
canvas.height = this.naturalHeight;
|
||||||
ctx.drawImage(img, 0, 0);
|
ctx.drawImage(img, 0, 0);
|
||||||
ctx.fillStyle = color;
|
ctx.fillStyle = color;
|
||||||
ctx.fillRect(0, 0, 2, 16);
|
if (options.globals.orientation === 'vertical') {
|
||||||
|
ctx.fillRect(0, 0, (options.globals.width / 16) * canvas.width, canvas.height);
|
||||||
|
} else {
|
||||||
|
ctx.fillRect(0, 0, canvas.width, (options.globals.width / 16) * canvas.height);
|
||||||
|
}
|
||||||
|
|
||||||
var link = document.createElement('link');
|
var link = document.createElement('link');
|
||||||
link.type = 'image/x-icon';
|
link.type = 'image/x-icon';
|
||||||
link.rel = 'shortcut icon';
|
link.rel = 'shortcut icon';
|
||||||
link.href = canvas.toDataURL("image/x-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);
|
document.getElementsByTagName('head')[0].appendChild(link);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var generateRandomColor = function(seed) {
|
var generateRandomColor = function(seed) {
|
||||||
var selectColor = function (colorNum, colors) {
|
var colors = ['#e6194b', '#3cb44b', '#ffe119', '#0082c8', '#f58231', '#FFFFFF'];
|
||||||
if (colors < 1) {
|
|
||||||
colors = 1; // defaults to one color - avoid divide by zero
|
var selectColor = function (colorNum) {
|
||||||
}
|
return colors[seed % colors.length]
|
||||||
return "hsl(" + (colorNum * (360 / colors) % 360) + ",100%,50%)";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return selectColor(seed, 8);
|
return selectColor(seed);
|
||||||
};
|
};
|
||||||
|
|
||||||
var registerToTST = async function() {
|
var registerToTST = async function() {
|
||||||
@@ -59,14 +67,22 @@ var getTabParent = (tabs, id, currentTopLevelTabPos) => {
|
|||||||
for (let i = 0; i < tabs.length; i++) {
|
for (let i = 0; i < tabs.length; i++) {
|
||||||
|
|
||||||
//on a root node because there is no opener
|
//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;
|
currentTopLevelTabPos = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tabs[i].id === id) {
|
if (tabs[i].id === id) {
|
||||||
|
|
||||||
|
//get original favicon for this tab
|
||||||
|
let orginalFavIconUrl = tabIcons[id];
|
||||||
|
if (!orginalFavIconUrl) {
|
||||||
|
orginalFavIconUrl = tabs[i].favIconUrl;
|
||||||
|
tabIcons[id] = orginalFavIconUrl;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
parentIndex: currentTopLevelTabPos,
|
parentIndex: currentTopLevelTabPos,
|
||||||
faviconUrl: tabs[i].favIconUrl
|
faviconUrl: orginalFavIconUrl
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
if (tabs[i].children && tabs[i].children.length > 0) {
|
if (tabs[i].children && tabs[i].children.length > 0) {
|
||||||
@@ -84,29 +100,35 @@ var updateAllColorsOnAllTabs = async () => {
|
|||||||
allWindows.forEach(async w => {
|
allWindows.forEach(async w => {
|
||||||
var tstTabs = await browser.runtime.sendMessage(kTST_ID, {
|
var tstTabs = await browser.runtime.sendMessage(kTST_ID, {
|
||||||
type: 'get-tree',
|
type: 'get-tree',
|
||||||
window: w.id
|
window: w.id
|
||||||
});
|
});
|
||||||
|
|
||||||
var changeTabs = (tabs) => {
|
var changeTabs = async (tabs) => {
|
||||||
|
|
||||||
for (let i = 0; i < tabs.length; i++) {
|
for (let i = 0; i < tabs.length; i++) {
|
||||||
|
|
||||||
if (tabs[i].status === 'complete') {
|
if (tabs[i].status === 'complete') {
|
||||||
let t = getTabParent(tstTabs, tabs[i].id);
|
let t = getTabParent(tstTabs, tabs[i].id);
|
||||||
|
let options = await loadOptions();
|
||||||
browser.tabs.executeScript(tabs[i].id, {
|
let tabHost = new URL(tabs[i].url).host;
|
||||||
code: '(' + changeIcon.toString() + ')' +
|
if (tabHost) {
|
||||||
'("' + generateRandomColor(t.parentIndex) + '", "' + t.faviconUrl + '")'
|
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) + ')'
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tabs[i].children && tabs[i].children.length > 0) {
|
if (tabs[i].children && tabs[i].children.length > 0) {
|
||||||
changeTabs(tabs[i].children);
|
await changeTabs(tabs[i].children);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
changeTabs(tstTabs);
|
await changeTabs(tstTabs);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -125,12 +147,24 @@ browser.runtime.onMessageExternal.addListener((aMessage, aSender) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//when something happens with a tab
|
//when something happens with a tab
|
||||||
let tabEvents = ['onUpdated', 'onAttached', 'onDetached', 'onMoved', 'onRemoved']
|
let tabEvents = ['onAttached', 'onDetached', 'onMoved', 'onRemoved']
|
||||||
tabEvents.forEach((ev) => {
|
tabEvents.forEach((ev) => {
|
||||||
browser.tabs[ev].addListener(async (tabId, changeInfo, tab) => {
|
browser.tabs[ev].addListener((tabId, changeInfo, tab) => {
|
||||||
updateAllColorsOnAllTabs();
|
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();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
registerToTST(); // aggressive registration on initial installation
|
registerToTST(); // aggressive registration on initial installation
|
||||||
|
@@ -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.14",
|
||||||
"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"
|
||||||
@@ -14,9 +14,15 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"background": {
|
"background": {
|
||||||
"scripts": ["bg.js"]
|
"scripts": ["bg.js", "utils.js"]
|
||||||
},
|
},
|
||||||
"permissions": [
|
"permissions": [
|
||||||
|
"storage",
|
||||||
|
"webNavigation",
|
||||||
"<all_urls>"
|
"<all_urls>"
|
||||||
]
|
],
|
||||||
|
"options_ui": {
|
||||||
|
"browser_style": true,
|
||||||
|
"page": "options/options.html"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
44
src/options/options.html
Normal file
44
src/options/options.html
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<section id="options-section" class="panel">
|
||||||
|
|
||||||
|
<div class="panel-section panel-section-header">
|
||||||
|
<span class="text-section-header">Indicator options</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="panel-section panel-section-formElements">
|
||||||
|
|
||||||
|
<div class="panel-formElements-item browser-style">
|
||||||
|
<label for="indicator-width">Width:</label>
|
||||||
|
<input type="number" id="indicator-width" max="16" min="1">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="panel-formElements-item browser-style">
|
||||||
|
<label for="indicator-orientation">Orientation:</label>
|
||||||
|
<select id="indicator-orientation">
|
||||||
|
<option value="vertical">Vertical</option>
|
||||||
|
<option value="horizontal">Horizontal</option>
|
||||||
|
</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>
|
||||||
|
|
||||||
|
<script src="../utils.js"></script>
|
||||||
|
<script src="options.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
28
src/options/options.js
Normal file
28
src/options/options.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
function persistOptions() {
|
||||||
|
var globals = {}; //global addon options
|
||||||
|
|
||||||
|
globals = {
|
||||||
|
width: document.querySelector('#indicator-width').value,
|
||||||
|
orientation: document.querySelector('#indicator-orientation').value,
|
||||||
|
ignore: document.querySelector('#ignore').value
|
||||||
|
};
|
||||||
|
|
||||||
|
return browser.storage.local.set({
|
||||||
|
globals: globals
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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,textarea');
|
||||||
|
for (var i = 0; i < list.length; i++) {
|
||||||
|
list[i].addEventListener('change', (ev) => {
|
||||||
|
persistOptions();
|
||||||
|
});
|
||||||
|
}
|
9
src/utils.js
Normal file
9
src/utils.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
function loadOptions() {
|
||||||
|
return browser.storage.local.get({
|
||||||
|
globals: {
|
||||||
|
width: 5,
|
||||||
|
orientation: 'horizontal',
|
||||||
|
ignore: 'web.whatsapp.com'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
Reference in New Issue
Block a user