Design Challenge Tutorial: Stupid XPI Tricks - Bookmarks and Prefs
Download
Install
- Download and unpack. Move the bookmarks-and-prefs folder to Projects.
- Mac and Linux: Make a file at ~/Profiles/stupid-tricks/extensions/bookmarks-and-prefs@evilbrainjono
The contents of the file should be:
~/Projects/bookmarks-and-prefs/
- Windows: Make a file at %USERPROFILE%\Profiles\stupid-tricks\extensions\bookmarks-and-prefs@evilbrainjono
The contents of the file should be:
%USERPROFILE%\Projects\bookmarks-and-prefs\
What's it do?
- Creates several bookmarks.
- Sets several preferences.
How does it work?
- See file bookmarks-and-prefs/chrome/content/setup.js
- Components.classes and Components.interfaces -- always defined in extension javascript context.
- Let your extension request a Firefox component and get an interface to it.
- There are MANY components you can use; this extension demonstrates using two: Nav-Bookmarks-Service and Preferences-Service.
- Other very useful components, not shown here, include those for reading/writing files on disk, manipulating the browsing history, etc.
- If you want to get really fancy, your extension can even create a component and register it, so that it will be available to other code.
Let's improve it
- Use about:config to find a preference.
- Use the Preferences service to print out the value of that preference.
- Use prefs.getCharPref( nameOfPref ); if it's a string.
- Try setting the value with prefs.setCharPref( nameOfPref, newValue );
Where to Learn More