Question

I've been searching and reading how firefox addons manages preferences, but all the samples I found involves GUI windows and other complex things I don't need.

What I need is, I have a list of some regex patterns, which needs to be updated often without user interaction whenever it's needed.

So I want to have the initial regex stored in the firefox addon like preferences but without any gui to edit them, and then be able to edit those hardcoded preferences.

Can someone show me an example on how to do this?

I don't want a full example, just how should I store these preferences and then edit them programmatically, without involving gui windows like all the .xul files I found does.

Was it helpful?

Solution

Something like this:

Components.utils.import("resource://gre/modules/Services.jsm");

// Reading the preference
var regexp = /foobar/;   // default value
try
{
  regexp = new RegExp(Services.prefs.getCharPref("extensions.myExtension.regexp"));
}
catch (e)
{
  // Errors are expected, the preference might not exist yet
}

// Setting the preference
Services.prefs.setCharPref("extensions.myExtension.regexp", regexp.source);

You will be able to see this preference under about:config. More code examples

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top