// ==UserScript==
// @name Amazon Library Search for Greasemonkey
// @namespace
// @description Library Lookup from Amazon book listings.
// @include http://*.amazon.co.jp*
// ==/UserScript==
libsearch(
'http://tosyokan.city.saku.nagano.jp/iliswing/we/opac/kensakucheck.jsp?kensaku.x=69&kensaku.y=14&sryskb0=1&allsryskb0=1&sryskb1=2&allsryskb1=2&sryskb2=3&allsryskb2=3&sryskb3=9&allsryskb3=9&sryskb_length=4&taisyokan1=0&kanmei_length=6&max_kensu=10&KSKNO1=019&KEYWORD1=&ITTI1=1&f_kanzen1=0&ANDOR2=0&KSKNO2=004&KEYWORD2=&ITTI2=0&f_kanzen2=0&ANDOR3=0&KSKNO3=005&KEYWORD3=&ITTI3=0&f_kanzen3=0&ANDOR4=0&KSKNO4=004&KEYWORD4=&ITTI4=1&f_kanzen4=0&tandoku=120&siborikomi=040&hanni1=&hanni2=&check2=&tandoku_keyword=',
'【佐久市立図書館へ】'
);
function libsearch( api, title ) {
// get ISB10
document.body.parentNode.innerHTML.match( /\s(4(\d{8}|-[\d-]{9}-)[\dX])/ );
var isbn = '';
if ( RegExp.$1!='' ) {
isbn = RegExp.$1
// get ISB13
} else {
document.body.parentNode.innerHTML.match( /\s(978\-4(\d{8}|-[\d-]{9}-)[\dX])/ );
if ( RegExp.$1!='' ) {
isbn = RegExp.$1
}
}
// check library
var header = document.evaluate( "//div[@id='priceBlock']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue;
if ( header ) {
if ( isbn ) {
checkLibrary( api, title, isbn, header );
} else {
//makelink( '', '', '', header, 0 );
}
}
}
function checkLibrary( api, title, isbn, header ) {
GM_xmlhttpRequest(
{
method : "GET",
url : api + isbn ,
headers : {
'User-Agent' : 'Mozilla/4.0 (compatible) Greasemonkey',
'Content-type': 'application/x-www-form-urlencoded'
},
onload : function( response ) {
makelink( api, title, isbn, header, response.responseText.match(/itiranview.jsp/) );
}
}
);
}
function makelink( api, title, isbn, header, foungflg ) {
var msg = ( foungflg ) ? '蔵書あり' : '蔵書なし';
var spl_link = document.createElement( 'a' );
spl_link.setAttribute( 'target', '_blank' );
spl_link.setAttribute( 'href', api + isbn );
spl_link.setAttribute( 'title', 'To Saku City Library' );
spl_link.innerHTML = '
» ' + title + msg + ' ';
header.parentNode.insertBefore( spl_link, header.nextSibling );
}