Created
March 28, 2009 18:28
-
-
Save satyr/87168 to your computer and use it in GitHub Desktop.
link-to-wikipedia++
This file contains hidden or 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
CmdUtils.CreateCommand({ | |
name: "link-to-wikipedia", | |
takes: {phrase: noun_arb_text}, | |
modifiers: {in: noun_type_language}, | |
icon: "http://www.wikipedia.org/favicon.ico", | |
description: "Turns a phrase into a link to the matching Wikipedia article.", | |
execute: function(dob, mod) { | |
if(!dob.text) return; | |
var link = this._link(dob, mod); | |
CmdUtils.setSelection(link, {text: link}); | |
}, | |
preview: function(pbl, dob, mod) { | |
pbl.innerHTML = this.description + "<p>"+ this._link(dob, mod) +"</p>"; | |
}, | |
_link: function({text, html}, {in: {data}})( | |
'<a href="http://'+ (data || "en") + | |
".wikipedia.org/wiki/Special%3ASearch/"+ | |
encodeURIComponent(text.replace(/ /g, "_")) +'">'+ html +"</a>") | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment