Greasy Fork

Greasy Fork is available in English.

Aliexpress Url Cleaner

Removes unnecessary parameters to Aliexpress urls

当前为 2019-01-15 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Aliexpress Url Cleaner
// @version      0.2
// @description  Removes unnecessary parameters to Aliexpress urls
// @match        *://*.aliexpress.com/*
// @namespace    http://greasyfork.icu/users/168
// @run-at       document-body
// @grant        none
// ==/UserScript==

function whenReady() {
    return new Promise((resolve) => {
        function completed() {
            document.removeEventListener('DOMContentLoaded', completed);
            window.removeEventListener('load', completed);
            resolve();
        }

        if (document.readyState === 'complete' ||
            document.readyState === 'interactive') {
            resolve();
        } else {
            document.addEventListener('DOMContentLoaded', completed);
            window.addEventListener('load', completed);
        }
    });
}


let reg = /((?:https?:)?\/\/(?:\w+\.)?aliexpress\.com\/(?:store\/product\/[^\/]+\/\d+_\d+|item\/[^\/]+\/\d+)\.html)(\?[^#\r\n]+)?(#.+)?/i;

function toCanonical(original) {
    let match = original.match(reg);
    if (match) {
        return match[1] + (match[3] || '');
    }
    return null;
}

let canonical = toCanonical(window.location.href);
if (!canonical) {
    let link = document.querySelector('head > link[rel=canonical]');
    if (link) {
        canonical = toCanonical(link.href + window.location.hash);
    }
}
if (canonical) {
    window.history.replaceState(history.state, document.title, canonical);
}

whenReady().then(() => {
    document.querySelectorAll('a').forEach((e) => {
        let canonical = toCanonical(e.href);
        if (canonical) {
            e.href = canonical;
        }
    });
});