Last active
April 8, 2018 15:47
-
-
Save itkrt2y/578f99c9eb7eaa108c0c293017f6150c to your computer and use it in GitHub Desktop.
Amazon商品ページの本の情報をScrapboxに記録する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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