options
This commit is contained in:
33
src/bg.js
33
src/bg.js
@@ -1,7 +1,7 @@
|
||||
const kTST_ID = 'treestyletab@piro.sakura.ne.jp';
|
||||
const MY_EXTENSION_NAME = 'tab-groupcolor';
|
||||
|
||||
var changeIcon = function(color, currentIcon) {
|
||||
var changeIcon = function(color, currentIcon, options) {
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = 16;
|
||||
canvas.height = 16;
|
||||
@@ -17,7 +17,12 @@ var changeIcon = function(color, currentIcon) {
|
||||
img.onload = function() {
|
||||
ctx.drawImage(img, 0, 0);
|
||||
ctx.fillStyle = color;
|
||||
ctx.fillRect(0, 0, 3, 16);
|
||||
if (options.globals.orientation === 'vertical') {
|
||||
ctx.fillRect(0, 0, options.globals.width, 16);
|
||||
} else {
|
||||
ctx.fillRect(0, 0, 16, options.globals.width);
|
||||
}
|
||||
|
||||
|
||||
var link = document.createElement('link');
|
||||
link.type = 'image/x-icon';
|
||||
@@ -62,9 +67,18 @@ var getTabParent = (tabs, id, currentTopLevelTabPos) => {
|
||||
}
|
||||
|
||||
if (tabs[i].id === id) {
|
||||
|
||||
//get original favicon for this tab
|
||||
let orginalFavIconUrl = tabs[i].favIconUrl;
|
||||
//let orginalFavIconUrl = await browser.sessions.getTabValue(id, 'orginalFavIconUrl');
|
||||
// if (!orginalFavIconUrl) {
|
||||
// orginalFavIconUrl = tabs[i].favIconUrl;
|
||||
// await browser.sessions.setTabValue(id, 'orginalFavIconUrl', orginalFavIconUrl);
|
||||
// }
|
||||
|
||||
return {
|
||||
parentIndex: currentTopLevelTabPos,
|
||||
faviconUrl: tabs[i].favIconUrl
|
||||
faviconUrl: orginalFavIconUrl
|
||||
};
|
||||
} else {
|
||||
if (tabs[i].children && tabs[i].children.length > 0) {
|
||||
@@ -92,9 +106,11 @@ var updateAllColorsOnAllTabs = async () => {
|
||||
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 + '")'
|
||||
loadOptions().then((options) => {
|
||||
browser.tabs.executeScript(tabs[i].id, {
|
||||
code: '(' + changeIcon.toString() + ')' +
|
||||
'("' + generateRandomColor(t.parentIndex) + '", "' + t.faviconUrl + '", ' + JSON.stringify(options) + ')'
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -130,5 +146,10 @@ tabEvents.forEach((ev) => {
|
||||
});
|
||||
});
|
||||
|
||||
//when the options are updated
|
||||
browser.storage.onChanged.addListener((changes) => {
|
||||
updateAllColorsOnAllTabs();
|
||||
});
|
||||
|
||||
|
||||
registerToTST(); // aggressive registration on initial installation
|
||||
|
Reference in New Issue
Block a user