Amazon URL Simplifier

Simplifies Amazon product page URLs to /dp/ASIN format.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name                Amazon URL Simplifier
// @name:ja             Amazon 商品URL 短縮ツール
// @namespace           https://greasyfork.org/users/1636783
// @version             1.0.0
// @description         Simplifies Amazon product page URLs to /dp/ASIN format.
// @description:ar      تبسيط عناوين URL لصفحات منتجات أمازون إلى صيغة /dp/ASIN.
// @description:de      Vereinfacht Amazon-Produktseiten-URLs auf das Format /dp/ASIN.
// @description:es      Simplifica las URL de las páginas de productos de Amazon al formato /dp/ASIN.
// @description:fr      Simplifie les URL des pages de produits Amazon au format /dp/ASIN.
// @description:it      Semplifica gli URL delle pagine dei prodotti Amazon nel formato /dp/ASIN.
// @description:ja      Amazonの商品ページURLを /dp/ASIN の形式に短縮・簡略化します。
// @description:nl      Vereenvoudigt Amazon-productpagina-URL's naar het /dp/ASIN-formaat.
// @description:pl      Upraszcza adresy URL stron produktów Amazon do formatu /dp/ASIN.
// @description:pt-BR   Simplifica as URLs das páginas de produtos da Amazon para o formato /dp/ASIN.
// @description:sv      Förenklar URL:er för Amazon-produktsidor till /dp/ASIN-format.
// @description:tr      Amazon ürün sayfası URL'lerini /dp/ASIN biçimine sadeleştirir.
// @author              miki33
// @license             MIT
// @icon                https://www.google.com/s2/favicons?sz=64&domain=amazon.com
// @match               https://www.amazon.com.au/*
// @match               https://www.amazon.com.be/*
// @match               https://www.amazon.com.br/*
// @match               https://www.amazon.ca/*
// @match               https://www.amazon.eg/*
// @match               https://www.amazon.fr/*
// @match               https://www.amazon.de/*
// @match               https://www.amazon.in/*
// @match               https://www.amazon.ie/*
// @match               https://www.amazon.it/*
// @match               https://www.amazon.co.jp/*
// @match               https://www.amazon.com.mx/*
// @match               https://www.amazon.nl/*
// @match               https://www.amazon.pl/*
// @match               https://www.amazon.sg/*
// @match               https://www.amazon.sa/*
// @match               https://www.amazon.es/*
// @match               https://www.amazon.se/*
// @match               https://www.amazon.com.tr/*
// @match               https://www.amazon.ae/*
// @match               https://www.amazon.co.uk/*
// @match               https://www.amazon.com/*
// @match               https://www.amazon.co.za/*
// @grant               none
// @run-at              document-start
// ==/UserScript==

(() => {
    'use strict';

    // Extract 10-character ASIN from Amazon product URL path
    const ASIN_RE = /\/(?:dp|gp\/product)\/([A-Z0-9]{10})(?:[/?]|$)/i;

    // Check and normalize URL to /dp/ASIN format
    const simplifyUrl = () => {
        const match = ASIN_RE.exec(location.pathname);
        if (!match) return;

        const asin = match[1];
        const normalizedPath = `/dp/${asin}`;

        // Rewrite URL if path is unnormalized or contains query parameters
        if (location.pathname !== normalizedPath || location.search !== '') {
            history.replaceState(history.state, '', normalizedPath + location.hash);
        }
    };

    // Run on page load and periodically check for dynamic parameter changes
    simplifyUrl();
    setInterval(simplifyUrl, 250);
})();