// ==UserScript==
// @name Chiba City Library Lookup from Amazon book listings.
// @namespace http://www.amazon.co.jp
// @description Chiba City Library Lookup from Amazon book listings.
// @include http://*.amazon.*
// ==/UserScript==
// Version 20070630
libsearch(
'https://www.library.city.chiba.jp/licsxp-opac/WOpacTifSchCmpdPreExecAction.do?returnid=&gamenid=tiles.WTifSchCmpd&chkflg=check&condition1=7&condition1Text=&mixing1=0&condition2=1&condition2Text=&range2=0&mixing2=0&condition3=6&mngshus=1&mngshus=2&mngshus=3&jyanruLabel=&yearselect=0&yearstart=&monthstart=&yearend=&monthend=&loccod=000&dispmaxnum=10&disporder=0&condition3Text=',
'千葉市図書館'
);
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( api, title, '', 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(/SearchListDocListTitleCaption/) );
}
}
);
}
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 Chiba City Library' );
spl_link.innerHTML = '
» [' + msg + '] ' + title + 'で検索 ';
header.parentNode.insertBefore( spl_link, header.nextSibling );
}