// ==UserScript==
// @name           ColofulTab_by_Palette.uc.js
// @namespace      http://d.hatena.ne.jp/Griever/
// @include        main
// ==/UserScript==

(function () {
    var palette = (function(){
        var c = '69cf';//0～F まで好きなように。
        var colorArray = new Array();
        var clen = c.length;
        for(r = 0; r < clen ; r++)
            for(g = 0; g < clen; g++)
                for(b = 0; b < clen; b++)
                    colorArray.push('#' + c[r] + c[g] + c[b]);
        return colorArray;
    })();

    function createColorCode(dom){
        var res = 0;
        Array.forEach(dom, function(s){
            res += s.charCodeAt(0);
        });
        return palette[res%palette.length];
    }

    gBrowser.mPanelContainer.addEventListener('DOMContentLoaded', function(e){
        var doc = e.target;
        var defView = doc.defaultView;
        if (!defView || defView != defView.parent) return;
        var dom = doc.domain;
        var color = dom? createColorCode(dom): '';
        var tab = gBrowser.mTabs[gBrowser.getBrowserIndexForDocument(doc)];
        tab.style.backgroundColor = color;
    }, false);
})();
