-
-
Save erikvold/141957 to your computer and use it in GitHub Desktop.
Greasemonkey Ubiquity Command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var noun_type_gmCommand = { | |
_name: "GM command name", | |
// Returns all GM commands available for the current page. | |
getCommands: function(){ | |
var commands= new Array(); | |
var menuitems = jQuery(context.chromeWindow.document).find('#userscript-commands-sb > menupopup > menuitem').get(); | |
for (var i=0; i<menuitems.length; i++){ | |
var cmd = menuitems[i]; | |
commands[cmd.getAttribute('label')] = cmd; | |
} | |
return commands; | |
}, | |
suggest: function( text, html ) { | |
var suggestions = []; | |
var commands = this.getCommands(); | |
for ( var cmd in commands ) { | |
if ( cmd.match( text, "i" ) ){ | |
suggestions.push( CmdUtils.makeSugg( cmd, cmd, commands[cmd] ) ); | |
} | |
} | |
// Return the list of input objects | |
return suggestions; | |
} | |
}; | |
CmdUtils.CreateCommand({ | |
names: [ "gm", "greasemonkey" ], | |
arguments: [ | |
{ role: 'object', nountype: noun_type_gmCommand, label: "GM command" }, | |
{ role: 'instrument', nountype: noun_arb_text, label: "input" } | |
], | |
author: { name: "Erik Vold", email: "erikvvold@gmail.com"}, | |
contributors: [ "Erik Vold", "esquifit" ], | |
homepage: "http://erikvold.com/tools/ubiquity/greasemonkey/gm.cfm", | |
description: "Issue Greasemonkey userscript commands from the Ubiquity command line", | |
icon: "chrome://greasemonkey/content/icon_small.png", | |
version: "1.0", | |
execute: function( args ) { | |
var inputString = args.instrument.text; | |
// save input sring to the window scope | |
CmdUtils.getWindowInsecure().ubiquityGMInput = inputString; | |
if ( inputString != "" && args.object.data._commandFuncWithString ) { | |
args.object.data._commandFuncWithString(inputString); | |
} | |
else{ | |
args.object.data._commandFunc(inputString); | |
} | |
return; | |
}, | |
preview: function( pblock, args ) { | |
var commands = noun_type_gmCommand.getCommands(); | |
var inputString = args.instrument.text; | |
pblock.innerHTML = | |
<div> | |
<h4><i>Commands available in this page:</i></h4> | |
<hr/> | |
<ul/> | |
</div>.toXMLString(); | |
var ul = jQuery(pblock).find('ul'); | |
for (c in commands){ | |
var cb = ( function (cmd){ | |
return function(){ | |
context.chromeWindow.gUbiquity.closeWindow(); | |
commands[cmd]._commandFunc(); | |
} | |
})(c); | |
ul.append(jQuery('<li/>').append(jQuery("<a/>").text(c).click(cb))); | |
} | |
return; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment