Extra caution is recommended when installing recently uploaded/updated scripts (read more)
Be sure you trust any scripts you install

Peninsula Library System - Amazon.com & other sources Lookup

Display the availability of a book in the San Francisco Peninsula (CA, USA) Library System on amazon.com, other bookstores and wikipedia book pages

Copyright (c) 2006-2007, Manpreet Singh
Released under the MIT/X11 license

 

TWEAK NOTE:
The script is enabled only on sites by default. This can be changed by Greasemonkey's menu to enable it only for known websites like amazon.com, Barnes And Noble, Wikipedia etc. Doing so is not recommended unless you experience any kind of slowness due to this script.

 

LATEST CHANGES:

Version: 3.7
Added real algorithmic validation for ISBN-10 and ISBN-13
Bumped up zIndex

Version: 3.6
Fixed oversight when partial results weren't return in case of error
Google books works better now

Version: 3.5
Added additional pattern to match on plsinfo.org page

Version: 3.4
Fixed Alternate ISBN lookup for ISBN-13

Version: 3.3
Lookup alternate ISBNs via xISBN web service
Link individual librarys on plsinfo.org book page
Added toggle menu
Added Mending status




Apr 12, 2007
Junk Blocker Script's author

I am just helping myself as a user of the library :)

I like your facility of linking to library location and hours on the library page for the book and was thinking of implementing the same in my version this weekend too.

 
Apr 12, 2007
Al N Scriptwright

Thanks for helping the Peninsula Library system. You may find this GM script interesting...

Google Print - Peninsula Library System Lookup Mashup

http://userscripts.org/scripts/show/8286

 
Mar 30, 2007
Junk Blocker Script's author

The sample code paste below for Gary Bobcat got messed up. The script on this page is fine :)

 
Mar 30, 2007
Junk Blocker Script's author

The code here got messed up while posting. See

http://userscripts.org/forums/1/topics/200?page...

for actual code.

 
Mar 12, 2007
Junk Blocker Script's author

Attempting to paste the code for the initial attempt.

// ==UserScript==
// @name        Timerbland Regional Library Catalog - Amazon.com & other sources Lookup
// @description Display the availability of a book in the Timberland Regional Library Catalog (WA, USA) on amazon.com, other bookstores and wikipedia book pages
// @namespace   http://loonyone.livejournal.com
// @include     *abebooks.com/*
// @include     *alibris.com/*
// @include     *amazon.*/*
// @include     *barnesandnoble.com/*
// @include     *bookfinder.com/*
// @include     *books.google.com/*
// @include     *booksamillion.com/*
// @include     *bookshelved.org/*
// @include     *bookmooch.com/*
// @include     *bordersstores.com/*
// @include     *buy.com/*
// @include     *c2.com/*
// @include     *half.ebay.com/*
// @include     *librarything.com/work/*
// @include     *mitpress.mit.edu/*
// @include     *penguin.*/*
// @include     *penguingroup.*/*
// @include     *penguinbooksindia.*/*
// @include     *penguincatalogue.*/*
// @include     *powells.com/*
// @include     *wikipedia.org/*isbn=*
// @include     *worldcat.org/*
// @include     *worldcatlibraries.org/*
// @creator     Manpreet Singh |junkblocker<at>yahoo</at><dot>com|
// @source      http://userscripts.org/scripts/show/1072
// @identifier  http://userscripts.org/scripts/source/1072.user.js
// @version     0.1
// @date        2007-03-11
// ==/UserScript==

// Initially based on Peninsula Library System lookup script
// Work on most sites. More specifically at least on *abebooks.com/*,
// *alibris.com/*, *amazon.*/*, *barnesandnoble.com/*, *bookfinder.com/*,
// *books.google.com/*, *booksamillion.com/*, *bookmooch.com/*,
// *bordersstores.com/*, *buy.com/*, *c2.com/*, *half.ebay.com/*,
// *librarything.com/work/*, *penguin.*/*, *penguingroup.*/*,
// *penguinbooksindia.*/*, *penguincatalogue.*/*, *powells.com/*,
// *wikipedia.org/*isbn=*, *worldcat.org/* & *worldcatlibraries.org/*
//
// Version 0.1 - First release based on Peninsula Library System - Amazon.com & other sources lookup script


