Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
e675bc4372 | |||
a1c8f5bb6e | |||
19571e036f | |||
7911e8a898 | |||
5c4ed146e6 | |||
dcd76d7240 | |||
3dc143c9d8 | |||
21dd898d44 | |||
757adc4722 | |||
26e7b44b36 | |||
675900d0c8 | |||
34d0f821a0 | |||
75e6a73f7f | |||
bd501edba3 | |||
52e7e13957 | |||
e3fc267821 | |||
2c81a30231 | |||
352131be4f | |||
65aadb4624 |
Before Width: | Height: | Size: 257 KiB After Width: | Height: | Size: 257 KiB |
34
src/bg.js
34
src/bg.js
@@ -4,31 +4,36 @@ 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);
|
||||
}
|
||||
};
|
||||
@@ -41,7 +46,7 @@ var generateRandomColor = function(seed) {
|
||||
return "hsl(" + (colorNum * (360 / colors) % 360) + ",100%,50%)";
|
||||
}
|
||||
|
||||
return selectColor(seed, 8);
|
||||
return selectColor(seed, 7);
|
||||
};
|
||||
|
||||
var registerToTST = async function() {
|
||||
@@ -106,11 +111,16 @@ var updateAllColorsOnAllTabs = async () => {
|
||||
if (tabs[i].status === 'complete') {
|
||||
let t = getTabParent(tstTabs, tabs[i].id);
|
||||
let options = await loadOptions();
|
||||
|
||||
browser.tabs.executeScript(tabs[i].id, {
|
||||
code: '(' + changeIcon.toString() + ')' +
|
||||
'("' + generateRandomColor(t.parentIndex) + '", "' + t.faviconUrl + '", ' + JSON.stringify(options) + ')'
|
||||
});
|
||||
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) + ')'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (tabs[i].children && tabs[i].children.length > 0) {
|
||||
|
@@ -2,7 +2,7 @@
|
||||
"description": "Color tabs based on their parent.",
|
||||
"manifest_version": 2,
|
||||
"name": "Color Tab Group",
|
||||
"version": "0.0.5",
|
||||
"version": "0.0.13",
|
||||
"homepage_url": "https://git.e.tern.al/s2/tab-groupcolor",
|
||||
"icons": {
|
||||
"48": "img/icon-48.png"
|
||||
|
@@ -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>
|
||||
|
@@ -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();
|
||||
|
@@ -2,7 +2,8 @@ function loadOptions() {
|
||||
return browser.storage.local.get({
|
||||
globals: {
|
||||
width: 3,
|
||||
orientation: 'vertical'
|
||||
orientation: 'vertical',
|
||||
ignore: ''
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user