Peninsula Library System - Amazon.com & other sources Lookup
— Last update Aug 1, 2007 — Installed 6,678 times.Archived Comments (locked)
|
|
The following is an archive of comments made before threaded discussions was implemented (November 16th, 2008) |
|
|
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. |
|
|
Thanks for helping the Peninsula Library system. You may find this GM script interesting... Google Print - Peninsula Library System Lookup Mashup |
|
|
The sample code paste below for Gary Bobcat got messed up. The script on this page is fine :) |
|
|
The code here got messed up while posting. See http://userscripts.org/forums/1/topics/200?page... for actual code. |
|
|
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>
|
|
|
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. |
|
|
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. |
