// ==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/* // @version 1.1.1 // @author 乾かしカラス // @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 // @downloadURL none // ==/UserScript== (() => { 'use strict'; const TARGET_ELEMENT_SELECTORS = [ '#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' ]; const ASIN_SOURCES = [ () => window.location.pathname.match(/\/(?:dp|gp\/product|exec\/obidos\/asin|o\/ASIN)\/(\w{10})/)?.[1], () => new URLSearchParams(window.location.search).get('asin'), () => document.querySelector('[name="ASIN.0"],[name="ASIN"]')?.value, ]; let previousUrl = window.location.href; const observer = new MutationObserver(() => { if (previousUrl !== window.location.href) { previousUrl = window.location.href; addCheckerLinks(); } }); observer.observe(document.documentElement, { childList: true, subtree: true }); function addCheckerLinks() { removeCheckerLinks(); const asin = extractAsin(); if (!asin) return; const linksHtml = ` `; const targetElement = findTargetElementForCheckerLinks(); if (targetElement) { targetElement.insertAdjacentHTML('afterend', linksHtml); } } function removeCheckerLinks() { document.getElementById('checker-links')?.remove(); } function extractAsin() { for (const source of ASIN_SOURCES) { const asin = source(); if (asin) return asin; } return ''; } function findTargetElementForCheckerLinks() { for (const selector of TARGET_ELEMENT_SELECTORS) { const targetElement = document.querySelector(selector); if (targetElement) return targetElement.closest('div.a-section'); } return null; } function addCheckerStyles() { const styleHtml = ` `; document.head.insertAdjacentHTML('beforeend', styleHtml); } addCheckerStyles(); addCheckerLinks(); })();