GM_unwatchValue

Greg Parris edited this page Jul 18, 2013 · 1 revision

Description

GM_unwatchValue allows a userscript to stop monitoring one or more preferences monitored via GM_watchValue.

Arguments

String aName

The name of the preference to stop watching.

String aUUID

Optional. The unique identifier (UUID) tying a watched preference to a callback.

Returns

Boolean aRemoved

false only if the aUUID argument was provided and a matching watcher (i.e. preference name + UUID) couldn't be found, otherwise true.

Example

GM_setValue("foo", "bar");
 
function myObserver1(aNotice) {
GM_log("#1 observed '" + aNotice.name + "' changed from '"
     + aNotice.oldValue + "' to '" + aNotice.newValue + "'");
}
 
function myObserver2(aNotice) {
GM_log("#2 observed '" + aNotice.name + "' changed from '"
     + aNotice.oldValue + "' to '" + aNotice.newValue + "'");
}
 
var obs1UUID = GM_watchValue("foo", myObserver1);
GM_log("'foo' observer #1 GUID == " + obs1UUID);
 
var obs2UUID = GM_watchValue("foo", myObserver2);
GM_log("'foo' observer #2 GUID == " + obs1UUID);
 
GM_setValue("foo", "baz");
 
if (GM_unwatchValue("foo", obs1UUID))
  GM_log("removed 'foo' observer #1");
else
  GM_log("unable to remove 'foo' observer #1");
 
GM_setValue("foo", "qux");
 
if (GM_unwatchValue("foo"))
  GM_log("removed all 'foo' observers");
else
  GM_log("unable to remove all 'foo' observers");

 
GM_setValue("foo", "bar");