Last active
September 8, 2020 00:39
-
-
Save kkd/8796f515b414fb6a6ebb1234bbf03017 to your computer and use it in GitHub Desktop.
Scrap Amazon to Scrapbox site.
This file contains 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
javascript:(function(){ | |
var site = 'your-scrapbox-site-name'; | |
var isKindle = false; | |
var p = document.getElementById("productTitle"); | |
if (!p) p = document.getElementById("ebooksProductTitle"); | |
var bylineInfo = document.getElementById('bylineInfo'); | |
var spans = bylineInfo.getElementsByTagName('span'); | |
for (i=0; i < spans.length; i++) { | |
let span = spans[i]; | |
if (span.innerText.match(/Kindle/) != null) isKindle = true; | |
} | |
var title = window.prompt('Scrap "Amazon" to your scrapbox.', p.innerHTML); | |
if (!title) return; | |
title = '『'+ title +'』'; | |
var image = document.getElementById("imgBlkFront"); | |
if (!image) image = document.getElementById("ebooksImgBlkFront"); | |
var imageUrl = image.getAttribute("src"); | |
var pub = []; | |
var c = document.getElementsByClassName('author'); | |
for (g=0; g < c.length ;g++){ | |
let at = c[g].innerText.replace(/,/,''); | |
let pu = at.match(/\(.+\)/); | |
let ct = at.replace(/\(.+\)/,'').replace(/ /g,''); | |
pub.push(pu + ' [' + ct + ']'); | |
} | |
var tags = ['#本','#amazon']; | |
if (isKindle) tags.push('#Kindle'); | |
var lines = '[' + imageUrl + | |
' ' + window.location.href + | |
']\n' + | |
pub.join(' ') + | |
'\n' + | |
tags.join('\n'); | |
var body = encodeURIComponent(lines); | |
window.open('https://scrapbox.io/'+ site + '/' + title.trim() + '?body=' + body); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment