移除虾皮追踪器

高效的清理虾皮商品网址

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Remove shopee tracker
// @name:zh-TW   移除蝦皮追蹤器
// @name:zh-CN   移除虾皮追踪器
// @namespace    https://greasyfork.org
// @version      0.0.5
// @description  Efficiently clean Shopee product URLs.
// @description:zh-TW 高效的清理蝦皮商品網址
// @description:zh-CN 高效的清理虾皮商品网址
// @author       Pixmi
// @match        *://shopee.tw/*
// @match        *://shopee.ph/*
// @match        *://shopee.sg/*
// @match        *://shopee.com.my/*
// @icon         https://icons.duckduckgo.com/ip2/shopee.com.ico
// @grant        none
// @license      GPL-3.0
// @run-at       document-body
// ==/UserScript==

(function() {
    'use strict';

    const reg = new RegExp(/\-i\.([\d]+)\.([\d]+)/);
    const cleanURL = (url) => {
        const match = url.match(reg);
        if (!match) return url;
        return `/product/${match[1]}/${match[2]}`;
    };
    if (reg.test(window.location.href)) {
        window.location.replace(`${window.location.origin}${cleanURL(window.location.href)}`);
    }
    const originalPushState = history.pushState;
    const originalReplaceState = history.replaceState;

    history.pushState = function(state, title, url) {
        if (url) { url = cleanURL(url); }
        return originalPushState.call(this, state, title, url);
    };

    history.replaceState = function(state, title, url) {
        if (url) { url = cleanURL(url); }
        return originalReplaceState.call(this, state, title, url);
    };
})();