Add links to Keepa and Sakura Checker to the Amazon.co.jp product screen.
// ==UserScript==
// @name Amazon_Keepa_Sakura_Button
// @name:ja Amazonの商品画面に価格履歴とサクラチェックのボタンを追加
// @namespace https://greasyfork.org/users/1324207
// @match https://www.amazon.co.jp/dp/*
// @match https://www.amazon.co.jp/*/dp/*
// @match https://www.amazon.co.jp/gp/product/*
// @match https://www.amazon.co.jp/exec/obidos/ASIN/*
// @match https://www.amazon.co.jp/o/ASIN/*
// @match https://www.amazon.co.jp/gp/aw/d/*
// @version 1.4.0
// @author Lark8037
// @description Add links to Keepa and Sakura Checker to the Amazon.co.jp product screen.
// @description:ja Amazonの商品画面にKeepaとサクラチェッカーへのリンクを追加します。
// @license MIT
// @icon https://www.amazon.co.jp/favicon.ico
// ==/UserScript==
((d, S) => {
d.getElementById('checker-style') || d.head.appendChild(Object.assign(d.createElement('style'), {
id: 'checker-style',
textContent: `.checker a{display:inline-block;border:0;height:4ex;line-height:4ex;margin-bottom:1.2ex;width:100%;text-align:center;color:black;border-radius:10em;text-decoration:none;font-size:1em}.sakura-checker-link{background:deeppink}.sakura-checker-link:hover{background:crimson}.price-history-link{background:deepskyblue}.price-history-link:hover{background:dodgerblue}@media screen and (max-width:768px){.checker a{height:5.5ex;line-height:5.5ex}}`
}));
const getASIN = () => {
const m = location.pathname.match(/\/([A-Z0-9]{10})(?:[/?]|$)/);
return m ? m[1] : new URLSearchParams(location.search).get('asin') || d.querySelector('[name="ASIN"], [name="ASIN.0"]')?.value || '';
};
const insert = () => {
if (d.getElementById('checker-links')) return;
const asin = getASIN();
if (!asin) return;
const el = S.map(s => d.querySelector(s)).find(Boolean);
const target = el?.closest('div.a-section') || el?.parentElement;
if (!target) return;
target.insertAdjacentHTML('afterend', `<div id="checker-links" class="checker">
<a class="price-history-link" href="https://keepa.com/#!product/5-${asin}" target="_blank" rel="noopener noreferrer">価格履歴</a>
<a class="sakura-checker-link" href="https://sakura-checker.jp/search/${asin}/" target="_blank" rel="noopener noreferrer">サクラチェック</a>
</div>`);
};
new MutationObserver(() => requestAnimationFrame(insert)).observe(d.getElementById('dp') || d.body, { childList: true, subtree: true });
insert();
})(document, ['#buyNow', '#add-to-cart-button', '#buybox .a-button-stack', '#add-to-cart-button-ubb', '#buybox-see-all-buying-choices', '#buybox-see-all-buying-choices-announce', '#rcx-subscribe-submit-button-announce', '#dealsAccordionRow', '#outOfStock']);