Etsy URL Cleaner

Removes specified query parameters from Etsy URLs

目前為 2025-03-06 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Etsy URL Cleaner
// @namespace    https://greasyfork.org/en/scripts/456795-etsy-url-cleaner
// @version      1.0.4
// @description  Removes specified query parameters from Etsy URLs
// @match        https://www.etsy.com/listing/*
// @match        https://www.etsy.com/shop/*
// @match        https://i.etsystatic.com/*
// @grant        none
// @icon        https://www.etsy.com/favicon.ico
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Danh sách các query parameters cần xóa
    // Bạn có thể dễ dàng thêm mới bằng cách thêm vào mảng này
    const QUERY_PARAMS_TO_REMOVE = [
        '?ref',
        '?click_key',
        '?ga_order',
        '?ref=simple-shop-header',
        '?ls'
    ];

    /**
     * Xóa các query parameters không mong muốn khỏi URL
     * @param {string} url - URL cần xử lý
     * @returns {string} URL đã được làm sạch
     */
    function cleanQueryParams(url) {
        let maxIndex = -1;

        // Tìm vị trí cuối cùng của bất kỳ parameter nào trong danh sách
        QUERY_PARAMS_TO_REMOVE.forEach(param => {
            const index = url.indexOf(param);
            if (index !== -1 && index > maxIndex) {
                maxIndex = index;
            }
        });

        // Nếu tìm thấy parameter, cắt bỏ từ vị trí đó trở đi
        if (maxIndex !== -1) {
            return url.substring(0, maxIndex);
        }
        return url;
    }

    /**
     * Xử lý URL hình ảnh để chuyển sang chất lượng đầy đủ
     * @param {string} url - URL cần xử lý
     * @returns {string} URL đã được xử lý hoặc null nếu không cần thay đổi
     */
    function processImageUrl(url) {
        if (url.indexOf('/il_fullxfull') !== -1) {
            return null;
        }

        if (url.indexOf('/il_') !== -1) {
            const ilIndex = url.indexOf('/il_');
            const dotIndex = url.indexOf('.', ilIndex);
            return url.substring(0, ilIndex) + '/il_fullxfull' + url.substring(dotIndex);
        }
        return null;
    }

    // Main execution
    let currentUrl = window.location.href;

    // Xử lý query parameters
    const cleanedUrl = cleanQueryParams(currentUrl);
    if (cleanedUrl !== currentUrl) {
        window.history.pushState({}, '', cleanedUrl);
        currentUrl = cleanedUrl;
    }

    // Xử lý URL hình ảnh
    const processedImageUrl = processImageUrl(currentUrl);
    if (processedImageUrl) {
        window.location.href = processedImageUrl;
    }
})();