User:Diberri/Template filler/pubmed.wtf.autolink.user.js

// ==UserScript== // @name       Highlight PubMed IDs for Wikipedia Template Filler // @namespace  http://diberri.dyndns.org/ // @description Links PMIDs found on PubMed pages to the Wikipedia Template Filler to generate a template. // @include    http://www.ncbi.nlm.nih.gov*/sites/entrez* // @include    http://www.ncbi.nlm.nih.gov*/pubmed/* // ==/UserScript==

var pmid_conts = document.evaluate( "//div[@class='PMid'] | //p[@class='pmid'] | //span[@class='rprtid'] | //dd[@class='title']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null );

for( var i = 0; i < pmid_conts.snapshotLength; i++ ) { var cont = pmid_conts.snapshotItem(i);

for( var j = 0; j < cont.childNodes.length; j++ ) { var child = cont.childNodes[j]; var text_str = child.nodeValue;

if( text_str && text_str.match( /PMID\:\s+(\d+)/ ) ) { var pmid = RegExp.lastParen; var wtf_url = "http://toolserver.org/~diberri/cgi-bin/templatefiller/index.cgi?ddb=&type=pubmed_id&id="+pmid+"&add_ref_tag=1&add_text_url=1&full_journal_title=1";

var new_cont = document.createElement( cont.nodeName ); new_cont.innerHTML = "Fill template:  ";

cont.parentNode.appendChild( new_cont ); } } }