// ==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.2.0 // @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 https://update.greasyfork.icu/scripts/498965/Amazon%E3%81%AE%E5%95%86%E5%93%81%E7%94%BB%E9%9D%A2%E3%81%AB%E4%BE%A1%E6%A0%BC%E5%B1%A5%E6%AD%B4%E3%81%A8%E3%82%B5%E3%82%AF%E3%83%A9%E3%83%81%E3%82%A7%E3%83%83%E3%82%AF%E3%81%AE%E3%83%9C%E3%82%BF%E3%83%B3%E3%82%92%E8%BF%BD%E5%8A%A0.user.js // @updateURL https://update.greasyfork.icu/scripts/498965/Amazon%E3%81%AE%E5%95%86%E5%93%81%E7%94%BB%E9%9D%A2%E3%81%AB%E4%BE%A1%E6%A0%BC%E5%B1%A5%E6%AD%B4%E3%81%A8%E3%82%B5%E3%82%AF%E3%83%A9%E3%83%81%E3%82%A7%E3%83%83%E3%82%AF%E3%81%AE%E3%83%9C%E3%82%BF%E3%83%B3%E3%82%92%E8%BF%BD%E5%8A%A0.meta.js // ==/UserScript== (() => { 'use strict'; const TARGET_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' ]; function extractAsin() { return ( window.location.pathname.split('/').find(part => part.length === 10 && /^[A-Z0-9]+$/.test(part)) || new URLSearchParams(window.location.search).get('asin') || document.querySelector('[name="ASIN.0"], [name="ASIN"]')?.value || '' ); } function findTargetElement() { for (const selector of TARGET_SELECTORS) { const target = document.querySelector(selector); if (target) return target.closest('div.a-section'); } return null; } function addCheckerLinks() { if (document.getElementById('checker-links')) return; const asin = extractAsin(); if (!asin) return; const target = findTargetElement(); if (!target) return; const div = document.createElement('div'); div.id = 'checker-links'; div.className = 'checker'; div.innerHTML = ` 価格履歴 サクラチェック `; target.insertAdjacentElement('afterend', div); } function addStyles() { if (document.getElementById('checker-style')) return; const style = document.createElement('style'); style.id = 'checker-style'; 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; } } `; document.head.appendChild(style); } let lastAsin = ''; const observer = new MutationObserver(() => { const currentAsin = extractAsin(); if (lastAsin !== currentAsin) { lastAsin = currentAsin; addCheckerLinks(); } }); observer.observe(document.documentElement, { childList: true, subtree: true }); addStyles(); addCheckerLinks(); })();