3
Sep

Update 9-7-2010, you can also get the firefox extension from here or a zipped version from here.

If you know and use Greasemonkey for Firefox, then just install the user script for pubmeder.appspot.com from http://userscripts.org/scripts/show/85346. In this way, you can modify the domains where you want this script to run. I attach a copy of the script at the end of this post - just some javascript.

Otherwise, install this Firefox Add-on from https://addons.mozilla.org/en-US/firefox/addon/223405/. It is compiled from the user script using an xpi compiler. A local version is here (remember to change the extension from zip to xpi before you drag it into firefox).

Nothing fancy here. Just works.

It records your browsing history and send doi/pmcid/pmid info to the server for future retrieving. Please do visit http://pubmeder.appspot.com/registration first to enable the script sending these info into your account). By default, all the records go to anonymous account, unless you visit the registration page first first!

Enjoy! xoxo

// pubmeder at appspot.com - user script
// version 0.31
// 2010-09-03
// Copyright (c) 2010, Liang Cai
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.  To install it, you need
// Greasemonkey from http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "pubmeder at appspot.com", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @ name          pubmeder at appspot.com
// @ namespace     http://pubmeder.appspot.com/
// @ description   send found pmc/doi/pmid on every page to the server
// @ include       *
// ==/UserScript==

// please visit http://pubmeder.appspot.com/registration to get the apikey for your email

if (!GM_xmlhttpRequest) {
    alert('Please upgrade to the latest version of Greasemonkey.');
    return;
}

if ( document.URL == "http://pubmeder.appspot.com/registration" ) {
  var email = document.getElementById('currentUser').innerHTML;
  var apikey = document.getElementById('apikey_pubmeder').innerHTML;
  GM_setValue("pubmeder_apikey",apikey);
  GM_setValue("pubmeder_email",email);
}

var apikey = GM_getValue("pubmeder_apikey");
var email = GM_getValue("pubmeder_email");
var tail = '';
if ((apikey !== undefined) && (email !== undefined)) {
  tail = '&apikey='+apikey+'&email='+email;
}

var currentList = GM_getValue("pubmeder_pmidList");
if (currentList === undefined) {
  currentList = "";
}

window.sendRequest = function(c) {
  currentList += ',' + c;
  d = currentList.split(",");
  new_d = [];
  g:for (var i = 0; i < d.length; i++) {
      if (d[i] === "")
        { continue g; }
      for (var j = 0; j < new_d.length; j++) {
        if (new_d[j] == d[i])
          { continue g; }
      }
      new_d[new_d.length] = d[i];
    }
  currentList = new_d.join(",");
  // alert(currentList);
  if (new_d.length > 9) {
    var urlurl = 'http://pubmeder.appspot.com/input?pmid=' + currentList + tail;
    GM_xmlhttpRequest({
      method: "GET",
      url: urlurl,
      onload: function(response) {
        if (response.responseText) {
          // alert(response.responseText);
          var logo = document.createElement("div");
          logo.innerHTML = '<div style="margin:0;padding:0;height:4px;background:#fdd;">&nbsp;</div>';
          document.body.insertBefore(logo, document.body.firstChild);
          GM_setValue("pubmeder_pmidList","");
        }
      }
    });
  } else {
    var logo = document.createElement("div");
    logo.innerHTML = '<div style="margin:0;padding:0;height:4px;background:#ddf;">&nbsp;</div>';
    document.body.insertBefore(logo, document.body.firstChild);
    GM_setValue("pubmeder_pmidList",currentList);
  }
};

window.esearchsend = function(b) {
  var url = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&tool=pubmeder&email=i@cail.cn&term=' + b;
  GM_xmlhttpRequest({
    method: "GET",
    url: url,
    onload: function(xml) {
      var parser = new DOMParser();
      var dom = parser.parseFromString(xml.responseText,"application/xml");
      var xid = dom.getElementsByTagName("Id");
      if (!xid[1]) {
        sendRequest(xid[0].firstChild.nodeValue);
      }
    }
  });
};

var a = document.body.innerText;
if (a === undefined) {
  a = document.body.innerHTML;
  var regExp = /<[^>]+>/gi;
  a = a.replace(regExp,"");
}

var regpmid = /pmid\s*:?\s*(\d+)\s*/i;
var regdoi = /doi\s*:?\s*/i;
var doipattern = /(\d{2}\.\d{4}\/[\w./]+\w)\s*\W?/;
var regpmc = /pmcid\s*:?\s*(PMC\d+)\s*/i;
var ID = "";

if (regpmid.test(a)) {
  ID = regpmid.exec(a);
  sendRequest(ID[1]);
} else if (regdoi.test(a) || doipattern.test(a)) {
  ID = doipattern.exec(a);
  if (ID !== null) {
    esearchsend(ID[1]);
  }
} else if (regpmc.test(a)) {
  ID = regpmc.exec(a);
  esearchsend(ID[1]);
} else {
  // no pattern matched
}

Leave a Reply