Skip to content

Instantly share code, notes, and snippets.

@supahgreg
Created March 12, 2011 18:24
Show Gist options
  • Save supahgreg/867450 to your computer and use it in GitHub Desktop.
Save supahgreg/867450 to your computer and use it in GitHub Desktop.
testing GM_(register|unregister|enable|disable)MenuCommand
// ==UserScript==
// @id [email protected]
// @name Scriptish menu command test!
// @author Greg Parris
// @namespace http://phob.net
// @description testing GM_(register|unregister|enable|disable)MenuCommand
// @include http://phob.net/
// ==/UserScript==
var body = document.getElementsByTagName("body")[0];
var uuid, btn, btn2, btn3, btn4;
btn = document.createElement("input");
btn.type = "button";
btn.value = "Add command";
btn.addEventListener("click", function() {
uuid = GM_registerMenuCommand("My fancy menu command", function() {
alert("'My fancy menu command' was called!");
});
alert("created command with uuid '" + uuid + "'");
}, false);
btn2 = document.createElement("input");
btn2.type = "button";
btn2.value = "Remove command";
btn2.addEventListener("click", function() {
if (uuid) {
alert("removed something? " + GM_unregisterMenuCommand(uuid));
alert("removed command with uuid '" + uuid + "'");
uuid = null;
} else {
alert("command wasn't found");
}
}, false);
btn3 = document.createElement("input");
btn3.type = "button";
btn3.value = "Disable command";
btn3.addEventListener("click", function() {
if (uuid) {
alert("disabled something? " + GM_disableMenuCommand(uuid));
alert("disabled command with uuid '" + uuid + "'");
} else {
alert("command wasn't found");
}
}, false);
btn4 = document.createElement("input");
btn4.type = "button";
btn4.value = "Enable command";
btn4.addEventListener("click", function() {
if (uuid) {
alert("enabled something? " + GM_enableMenuCommand(uuid));
alert("enabled command with uuid '" + uuid + "'");
} else {
alert("command wasn't found");
}
}, false);
body.appendChild(btn);
body.appendChild(btn2);
body.appendChild(btn3);
body.appendChild(btn4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment