initial draft
This commit is contained in:
44
src/bg.js
Normal file
44
src/bg.js
Normal 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
7
src/manifest.json
Normal 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",
|
||||
}
|
Reference in New Issue
Block a user