User:Diberri/Template filler/pubmed.wtf.autolink.user.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Diberri/Template filler/pubmed.wtf.autolink.user. |
// ==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 {{cite journal}} 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 = "<span class=\"wtflink\" style=\"font-size:10pt\">Fill template: <a style=\"font-weight:bold\" href=\""+wtf_url+"\">{{cite journal}}</a></span>";
cont.parentNode.appendChild( new_cont );
}
}
}