【问题标题】:How can I change the background color of the firefox address bar based on protocol?如何根据协议更改firefox地址栏的背景颜色?
【发布时间】:2015-05-12 21:24:37
【问题描述】:

我希望能够根据协议更改 Firefox 中地址栏的背景颜色。我该怎么做?

例如当使用 https 时,bg-color: blue 混合内容警告:橙色 ev-证书:绿色 无效证书:红色

【问题讨论】:

标签: css firefox firefox-addon


【解决方案1】:

这是我很久以前在 Firefox 7 中所做的,现在看它有很多问题,但它确实可以解决您需要的技巧,但肯定应该改进代码:

var {Cc, Ci} = require('chrome');
var sss = Cc['@mozilla.org/content/style-sheet-service;1'].getService(Ci.nsIStyleSheetService);
var ios = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService);
var windowUtils = require('window-utils');
var wm = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator);

exports.main = function() {
    //nothing to export
};

var aWin = wm.getMostRecentWindow('navigator:browser'); //aWin stands for anyWindow. this is used by stuff to use functions like encodeURI

//hide the extended label when a page is verified
var identityBoxCss = '.verifiedDomain .plain {display:none}';
var identityBoxCssData = 'data:text/css;charset=utf-8,' + aWin.encodeURI(identityBoxCss);
var identityBoxCssUri = ios.newURI(identityBoxCssData, null, null);
//end hide the extended label when a page is verified
//url bar colorize
var gUrlBarColorize = {
    func: function(win) {
        var identityIconLabel = win.document.getElementById('identity-icon-label');
        var identityBox = win.document.getElementById('identity-box');
        var gURLBar = win.gURLBar;
        if (gURLBar.value.search(/https/i) == 0) {
            if ((identityBox.classList.contains('verifiedDomain') || identityBox.classList.contains('verifiedIdentity'))&& identityIconLabel.value.length > 0) {
                gURLBar.style.backgroundColor = '#D0F7B9';
            } else {
                gURLBar.style.backgroundColor = '#F8D6DE';
            }
        } else {
            gURLBar.style.backgroundColor = '';
        }
    }
};
//end - url bar colorize
//hide icons in bookmarks toolbar
var bookmarksToolbarCss = '.bookmark-item .toolbarbutton-icon {display:none}';
var bookmarksToolbarCssData = 'data:text/css;charset=utf-8,' + aWin.encodeURI(bookmarksToolbarCss);
var bookmarksToolbarCssUri = ios.newURI(bookmarksToolbarCssData, null, null);
//end - hide icons in bookmarks toolbar

var wt = new windowUtils.WindowTracker({
    onTrack: function (window) {
        //hide the extended label when a page is verified
        var IdentityBox = window.document.getElementById('identity-box');
        if (IdentityBox) {
            if (sss.sheetRegistered(identityBoxCssUri, sss.USER_SHEET)) {
                sss.unregisterSheet(identityBoxCssUri, sss.USER_SHEET);
            }
            sss.loadAndRegisterSheet(identityBoxCssUri, sss.USER_SHEET);
        }
        //end hide the extended label when a page is verified
        //url bar colorize
        if (window.gBrowser) {
            window.FF7TweaksForScot = {}
            window.FF7TweaksForScot.gUrlBarColorize = function() { gUrlBarColorize.func(window) };
            window.FF7TweaksForScot.gUrlBarColorize();
            window.gBrowser.addEventListener('load', window.FF7TweaksForScot.gUrlBarColorize, true);
            window.gBrowser.addEventListener('pageshow', window.FF7TweaksForScot.gUrlBarColorize, true);
            window.gBrowser.tabContainer.addEventListener('TabSelect', window.FF7TweaksForScot.gUrlBarColorize, true);
        }
        //end - url bar colorize
        //hide icons in bookmarks toolbar
        var PlacesToolbarItems = window.document.getElementById('PlacesToolbarItems');
        if (PlacesToolbarItems) {
            if (sss.sheetRegistered(bookmarksToolbarCssUri, sss.USER_SHEET)) {
                sss.unregisterSheet(bookmarksToolbarCssUri, sss.USER_SHEET);
            }
            sss.loadAndRegisterSheet(bookmarksToolbarCssUri, sss.USER_SHEET);
        }
        //end - hide icons in bookmarks toolbar
    },
    onUntrack: function (window) {
        //hide the extended label when a page is verified
        var IdentityBox = window.document.getElementById('identity-box');
        if (IdentityBox) {
            if (sss.sheetRegistered(identityBoxCssUri, sss.USER_SHEET)) {
                sss.unregisterSheet(identityBoxCssUri, sss.USER_SHEET);
            }
        }
        //end hide the extended label when a page is verified
        //url bar colorize
        if (window.gBrowser) {
            window.gURLBar.style.backgroundColor = '';
            window.gBrowser.removeEventListener('load', window.FF7TweaksForScot.gUrlBarColorize, true);
            window.gBrowser.removeEventListener('pageshow', window.FF7TweaksForScot.gUrlBarColorize, true);
            window.gBrowser.tabContainer.removeEventListener('TabSelect', window.FF7TweaksForScot.gUrlBarColorize, true);
            delete window.FF7TweaksForScot;
        }
        //end - url bar colorize
        //hide icons in bookmarks toolbar
        var PlacesToolbarItems = window.document.getElementById('PlacesToolbarItems');
        if (PlacesToolbarItems) {
            if (sss.sheetRegistered(bookmarksToolbarCssUri, sss.USER_SHEET)) {
                sss.unregisterSheet(bookmarksToolbarCssUri, sss.USER_SHEET);
            }
        }
        //end - hide icons in bookmarks toolbar
    }
});

【讨论】:

    猜你喜欢
    • 2011-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-24
    • 1970-01-01
    • 2016-06-02
    • 2019-06-20
    相关资源
    最近更新 更多