Shorten AliExpress Links

Get rid of all those useless parameters on an item URL

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        Shorten AliExpress Links
// @description Get rid of all those useless parameters on an item URL
// @namespace   ceremony.shorten.aliexpress.links
// @include     /https?:\/\/([^\.]+\.)?aliexpress\.[a-z.]*\/(store\/product|item)\/([^\/]+\/)?[_\d]+\.html(\?.*)?/
// @version     2.1
// @run-at      document-start
// @grant       none
// ==/UserScript==

let realWindow = window.parent, url = document.createElement('a');
url.href = realWindow.location.href;

url.protocol = "https:";
url.search = "";
url.hash = "";
//url.hostname = "www.aliexpress.com"; // does not work due to cookie/session variables

if (url.href !== realWindow.location.href) {
  if (realWindow.location.hostname === url.hostname && realWindow.location.protocol === url.protocol)
    realWindow.history.replaceState(null, null, url.href);
  else
    realWindow.location = url.href;
}