Amazon URL Simplifier

Amazon ürün sayfası URL'lerini /dp/ASIN biçimine sadeleştirir.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu betiği yüklemek için bir betik yöneticisi eklentisi yüklemeniz gerekecektir.

(Zaten bir betik yöneticim var, hadi yükleyelim!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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);
})();