AmazonからScrapboxにスクラップするブックマークレット - 読む、書く、考える
AmazonからScrapboxにスクラップするブックマークレット - 読む、書く、考える を元に改変しました。
ここでブックマークレットにすること。
ブックマークレットにする前にサイトの名前をちゃんと変えてから使おう!
タイトルのエンコーディングはいらないので除去してからブックマークレットにすること。(2020/08/25)
amazonタグ、kindleタグを追加するようにした。(2020/9/4)
試し読みONの時にkindle版の書影が取れない場合があるので書影のロジックを見直した (2020/9/7)
gistにおいた→ https://gist.github.com/kkd/8796f515b414fb6a6ebb1234bbf03017 (2020/9/8)
文字列連結してるところを配列→joinに変更した。
code:script.js
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 = spansi;
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 = cg.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);
})();
Bookmarkletにしたもの
code:az2sb.js
javascript:(function(){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 = spansi;if (span.innerText.match(/Kindle/) != null) isKindle = true;}var title = window.prompt('Scrap "Amazon" to your scrapbox.', p.innerHTML);if (!title) return;title = '%E3%80%8E'+ title +'%E3%80%8F';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 = cg.innerText.replace(/,/,'');let pu = at.match(/\(.+\)/);let ct = at.replace(/\(.+\)/,'').replace(/ /g,'');pub.push(pu + ' + ct + '');}var tags = '#%E6%9C%AC','#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);})(); })();
Added on 2020-08-25
#scrap
#ブックマークレット
#scrapbox