(function() {
  // check for updates every day
  /*
  if ((unsafeWindow || window.wrappedJSObject || window).UserScriptUpdates) {
    var lastChecked = GM_getValue('LAST_UPDATE_CHECKED', null);
    var now = new Date().getTime();
    if (!lastChecked || (now - lastChecked) > 24 * 60 * 60 * 1000) {
      GM_setValue('LAST_UPDATE_CHECKED', now.toString());
      var SCRIPT = {
        name: ' Timerbland Regional Library Catalog - Amazon.com & other sources Lookup',
        namespace: 'http://loonyone.livejournal.com',
        description:  'Display the availability of a book in the Timberland Regional Library Catalog (WA, USA) on amazon.com, other bookstores and wikipedia book pages'
        source: 'http://userscripts.org/scripts/show/1072',
        identifier: 'http://userscripts.org/scripts/source/1072.user.js',
        version: "0.1",               // version
        date: (new Date(2007, 3 - 1, 11))    // update date
            .valueOf()
      };
      try {
        (unsafeWindow || window.wrappedJSObject || window).UserScriptUpdates.requestAutomaticUpdates(SCRIPT);
      } catch (ex) {}
    }
  }
  */
  Array.prototype.addUnique = function (elem) {
    for (var i = 0, len = this.length; i < len; i++) {
      if (this[i] == elem) {
        return;
      }
    }
    this.push(elem);
  }
  /*
  window.alert = function (msg) {
    if (! window.confirm(msg)) {
      throw 'aborted';
    }
  }*/
  function findGenericISBN(themap) {
    var bodyhtml = document.body.innerHTML;
    while (bodyhtml.match(/ISBN(?:-1[03])?\s*[ =:]\s*(?:<\/?[a-zA-Z0-9]+\s*\/?>)?([\n\r\s\dX-]+)((.*[\n\r]*)*)/i)) {
      var maybeMultiple = RegExp.$1;
      bodyhtml = RegExp.$2;
      while (maybeMultiple.match(/\b((?:\d{3}-?)?(?:\d{9}[\dX]|[\d-]{8,}[\dx]))([\s\n\r\dX-]*)/i)) {
        themap[RegExp.$1]='';
        maybeMultiple = RegExp.$2;
      }
    }
    try {
      themap[location.href.match(/isbn[=\/]((\d{3}-?)?\d{9}[\dX])/i)[1]] = '';
    } catch (e){}
  }
  function getISBN() {
    var results = {};
    try {
      if (location.href.match(/^https?:\/\/(www\.)?librarything\.com/)) {
        var isbns = document.evaluate("//div[@class='isbn']/a", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
        for (var i = 0, len = isbns.snapshotLength; i < len; i++) {
          var a = isbns.snapshotItem(i);
          if (a.innerHTML.match(/ISBN\s+((\d{3}-?)?\d{9}[\dX])/i)) {
            results[RegExp.$1] = '';
          }
        }
      } else if (location.href.match(/^https?:\/\/(www\.)?amazon\./)) {
        try {
          results[location.href.match(/(asin|product|dp)[\/=]((\d{3}-?)?\d{9}[\dX])(\/|&|;|\?|$)/i)[2]] = '';
        } catch (e) {}
        var thiscontent = document.body.innerHTML;
        var idx = thiscontent.indexOf('ISBN-10:');
        if (idx != -1 && thiscontent.substring(idx+12).match(/^[\n\r\s]*((\d{3}-?)?\d{9}[\dX])/i)) {
          results[RegExp.$1] = '';
        }
        var idx = thiscontent.indexOf('ISBN-13:');
        if (idx != -1 && thiscontent.substring(idx+12).match(/^[\n\r\s]*((\d{3}-?)?\d{9}[\dX])/i)) {
          results[RegExp.$1] = '';
        }
      } else if (location.href.match('abebooks.com')) {
        try {
          results[document.title.match(/ISBN ((\d{3}-?)?\d{9}[\dX])/i)[1]] = '';
        } catch (e) {};
        try {
          results[document.body.innerHTML.match(/class="isbn">((\d{3}-?)?\d{9}[\dX])/i)[1]] = '';
        } catch (e) {};
      } else if (location.href.match('buy.com')) {
        results[document.title.match(/ISBN ((\d{3}-?)?\d{9}[\dX])/i)[1]] = '';
      } else if (location.href.match('powells.com')) {
        findGenericISBN(results);
        var dts = document.getElementsByTagName('dt');
        for (var i=0; i<dts><bs> ISBN  ' + isbn;
      for (var i = 0, len = avails.length; i < len; i++) {
        var hrefTitle = avails[i][0];
        var theColor = avails[i][1];
        var thislink = document.createElement('a');
        with (thislink) {
          href = libraryUrlPattern + isbn + libraryUrlPatternSuffix;
          alt = hrefTitle;
          title = hrefTitle;
          textContent = hrefTitle;
        }
        with (thislink.style) {
          display = 'block';
          border = 'outset thin black';
          padding = '2px';
          textAlign = 'center';
          color = 'white';
          fontWeight = 'bold';
          background = theColor;
          textDecoration = 'none';
          fontFamily = 'arial,sans';
          margin = '0px 0px 3px';
        }
        thespan.appendChild(thislink);
      }
      divStyled.appendChild(thespan);
      if (!maindiv) {
        maindiv = document.createElement('div');
        maindiv.id = 'trlcdiv';
        with (maindiv.style) {
          left = '200px';
          top = '6px';
          zIndex = '999';
          border = '1px solid #000033';
          color = 'black';
          padding = '0px';
          position = 'absolute';
          opacity = '0.95';
          textAlign = 'left';
        }

        var title = document.createElement('div');
        with (title.style) {
          background = 'rgb(153,204,255)';
          border = 'solid';
          borderWidth = '0px 0px 1px';
          cursor = 'move';
          fontFamily = 'dialog,arial,sans';
          fontSize = '12px';
          fontWeight = 'bold';
          padding = '3px 0px 2px 15px';
          textAlign = 'right';
        }
        title.appendChild(document.createTextNode(' ' + libraryName + ' '));
        var closeButton = document.createElement('a');
        closeButton.href = 'javascript: closeTRLC();';
        closeButton.innerHTML = 'X';
        with (closeButton.style) {
          display = 'inline';
          padding = '2px 6px 1px';
          color = 'white';
          cursor = 'pointer';
          textDecoration = 'none';
          border = 'solid 1px white';
          background = '#069';
        }
        title.appendChild(closeButton);

        maindiv.appendChild(title);
        body.appendChild(maindiv);
        title.drag = new Drag(title, maindiv);
      }
      maindiv.appendChild(divStyled);
    },

    doLookup : function (isbns) {
      var makeCallback = function(isobune) {
        return function(results) {
          page = results.responseText;
          var availTypes = [];
          if (notFound.test(page)) {
            var due = page.match(notFound)[1];
            availTypes.addUnique(["Not available." , "#f66"]);
          } else {
            if (libraryAvailability.test(page)) {
              availTypes.addUnique(["On the shelf now!" , "#00cc66"]);
            }
            if (libraryCheckedOut.test(page)) {
              availTypes.addUnique(["Checked out" , "orange"]);
            }
            if (libraryTransit.test(page)) {
              availTypes.addUnique(["Transit Request" , "orange"]);
            }
          }
          if (!availTypes.length) {
            while (page.match(/(?:white|FCFDC|ormation)">(.+)<\/a>((.*[\n\r]*)*)/i)) {
              var extraType = RegExp.$1;
              page = RegExp.$2;
              extraType = extraType.replace(/<!--.*-->/g,'');
              extraType = extraType.replace(/.nbsp;/g, ' ');
              extraType = extraType.replace(/^\s+/, '');
              extraType = extraType.replace(/\s+$/, '');
              availTypes.addUnique([extraType, "orange"]);
            }
          }
          if (!availTypes.length) {
            availTypes.addUnique(["Error: Click for library page. You can check by searching manually." , "red"]);
          }
          libraryLookup.insertLinks (isobune, availTypes);
        };
      };
      for (var isbn in isbns) {
        GM_log(libraryUrlPattern + isbn + libraryUrlPatternSuffix);
        GM_xmlhttpRequest ({method : 'GET', url : libraryUrlPattern + isbn + libraryUrlPatternSuffix, onload : makeCallback(isbn)});
      }
    }
  }

  try {
    libraryLookup.doLookup(thisisbn);
    var head = document.getElementsByTagName('head');
    if (head && head[0]) {
      var s = document.createElement('script');
      s.language='javascript';
      s.type = 'text/javascript';
      s.text = 'function closeTRLC(){try{document.getElementById("trlcdiv").style.display="none"}catch(e){}}';
      head[0].appendChild(s);
    }
  } catch (e) {
    return;
  }
}
)();
</dot>

 
Mar 12, 2007
Junk Blocker Script's author

Thank you.

I was able to modify the script to do some minimal checking but a full fledged new library takes a lot of work to create and more importantly to maintain. You should try asking for this on the forums and I'll be glad to send my initial attempt.

 
Mar 12, 2007
Gary Bobcat User

Very nice script, particularly in the number of sites covered. I don't know how to make scripts yet or else I would try to do this myself. Would you be able to modify yours for Timberland Regional Library in Western WA? http://www.timberland.lib.wa.us/

Thank you for your consideration. I would notify TRL of its existence if you do.

You could comment on this script if you were logged in.