Skip to content

Instantly share code, notes, and snippets.

@Kenya-West
Created June 26, 2020 12:43
Show Gist options
  • Save Kenya-West/fa703dc7a0d6cdd247c2793bd1b180bb to your computer and use it in GitHub Desktop.
Save Kenya-West/fa703dc7a0d6cdd247c2793bd1b180bb to your computer and use it in GitHub Desktop.
Aliexpress-link-fixier

Description

A js file for Tampermonkey to make Aliexpress.com website redirect to the new item page. This project is a script for Aliexpress website.

How to contribute

Clone this project on GitHub and start your changes. If you want to use the script from source code, then create new script in Tampermonkey extension and put source code in opened window.

How to use this script?

You need Tampermonkey extension installed on your browser to use this style.

P. S. Author is not affiliated in any kind of mentioned organizations.

// ==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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment