/*
* @title bookmarklet
* @description my bookmarklet
* @include http://www.oreilly.co.jp/books/*
* @license MIT License
*/
var elem = document.evaluate(
'//*[@id="center"]/ul/li[4]',
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
var isbn9 = elem.innerText.replace(/\D/g, '').match(/\d{3}(\d{9})/)[1];
var sum = 0;
for (var i = 0; i <= 8; ++i){
sum += isbn9[i] * [10, 9, 8, 7, 6, 5, 4, 3, 2][i];
}
var isbn10 = isbn9 + '0123456789X'[11 - sum % 11];
var elem2 = document.evaluate(
'//*[@id="center"]/div[2]',
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
elem2.innerHTML += '<a href="http://www.amazon.co.jp/dp/' + isbn10 + '"><img src="https://images-na.ssl-images-amazon.com/images/G/09/extranet/associates/buttons/remote-buy-jp8._V192265084_.gif" style="height:20px; vertical-align:top; padding:0 22px 0 0;" /></a>';