commit 0c72a810d2f6adb938c0ac81ef8cc525439c9a76 Author: s2 Date: Mon Dec 11 12:46:54 2017 +0100 initial draft diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ac287db --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8fe4fa --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.project diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..18f8586 --- /dev/null +++ b/.jscsrc @@ -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 +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..2b59c7c --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# colortabgroups + +## What it does + +color tabs based on their parent. diff --git a/src/bg.js b/src/bg.js new file mode 100644 index 0000000..94d9657 --- /dev/null +++ b/src/bg.js @@ -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)); diff --git a/src/manifest.json b/src/manifest.json new file mode 100644 index 0000000..71194a7 --- /dev/null +++ b/src/manifest.json @@ -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", +}