Created
April 22, 2009 06:28
-
-
Save kirel/99623 to your computer and use it in GitHub Desktop.
ubiquity commands
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
// first beta command | |
CmdUtils.CreateCommand({ | |
name: "pbwiki", | |
//icon: "http://example.com/example.png", | |
//homepage: "http://example.com/", | |
author: { name: "Daniel Kirsch", email: "[email protected]"}, | |
license: "GPL", | |
description: "Searches in your pbwiki", | |
help: "Help! Dunno!", | |
takes: {"term": noun_arb_text}, | |
modifiers: {"in": noun_arb_text}, | |
defaultwiki: "bewatec", // ************************* Ersetze hier default wiki | |
preview: function( pblock, term, mods ) { | |
pblock.innerHTML = 'Searching...'; | |
var wiki = mods["in"].text || this.defaultwiki; | |
jQuery.get("https://"+wiki+".pbwiki.com/api_v2/op/Search/_type/jsontext/q/"+term.text, | |
function(data){ | |
//pblock.innerHTML = data; | |
var json = data.split("\n").slice(1,-2).join(""); | |
var res = eval('(' + json + ')'); | |
var results = jQuery.grep(res["results"], function(r){ | |
return ((r.type == "page") || (r.type == "file")); | |
}); // filter out only pages as results | |
results.sort(function(a,b) { a.score - b.score }); | |
var t = 'Got ${results.length} results'; | |
t += '<ul style="margin:0;padding:0;list-style:none;">{for r in results}<li style="margin:0;"><h3 style="margin-bottom:2px;"><a href="http://${wiki}.pbwiki.com/${r.url}" style="color:#C3FF68;">${r.title}</a></h3>${r.snippet}<div><small style="color:gray;">Score: ${r.score}</div></small></li>{/for}</ul>' | |
pblock.innerHTML = CmdUtils.renderTemplate(t, {"results": results, "wiki": wiki}); | |
}); | |
}, | |
execute: function(term, mods) { | |
var wiki = mods["in"].text || this.defaultwiki; | |
Utils.openUrlInBrowser("https://"+wiki+".pbwiki.com/FindPage?SearchFor="+term.text); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment