initial draft

This commit is contained in:
s2
2017-12-11 12:46:54 +01:00
commit 0c72a810d2
6 changed files with 139 additions and 0 deletions

44
src/bg.js Normal file
View File

@@ -0,0 +1,44 @@
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) {
var canvas = document.createElement('canvas');
canvas.width = 16;
canvas.height = 16;
var ctx = canvas.getContext('2d');
var img = new Image();
img.src = getFavicon();
img.onload = function() {
ctx.drawImage(img, 0, 0);
ctx.fillStyle = color;
ctx.fillRect(0, 0, 2, 16);
var link = document.createElement('link');
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
link.href = canvas.toDataURL("image/x-icon");
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%)";
}
return selectColor(seed, 8);
}
changeIcon(generateRandomColor(1));

7
src/manifest.json Normal file
View File

@@ -0,0 +1,7 @@
{
"description": "color tabs based on their parent.",
"manifest_version": 2,
"name": "colortabgroups",
"version": "0.0.1",
"homepage_url": "https://git.e.tern.al/s2/colortabgroups",
}