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

14
.editorconfig Normal file
View File

@@ -0,0 +1,14 @@
# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = tab
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
[*.md]
max_line_length = off
trim_trailing_whitespace = false

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/.project

68
.jscsrc Normal file
View File

@@ -0,0 +1,68 @@
{
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"case",
"return",
"try",
"catch"
],
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": true,
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true
},
"requireSpaceBetweenArguments": true,
"disallowMultipleVarDecl": true,
"requireVarDeclFirst": false,
"requireBlocksOnNewline": false,
"disallowEmptyBlocks": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowDanglingUnderscores": false,
"requireCommaBeforeLineBreak": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpaceBeforePostfixUnaryOperators": true,
"disallowSpaceBeforeBinaryOperators": [
","
],
"requireSpacesInForStatement": true,
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceAfterBinaryOperators": true,
"disallowKeywords": [
"with"
],
"validateIndentation": "\t",
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true,
"disallowKeywordsOnNewLine": [
"else"
],
"requireLineFeedAtFileEnd": true,
"requireCapitalizedConstructors": true,
"requireDotNotation": false,
"disallowNewlineBeforeBlockStatements": true,
"disallowMultipleLineStrings": true,
"requireSpaceBeforeObjectValues": true
}

5
README.md Normal file
View File

@@ -0,0 +1,5 @@
# colortabgroups
## What it does
color tabs based on their parent.

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",
}