Skip to content

Instantly share code, notes, and snippets.

@cmcbride
Created August 10, 2011 23:05
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 cmcbride/1138523 to your computer and use it in GitHub Desktop.
Save cmcbride/1138523 to your computer and use it in GitHub Desktop.
// this is a simple bookmarklet to make using NASA ADS simple at CfA
// (assuming one has a CfA PIN to log into the proxy)
//
// to make it a bookmarklet, run it through:
// John Gruber's Bookmarklet-Builder
// http://daringfireball.net/2007/03/javascript_bookmarklet_builder
// OR
// http://subsimple.com/bookmarklets/jsbuilder.htm
var public_url = "adsabs.harvard.edu";
var proxy_url = "adsabs.harvard.edu.ezp-prod1.hul.harvard.edu";
// these shouldn't really use a string literal here, but just since
// above only really use '.' it should work
var re_pub = new RegExp(public_url) ;
var re_proxy = new RegExp(proxy_url);
var url = location.href;
if(url.match(re_proxy)!=null){
url=url.replace(re_proxy,public_url);
location.href=url;
}
else if(url.match(re_pub)){
url=url.replace(re_pub,proxy_url);
location.href=url;
}
else{
alert("Current URL is not NASA ADS!\nDoes not match:\n" + location.protocol + "//" + public_url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment