This script replaces Amazon URLs with a simple format and adds a button to filter search results to only Amazon-sold products.
// ==UserScript==
// @name Simplify Amazon URLs
// @name:ja AmazonのURLをシンプルにする
// @name:es Simplificar las URL de Amazon
// @name:zh-CN 简化 Amazon 的 URL
// @namespace https://x.com/mana2hoshi/
// @version 2.0
// @description This script replaces Amazon URLs with a simple format and adds a button to filter search results to only Amazon-sold products.
// @description:ja このスクリプトはAmazonのURLをシンプルなものに置き換え、さらに検索結果ページに「販売元をAmazon.co.jpに限定する」ボタンを追加します。
// @description:es Este script reemplaza las URL de Amazon con un formato simple y añade un botón para filtrar los resultados de búsqueda solo por productos vendidos por Amazon.
// @description:zh-CN 此脚本将亚马逊网址替换为简单的格式,并添加一个按钮以仅筛选亚马逊自营商品。
// @license MIT
// @author Manatsu
// @match https://www.amazon.com/*/dp/*
// @match https://www.amzn.com/*/dp/*
// @match https://www.amazon.co.uk/*/dp/*
// @match https://www.amazon.de/*/dp/*
// @match https://www.amazon.fr/*/dp/*
// @match https://www.amazon.it/*/dp/*
// @match https://www.amazon.ca/*/dp/*
// @match https://www.amazon.com.mx/*/dp/*
// @match https://www.amazon.es/*/dp/*
// @match https://www.amazon.co.jp/*/dp/*
// @match https://www.amazon.in/*/dp/*
// @match https://www.amazon.com.br/*/dp/*
// @match https://www.amazon.nl/*/dp/*
// @match https://www.amazon.com.au/*/dp/*
// @match https://www.amazon.ae/*/dp/*
// @match https://www.amazon.eg/*/dp/*
// @match https://www.amazon.pl/*/dp/*
// @match https://www.amazon.se/*/dp/*
// @match https://www.amazon.sg/*/dp/*
// @match https://www.amazon.com.tr/*/dp/*
// @match https://www.amazon.cn/*/dp/*
// @match https://www.amazon.sa/*/dp/*
// @match https://www.amazon.com.be/*/dp/*
// @match https://www.amazon.com/s*
// @match https://www.amazon.co.jp/s*
// @match https://www.amazon.co.uk/s*
// @match https://www.amazon.de/s*
// @match https://www.amazon.fr/s*
// @match https://www.amazon.it/s*
// @match https://www.amazon.ca/s*
// @match https://www.amazon.es/s*
// @grant none
// ==/UserScript==
(function () {
'use strict';
// 各国のAmazon公式Seller IDマッピング
var OFFICIAL_SELLER_IDS = {
'co.jp': 'AN1VRQENFRJN5',
'com': 'ATVPDKIKX0DER',
'co.uk': 'A3P5ROKL5A1OLE',
'de': 'A3JWKAKR8XB7XF',
'fr': 'A1X6FK5RDHNB96',
'it': 'A11IL2PNWYJU7H',
'es': 'A1AT7YVPFBWXBL',
'ca': 'A3DWYIK6Y9EEQB'
};
var currentUrl = window.location.href;
var pathName = window.location.pathname;
// 正規表現を使用してASINを抽出
var asinMatch = currentUrl.match(/\/dp\/([A-Za-z0-9]+)/);
if (asinMatch && asinMatch[1]) {
// 1. 商品詳細ページの場合は既存のURL簡素化ロジックを実行
var asin = asinMatch[1];
// Amazonの国別ドメインを取得
var amazonDomainMatch = currentUrl.match(/https:\/\/www\.amazon\.(.*?)\//);
if (amazonDomainMatch && amazonDomainMatch[1]) {
var amazonDomain = amazonDomainMatch[1];
// 新しいURLを生成
var newUrl = 'https://www.amazon.' + amazonDomain + '/dp/' + asin;
// 新しいURLにリダイレクト
window.location.href = newUrl;
}
} else if (pathName.indexOf('/s') === 0) {
// 2. 検索結果ページの場合はフィルターボタンを初期化
initSellerFilter();
}
// フィルターボタンを初期化して表示する関数
function initSellerFilter() {
var hostname = window.location.hostname;
var domainMatch = hostname.match(/amazon\.(.*?)$/);
var tld = domainMatch ? domainMatch[1] : '';
var sellerId = OFFICIAL_SELLER_IDS[tld];
// 対応するSeller IDがマッピングにない場合はボタンを表示しない
if (!sellerId) {
return;
}
var searchParams = new URLSearchParams(window.location.search);
var currentEmi = searchParams.get('emi');
var isFiltered = (currentEmi === sellerId);
var isJa = (tld === 'co.jp');
var buttonText = '';
var buttonBgColor = '';
var buttonTextColor = '';
if (isFiltered) {
buttonText = isJa ? '✅ Amazon限定中 (解除)' : '✅ Amazon Only (Cancel)';
buttonBgColor = '#2ed573'; // アクティブグリーン
buttonTextColor = '#ffffff';
} else {
buttonText = isJa ? '🌟 Amazon限定にする' : '🌟 Only Amazon';
buttonBgColor = '#ff9900'; // Amazonオレンジ
buttonTextColor = '#111111';
}
// ボタン要素を作成
var btn = document.createElement('button');
btn.id = 'amazon-seller-filter-btn';
btn.innerText = buttonText;
// スタイルを適用
btn.style.position = 'fixed';
btn.style.bottom = '20px';
btn.style.right = '20px';
btn.style.zIndex = '99999';
btn.style.padding = '12px 18px';
btn.style.fontSize = '14px';
btn.style.fontWeight = 'bold';
btn.style.color = buttonTextColor;
btn.style.backgroundColor = buttonBgColor;
btn.style.border = 'none';
btn.style.borderRadius = '25px';
btn.style.boxShadow = '0 4px 15px rgba(0, 0, 0, 0.2)';
btn.style.cursor = 'pointer';
btn.style.transition = 'all 0.2s ease-in-out';
btn.style.outline = 'none';
btn.style.display = 'flex';
btn.style.alignItems = 'center';
btn.style.fontFamily = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';
// マウスホバー時のエフェクト
btn.addEventListener('mouseover', function () {
btn.style.transform = 'translateY(-2px)';
btn.style.boxShadow = '0 6px 20px rgba(0, 0, 0, 0.3)';
btn.style.backgroundColor = isFiltered ? '#26af5f' : '#e68a00';
});
btn.addEventListener('mouseout', function () {
btn.style.transform = 'translateY(0)';
btn.style.boxShadow = '0 4px 15px rgba(0, 0, 0, 0.2)';
btn.style.backgroundColor = buttonBgColor;
});
// クリック時のトグル処理
btn.addEventListener('click', function () {
if (isFiltered) {
searchParams.delete('emi');
} else {
searchParams.set('emi', sellerId);
}
var newSearch = searchParams.toString();
var newUrl = window.location.origin + window.location.pathname;
if (newSearch) {
newUrl += '?' + newSearch;
}
window.location.href = newUrl;
});
// DOMツリーの読み込みを待ってからボタンを配置
if (document.body) {
document.body.appendChild(btn);
} else {
document.addEventListener('DOMContentLoaded', function () {
document.body.appendChild(btn);
});
}
}
})();