Skip to content

Instantly share code, notes, and snippets.

@supahgreg
Created September 5, 2011 01:02
Show Gist options
  • Select an option

  • Save supahgreg/1193818 to your computer and use it in GitHub Desktop.

Select an option

Save supahgreg/1193818 to your computer and use it in GitHub Desktop.
Testing GM_watchValue and GM_unwatchValue
// ==UserScript==
// @id [email protected]
// @name GM_watchValue test
// @version 1.0
// @namespace phob.net
// @author wn
// @description Testing GM_watchValue and GM_unwatchValue
// @include http://phob.net/
// @run-at document-end
// ==/UserScript==
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");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment