amazon-bookmark-1
from Amazon-bookmark
#2021-12-22 05:35:14
#2021-09-21 20:41:53
#2021-02-06 01:59:27
著者情報が二重に書き込まれていたのを直した
#2021-01-30 19:00:16 scrap先のprojectを選べるようにした
#2020-10-02 03:50:41
#2020-09-14 14:10:55
うまく動かないページがあったので、全面的にコードを見直す
該当ページ:土木計画学(第3版) | 樗木 武 |本 | 通販 | Amazon
#2020-09-02 13:25:09
記法を書き換えた
#2020-06-21
#to-linkタグを追加した
see:ページの状態を表すhashtag
#2020-06-20
目次用箇条書き欄を追加
本をbookmarkした動機を書く欄を追加
#2020-06-17
日付タグを追加
#2020-06-03
#2020-05-30
hashtagを #book にした
s/出版社/Publisher/g
code:script.js
javascript:(() => {
const project = window.prompt('Scrap "Amazon" to your scrapbox:', 'takker');
if (!project) return;
//書籍のタイトルの処理
const p = document.getElementById("productTitle")
?? document.getElementById("ebooksProductTitle");
const title = 『${p.textContent.trim()}』;
//ASIN番号の処理
const asin = ASIN: ${document.getElementById('ASIN') ?? document.getElementsByName('ASIN.0')[0]};
const zero = n => String(n).padStart(2, '0');
//出版社と出版年月の処理
const detail = document.getElementById('detailBullets_feature_div').innerText;
const pubdata = detail.match(/出版社 : (.+)\((.+)\)/);//1シーアンドアール研究所,22018/7/27
const pubData = pubdata ?
{
publisher: Publisher: [${pubdata[1].trim()}],
date: pubdata2 = Published on [${pubdata[2].split('/').map(n => zero(n)).join('-')}]
} :
{
publisher: 'No publisher',
date: 'No pulished date'
};
// 内容紹介の処理
const subdoc = document.getElementById('bookDesc_iframe')?.contentWindow.document;
const detailText = subdoc?.getElementById('iframeContent');
const introduction = detailText?.innerText.replace(/\n/g,'\n>') ?? '';
//書影の処理
const image=document.getElementById("imgBlkFront")
?? document.getElementById("ebooksImgBlkFront");
const imageUrl = image.getAttribute("src");
//著者情報の処理
const authors = Array.prototype.map.call(document.getElementsByClassName('author'),
author => {
const at = author.innerText.replace(/,/,'');
const pu = at.match(/\(.+\)/);
const ct = at.replace(/\(.+\)/,'').replace(/ /g,'');
return ${pu} [${ct}];
});
// ページ作成日時をhash tagとして末尾に追加する
const datetime = (d =>
${d.getFullYear()}-${zero(d.getMonth() + 1)}-${zero(d.getDate())})(new Date());
//ページへの書き込み内容。ここで順番を変えればページ内容も変わります。
const lines= [
[${imageUrl} ${window.location.href}],
authors.join(' '),
pubData.publisher,
pubData.date,
> ${introduction},
'なんでbookmarkしたの?',
' ',
'目次',
' ',
#${datetime},
'#to-link'
];
const e = text => encodeURIComponent(text);
window.open(https://scrapbox.io/${project}/${e(title.trim())}?body=${e(lines.join('\n'))});
})();