Skip to content

Instantly share code, notes, and snippets.

@source-data
Created November 3, 2008 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save source-data/21865 to your computer and use it in GitHub Desktop.
Save source-data/21865 to your computer and use it in GitHub Desktop.
Ubiquity command open-doi
CmdUtils.CreateCommand({
//to install this command, visit http://gist.github.com/21865
//code is part of http://code.google.com/p/tl-ubiquity-commands/
name: "open-doi",
takes: {"selected text": noun_arb_text},
preview: function(pblock, directObject){
if (directObject.text){
var m = directObject.text.match(/(doi:)?.*?\b(10\.\d{4}\/\S+)/i);
if (!m){pblock.innerHTML="The selection <pre>"+directObject.text+"</pre> does not include a recognized doi !";}
else {pblock.innerHTML="press Return to go to the document associated with <i>"+m[2]+"</i>.";}
} else {pblock.innerHTML="Select or type a text that includes a doi..."}
},
execute: function(directObject){
if (directObject.text){
var m = directObject.text.match(/(doi:)?.*?\b(10\.\d{4}\/\S+)/i);
if (m){Utils.openUrlInBrowser("http://dx.doi.org/"+m[2])}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment