Skip to content

Instantly share code, notes, and snippets.

@mildmojo
Created March 15, 2012 15:45
Show Gist options
  • Save mildmojo/2044883 to your computer and use it in GitHub Desktop.
Save mildmojo/2044883 to your computer and use it in GitHub Desktop.
Add Firefox buttons to manipulate about:config settings
/*
I needed a button in the Firefox UI to toggle the default page zoom level
setting offered by the NoSquint extension (shown as "extensions.nosquint.fullZoomLevel"
in about:config). Since this isn't likely to be provided directly and I
wasn't interested in writing my own extension for something so simple, I
looked for an extension that would expose about:config settings to buttons.
Instead, I found the Custom Buttons extension:
https://addons.mozilla.org/en-US/firefox/addon/custom-buttons/
Custom Buttons lets you put some javascript behind a button that can be
placed on your toolbars. The code operates as a XUL overlay, so you have
access to Firefox's internal APIs. Here's the code I used:
*/
var prefManager = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
// Available methods: getIntPref, getBoolPref, getCharPref
var currentZoom = prefManager.getIntPref( "extensions.nosquint.fullZoomLevel" );
if ( currentZoom < 150 ) {
currentZoom = 150;
} else {
currentZoom = 100;
}
// Available methods: setIntPref, setBoolPref, setCharPref available
prefManager.setIntPref( "extensions.nosquint.fullZoomLevel", currentZoom );
@jantman
Copy link

jantman commented Oct 13, 2014

Thanks so much for this. I spent about 30 minutes trying to figure out how to change prefs from JS to do this exact same thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment