-
Notifications
You must be signed in to change notification settings - Fork 0
/
amazon-detail.js
30 lines (25 loc) · 1.01 KB
/
amazon-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
/* 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 maker = d.querySelector('.po-brand td:nth-child(2)')?.textContent?.trim();
if (!maker) {
const els = Array.from(document.querySelectorAll('#detailBullets_feature_div .a-list-item')).filter((el) => el.textContent.includes('メーカー'));
if (els.length > 0) {
maker = els[0].querySelector('span + span')?.textContent?.trim();
}
}
const imageUrl = document.querySelector('#imgTagWrapperId img')?.src;
if (title) {
title = title.replace("'", "'")
}
if (maker) {
maker = maker.replace("'", "'")
}
const asin = d.location.href.match(ASIN_REGEX)[4];
const data = { title, maker, asin, imageUrl };
navigator.clipboard.writeText(JSON.stringify(data));
})(document);