-
Notifications
You must be signed in to change notification settings - Fork 0
/
kindle-detail.js
34 lines (30 loc) · 1.24 KB
/
kindle-detail.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* eslint-disable no-undef */
/* eslint-disable prettier/prettier */
// eslint-disable-next-line no-unused-labels
javascript:(function (d) {
const ASIN_REGEX =
/https:\/\/www.amazon.co.jp\/(.*\/|)(dp|gp)\/(product\/|)([A-Z0-9]+).*/;
let title = d.getElementById('productTitle').textContent.trim();
let authors = [...document.querySelectorAll('#bylineInfo .author')]
.map((el) => el.textContent.replace(/\n/g,'').replace(/\t/g,'').replace(/\s+/g, ' ').trim())
.join('');
let publisher = d.querySelector(
'#rpi-attribute-book_details-publisher .rpi-attribute-value',
)?.textContent?.trim();
const publishedAt = d.querySelector(
'#rpi-attribute-book_details-publication_date .rpi-attribute-value',
).textContent.trim();
const asin = d.location.href.match(ASIN_REGEX)[4];
const seriesAsin = d
.querySelector('#seriesBulletWidget_feature_div a')
?.href?.match(ASIN_REGEX)[4];
const imageUrl = document.querySelector('#imgTagWrapperId img')?.src;
if (title) {
title = title.replace("'", "'")
}
if (authors) {
authors = authors.replace("'", "'")
}
const data = { title, authors, publisher, publishedAt, asin, seriesAsin, imageUrl };
navigator.clipboard.writeText(JSON.stringify(data));
})(document);