Amazonの商品画面にKeepaとサクラチェッカーへのリンクを追加します。
当前为
// ==UserScript==
// @name Amazon_Keepa_Sakura_Button
// @name:ja Amazonの商品画面に価格履歴とサクラチェックのボタンを追加
// @namespace https://gf.qytechs.cn/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.0
// @author 乾かしカラス
// @description Amazonの商品画面にKeepaとサクラチェッカーへのリンクを追加します。
// @license MIT
// @icon https://www.amazon.co.jp/favicon.ico
// ==/UserScript==
(() => {
'use strict';
const TARGET_ELEMENT_SELECTORS = [
'#dealsAccordionRow',
'#buyNow',
'#add-to-cart-button',
'#outOfStock',
'#rcx-subscribe-submit-button-announce',
'#buybox-see-all-buying-choices',
'#add-to-cart-button-ubb',
'#buybox-see-all-buying-choices-announce',
];
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 = `
<div id='checker-links' class='checker'>
<a href='https://keepa.com/#!product/5-${asin}/' target='_blank' class='price-history-link'>
価格履歴
</a>
<a href='https://sakura-checker.jp/search/${asin}/' target='_blank' class='sakura-checker-link'>
サクラチェック
</a>
</div>`;
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 = `
<style>
.checker a {
display: inline-block;
border: 0;
height: 31px;
line-height: 31px;
margin-bottom: 1.2ex;
width: 100%;
text-align: center;
color: black;
border-radius: 19px;
box-shadow: 0 2px 5px 0 rgba(213, 217, 217, 0.5);
text-decoration: none;
}
.sakura-checker-link {
background: deeppink;
}
.sakura-checker-link:hover {
background: Crimson;
}
.price-history-link {
background: DeepSkyBlue;
}
.price-history-link:hover {
background: DodgerBlue;
}
</style>`;
document.head.insertAdjacentHTML('beforeend', styleHtml);
}
addCheckerStyles();
addCheckerLinks();
})();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址