这是我很久以前在 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
}
});