Skip to content

Instantly share code, notes, and snippets.

@masnick masnick/bookmarklet.js
Last active Jul 26, 2017

Embed
What would you like to do?
Universal "find at my library" bookmarklet for journal articles
var url = 'http://something.youruniversity.edu/foo/bar';
var doi;
var suffixes = {
"pmid": "?sid=Entrez:PubMed&id=pmid:",
"doi": "?sid=Entrez:DOI&id=doi:"
};
var re = /^[0-9]{5,15}/;
var found = jQuery(jQuery(".rprtid dd")[0]).text().match(re);
if(found != null) {
location.href = url + suffixes["pmid"] +found[0];
}
else {
// Try to find DOI link
var dois = jQuery.grep(jQuery("a").map(function() {return this.href;}), function(n, i) { return n.indexOf("dx.doi.org") !== -1;});
if(dois && dois.length > 0) {
doi = dois[0].replace(/.*dx.doi.org\//, "");
location.href = url + suffixes["doi"] + doi;
}
else {
// try to find DOI text
// Add spaces between all elements so `text()` will work properly
jQuery( "*" ).each(function( index ) {
jQuery( this ).append(" ");
});
var match = /doi\s*:?\s*(10\.[0-9]+\/[a-z0-9\.]*)/gi.exec(jQuery("body").text());
if(match && match.length > 1) {
doi = match[1];
location.href = url + suffixes["doi"] + doi;
}
else {
alert("Neither PubMed ID nor DOI link found.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.