erikvold (owner)

Fork Of

gist: 101722 by esquifit Issue Greasemonkey userscri...

Revisions

gist: 141957 Download_button fork
public
Description:
Greasemonkey Ubiquity Command
Public Clone URL: git://gist.github.com/141957.git
Embed All Files: show embed
Userscript_commands.ubiq.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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;
}
});