Aliexpress link fixier

This script fixes links redirects' to new interface

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

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Aliexpress link fixier
// @namespace    http://aliexpress.com/
// @version      0.1
// @description  This script fixes links redirects' to new interface
// @author       Kenya-West
// @include      *aliexpress.com*
// @grant        none
// ==/UserScript==

window.onload = () => {
    fixLinks();
}

function fixLinks() {
    let urls;
    let regex = /item\/(.*)\/(\d+)\.html/gi;

    window.setInterval(() => {

        urls = document.querySelectorAll("a[href*='aliexpress.com/item/']");

        urls.forEach((element) => {
            element.href = element.href.split(/[?#]/)[0];
            let path = new URL(element);

            if (regex.test(path.pathname) == true) {
                path.pathname = path.pathname.replace(regex, "item/$2.html");
                element.pathname = path.pathname;
            }
        })
    }, 500);
}