Here is a simple Greasemonkey script to get postgenomic links in Nature journals.

Big disclaimer: It's my first greasemonkey script and I don't really know much about JavaScript :)

The trick is going to make the script useful in any science journal. If anyone is good with Xpath and/or finds a much simpler way of doing it feel free to edit the script.

To use copy-paste the script into a file and name the file (something.user.js). Drag the file into a firefox window to install.

Alternatively you can install the script by clicking on this link postgenomic.user.js, Firefox will recognise the file as a Greasemonkey script and prompt you to install it.

Then go to a nature journal and browse around the table of contents. You should find some papers with the logo of Postgenomic below the DOI.



// --------------------------------------------------------------------
//
// ==UserScript==
// @name          Postgenomic
// @namespace     http://www.postgenomic.com/
// @description   example script to look for Postgenomic content
// @include       http://www.nature.com/*
// @include       http://www.sciencemag.org/*
// ==/UserScript==
 
var d = new Date();
var curr_date = d.getDate();
var stored_date=0;
var DOI_list="";
var stored_date= GM_getValue("postgenomics_data_date", 0);
// Check for new DOIs in Postgenomic only once per day
if (stored_date != curr_date)
{
	get_DOI_list();
	GM_setValue("postgenomics_data_date", curr_date);
}
var test_list = GM_getValue("postgenomics_DOI_list",0);
 
 
//I just changed some things from some scripts found in http://diveintogreasemonkey.org/
//It is useful to have a look at Xpath and Document Object Model (DOM) to read the next bit
function gm_xpath(expression,contextNode){
	return document.evaluate(expression,contextNode,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
}
var allTextareas, thisTextarea;
var postgenomic=false;
allTextareas = document.getElementsByTagName('*');
//For every node in the document
for (var i = 0; i < allTextareas.length; i++) {
    thisTextarea = allTextareas[i];
	if (!thisTextarea.firstChild){continue;}
	//For every child of this node check for the presence of a DOI
	for (var k =0;k< thisTextarea.childNodes.length;k++ )
	{
		var reg = /:(?:[ ]*)([0-9\.]+\/[a-z0-9\.\-]+)/i;
		var ar = reg.exec(thisTextarea.childNodes[k].nodeValue);
		var doi_found=RegExp.$1;
		if (ar && doi_found){
			//GM_log(thisTextarea.childNodes[k].nodeValue+" :"+doi_found);
			var reg = new RegExp(doi_found, "i");
			//when a DOI is found, check if it is listed in postgenomic
			if (reg.exec(test_list))
			{
				//if that is the case then create a new document node with a link to postgenomic
				newanchor = document.createElement("a");
				newanchor.setAttribute("title","Comments from Postgenomic");
				newanchor.setAttribute("href","http://postgenomic.com/paper.php?doi="+doi_found);
				img = document.createElement("img");
				img.setAttribute("alt","Comments at Postgenomic");
				img.setAttribute("src","http://postgenomic.com/images/postgenomic_title.png");
				img.setAttribute("border","0");
				newanchor.appendChild(img);
				//insert the created node before the next sibling of the DOI containing node
				thisTextarea.parentNode.insertBefore(newanchor, thisTextarea.nextSibling);
			}
		}
	}
}
 
 
 
 
 
function get_DOI_list(){
	GM_log("GETTING DOI LIST");
	GM_xmlhttpRequest({
		method: 'GET',
		url: "http://www.postgenomic.com/api.php?action=get&type=papers",
		headers: {
			'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
			'Accept': 'application/xml,text/html',
		},
		onload: function(responseDetails) {
			var response_status=responseDetails.status;
			var response_text=null;
			if (response_status==200){
				GM_log("Get Doi List: response ok");
				response_text=responseDetails.responseText;
			}
			var count_doi=0;
			var reg_test = /(10\.[0-9\.]+\/\S+)\s/ig;
			while (reg_test.exec(response_text))
			{
				count_doi++;
				//The DOIs are kept in a simple string
				DOI_list=DOI_list+";"+RegExp.$1;
			}
//			GM_log("LIST:"+DOI_list);
//			GM_log(count_doi);
			GM_setValue("postgenomics_DOI_list", DOI_list);
 
		}
	});
}
 
projects_postgenomic.txt · Last modified: 2007/08/20 13:27 (external edit)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki