// ==UserScript==
// @name Asahikawa City Public Library Lookup from Amazon book listings.
// @namespace http://www.amazon.co.jp
// @description Asahikawa City Public Library Lookup from Amazon book listings.
// @include http://*.amazon.*
// ==/UserScript==
// Version 200801.01
libsearch(
'http://www2.lib.city.asahikawa.hokkaido.jp/kensaku/toslist.asp?isbnkey1=',
'旭川市図書館'
);
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
}
// check library
var header = document.evaluate("//div[@class='buying']//h1[@class='parseasinTitle']",
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null).singleNodeValue;
if ( header ) {
if ( isbn ) {
checkLibrary( api, title, isbn, header );
}
}
}
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(/toslist.asp/i) );
}
}
);
}
function makelink( api, title, isbn, header, foungflg ) {
if (foungflg){
var msg = '蔵書あり';
var spl_link = document.createElement( 'a' );
spl_link.setAttribute( 'target', '_blank' );
spl_link.setAttribute( 'href', api + isbn );
spl_link.setAttribute( 'title', 'To Asahikawa City Public Library' );
spl_link.innerHTML = ' » [' + msg + '] ' + title + 'で検索
';
}else{
var msg = '蔵書なし';
var spl_link = document.createElement( 'span' );
spl_link.innerHTML = ' » [' + msg + '] ' + title + '
';
}
header.parentNode.insertBefore( spl_link, header.nextSibling );
}