Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Amazon商品ページの本の情報をScrapboxに記録する
const title = (document.querySelector("#productTitle") || document.querySelector("#ebooksProductTitle")).innerText;
let body = '[amazon ' + window.location.href + ']\n';
const orderContainer = (document.querySelector("#instantOrderUpdate") || document.querySelector("#ebooksInstantOrderUpdate"));
if (orderContainer) {
const year = new RegExp(/\d{4}/).exec(orderContainer.innerText)[0];
const year_month = new RegExp(/\d{4}\/\d{1,2}/).exec(orderContainer.innerText)[0];
body = body + 'Ordered: [' + year + '], [' + year_month + ']\n';
}
const category = document.querySelector('#wayfinding-breadcrumbs_container ul > li:last-child a').innerText;
body = body + 'Category: [' + category + ']\n';
const productDetails = document.querySelector("#productDetailsTable").innerText;
const detailRegexp = new RegExp(/出版社:(.*);.*\(.*\)/);
productDetails.split('\n').forEach(line => {
const match = detailRegexp.exec(line);
if (match) {
body = body + 'Publisher: [' + match[1].trim() + ']\n';
}
});
const authors = [].map.call(document.querySelectorAll('.author'), el => (el.querySelector('a.contributorNameID') || el.querySelector('a')).innerText);
body = body + 'Author, Co-Author, Translater: [' + authors.join("], [") + ']\n';
const thumbnail = (document.querySelector("#imgBlkFront") || document.querySelector("#ebooksImgBlkFront")).src;
body = body + '\n[' + thumbnail + ']';
window.open('https://scrapbox.io/itkrt2y-books/'+ encodeURIComponent(title) + '?body=' + encodeURIComponent(body));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.