/*Adding Postgenomic comments to Connotea Based very heavily on Pedro's script at http://wiki.nodalpoint.org/projects_postgenomicThere's almost certainly a much better way to do this using the Postgenomic API, JSON and a callback function:http://www.postgenomic.com/api.php?type=paper&format=json&ids_only=1However, as a proof of concept this'll do!*/// ==UserScript==// @name			Connotea / Postgenomic mashup// @namespace		http://www.postgenomic.com/userscripts// @description		Papers that are in the Postgenomic index get a wee link next to them in Connotea.// @include			http://www.connotea.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);GM_log("Starting Postgenomic / Connotea mashup : DOI list is " + test_list.length + " chars long.");var allLinks, thisLink;allLinks = document.evaluate(	"//a[@class='dblink']",    document,    null,    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,    null);for (var i = 0; i < allLinks.snapshotLength; i++) {    thisLink = allLinks.snapshotItem(i);    // do something with thisLink	GM_log("Found a DB link " + thisLink.textContent);		// strip out the "DOI:" or "PMID:" bits of the text	var reg = /(?:.*?):(?:\s*)(.+)/i;	var ar = reg.exec(thisLink.textContent);	var doi_found = RegExp.$1;		if (ar && doi_found) {		var reg = new RegExp(doi_found, "i");		if (reg.exec(test_list)) {				newanchor = document.createElement("a");			newanchor.setAttribute("title","Comments from Postgenomic");			newanchor.setAttribute("href","http://postgenomic.com/paper.php?doi=" + doi_found);			//var linkText = document.createTextNode("pg");			//newanchor.appendChild(linkText);			img = document.createElement("img");			img.setAttribute("alt","Comments at Postgenomic");			img.setAttribute("src","http://www.postgenomic.com/images/comments.png");			img.setAttribute("border","0");			newanchor.appendChild(img);				thisLink.parentNode.insertBefore(newanchor, thisLink.nextSibling);		}	}}function get_DOI_list(){	GM_log("GETTING DOI LIST");	GM_xmlhttpRequest({		method: 'GET',		url: "http://www.postgenomic.com/api.php?type=paper&ids_only=1&format=text",		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); 		}	});}