// ==UserScript==


// @name          CSU Amazon Linky

// @namespace     http://www.library.southernct.edu/firefox/
// @description	  This script inserts a link under the book title to the CONSULS libraries catalog (http://www.consuls.org/).
// @description   Based on Amazon Linky (http://userscripts.org/scripts/show/1058) and the OCLC xISBN project (http://www.oclc.org/research/researchworks/xisbn/default.htm)
// @include       http://*.amazon.*

// @date          2005-12-29

// @version       0.2

// @GM_version    0.6.4



/* BEGIN LICENSE BLOCK
 Copyright (C) 2005 Chenxin Li

 This program is free software; you can redistribute it and/or 
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 

This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 

You can download a copy of the GNU General Public License at
http://diveintomark.org/projects/greasemonkey/COPYING
 or get a free printed copy by writing to the Free Software Foundation, 
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 END LICENSE BLOCK */



// ==/UserScript==



(

function() {
  
  mainmatch = window.location.href.match(/\/(\d{9}[\d|X])\//);

  if (mainmatch){

  	var isbn = mainmatch[1];

  	var header = document.evaluate("//b[@class='sans']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

  	if (header) {

      	  

	  var consuls_link = document.createElement('a');
   	  consuls_link.setAttribute('href', 'http://labs.oclc.org/xisbn/liblook?baseURL=http://www.consuls.org&opacID=innovative&isbn=' + isbn);
   	  consuls_link.setAttribute('title', 'Lookup this book in CONSULS');
   	  consuls_link.innerHTML 
	   	= '<img src="http://www.consuls.org/screens/csulogo_sm.jpg"'
      	+ ' style="border: 0; margin: 0px 0 0 2px; padding: 0; vertical-align: middle"'
      	+ ' alt="CONSULS icon" />';
      
            

      header.parentNode.insertBefore(consuls_link, header.nextSibling);

      
    }

  }
 
}

)();

