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
javascript:var%20metas=document.getElementsByTagName('meta');var%20a='';for(i=0;i<metas.length;i++){if(metas[i].getAttribute('name')=='citation_doi'){a=metas[i].getAttribute('content')}}if(a){location.href='http://shortdoi.org/'+a}else{a=document.documentElement.innerHTML.match(/doi%20*[:=]%20*10[-/0-9a-z.]\/[-/0-9a-z.]+/mig)||document.documentElement.innerHTML.match(/dx.doi.org\/10[-/0-9a-z.]+/mig);if(a==null){alert('Could%20not%20find%20DOI!')}else{a=a.map(function(x){return%20x.match('10.*')[0]});var%20d=a[0];if(a.length>1){var%20c=new%20Array();for(i%20in%20a){if(c[a[i]]){c[a[i]]++}else{c[a[i]]=1}}var%20m=0;d=null;for(i%20in%20c){if(c[i]>m){m=c[i];d=i}else%20if(c[i]==m){d=null}}}if(d==null){alert('More%20than%20one%20DOI%20found!')}else{location.href='http://shortdoi.org/'+d}}} |
A shortDOI URL is probably more persistent than, say, bit.ly, as it's backed by the organization that maintains the DOI infrastructure. However, if doi.org would go down, you could always use a search engine if you have the original DOI, but the shortDOI URL will be worthless.
Update 24.02.2011: Use some majority voting to find the right DOI.
Update 01.03.2011: Expand the list of allowed characters. Does anybody know which characters can be part of the DOI?
Update 29.07.2015: Be strict about having a prefix and suffix. First check for the "citation_doi" meta tag before looking in the rest of the document.
6 comments:
Hi Michael, nice idea and it works well.
It seems to struggle on some nature pages though, claiming there is more than one DOI on the page...
e.g.
http://www.nature.com/nature/journal/v470/n7335/full/nature09704.html
Hi Duncan,
the reason was the Nature page is full of the references' DOIs. I've changed the bookmarklet to use majority voting, i.e. it'll take the most common DOI (which is hopefully the correct one).
Worked for a couple of examples I tried,
but failed for the following examples:
http://onlinelibrary.wiley.com/doi/10.1002/ceat.201400796/abstract
http://link.springer.com/article/10.1134/S0018151X15020030
Hi Matthis,
thanks for checking it out! I fixed the bookmarklet. As it turns out, many journal articles have a dedicated tag nowadays, which makes extraction of the DOI even easier. It now works for both your examples.
Hi,
thanks for the update! I can confirm that the code from the gist does now work. If you also update the link in the blog post, installing the bookmarklet will be as easy as before (just dragging it to the bookmark bar).
Cheers,
Matthis
Ah, thanks for the reminder!
Post a Comment