Skip to content

Instantly share code, notes, and snippets.

@nollinvoyd
Created January 24, 2025 18:12
Show Gist options
  • Save nollinvoyd/1022310756a2b5f3e8095b9561dd3c17 to your computer and use it in GitHub Desktop.
Save nollinvoyd/1022310756a2b5f3e8095b9561dd3c17 to your computer and use it in GitHub Desktop.
Firefox custom toolbar button
// 'about:'-Button script for Firefox 89+ by Aris
//
// Need a different 'about' page button?
// - replace 'about:config' url with a different 'about:' url
// - replace button id
// - replace icon / icon url / icon color
(function() {
try {
Components.utils.import("resource:///modules/CustomizableUI.jsm");
ChromeUtils.importESModule("resource:///modules/CustomizableUI.sys.mjs");
var sss = Components.classes["@mozilla.org/content/style-sheet-service;1"].getService(Components.interfaces.nsIStyleSheetService);
var button_label = "About Button";
CustomizableUI.createWidget({
id: "aboutaddons", // button id
defaultArea: CustomizableUI.AREA_NAVBAR,
removable: true,
label: button_label, // button title
tooltiptext: button_label, // tooltip title
onClick: function(event) {
var win = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator)
.getMostRecentWindow("navigator:browser");
if(event.button=='0') {
try {
openAboutDialog();
} catch (e) {}
}
if(event.button=='2') {
try {
win.gBrowser.selectedTab = win.gBrowser.addTrustedTab('aboutaddons');
setTimeout(function(){
document.querySelector("#toolbar-context-menu").hidePopup();
},0);
} catch (e) {}
}
},
onCreated: function(button) {
return button;
}
});
// style button icon
var uri = Services.io.newURI("data:text/css;charset=utf-8," + encodeURIComponent('\
\
#about-button .toolbarbutton-icon {\
list-style-image: url("chrome://mozapps/skin/extensions/extension.svg)',
fill: dimgray; /* icon color name/code */\
}\
\
'), null, null);
sss.loadAndRegisterSheet(uri, sss.AGENT_SHEET);
} catch (e) {
Components.utils.reportError(e);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment