Skip to content

Instantly share code, notes, and snippets.

@coreequip
Forked from eremin/ageShot.js
Last active August 29, 2022 17:32
Show Gist options
  • Save coreequip/3cd548d31e55288091dba44ad4dddc4b to your computer and use it in GitHub Desktop.
Save coreequip/3cd548d31e55288091dba44ad4dddc4b to your computer and use it in GitHub Desktop.
Aliexpress/eBay/Gearbest URL Shortener
// ==UserScript==
// @name Aliexpress/eBay/Gearbest/Amazon URL Shortener
// @namespace http://tampermonkey.net/
// @version 0.5
// @author hedgehog, core.equip
// @match https://*.aliexpress.com/item/*
// @match https://*.ebay.de/itm/*
// @match https://*.ebay.com/itm/*
// @match https://*.gearbest.com/*
// @match https://*.amazon.de/*
// @match https://*.amazon.co.uk/*
// @match https://*.amazon.es/*
// @match https://*.amazon.com/*
// @grant none
// ==/UserScript==
((w, l, h) => {
'use strict'
let shops = {
aliexpress: [/^(https?:\/\/[a-z]+\.aliexpress\.com\/item\/)[^/]+(\/[0-9]+\.html)\??.*$/, '$1-$2'],
ebay: [/^(https?:\/\/www\.ebay(?:\.[a-z]+)+\/itm\/)[^\/]+(\/[0-9]+)\??.*$/, '$1-$2'],
gearbest: [/^(https?:\/\/www\.gearbest\.com\/)[^\/]+(\/pp_[0-9]+\.html)\??.*$/, '$1-$2'],
amazon: [/^(https?:\/\/\w+\.amazon\.[\w.]+\/).*?\/(B[A-Z0-9]+).*$/, '$1dp/$2']
}
w.addEventListener('load', function load(event) {
w.removeEventListener('load', load, false)
Object.keys(shops).forEach((replace) => h.pushState({}, '', l.href.replace(shops[replace][0], shops[replace][1])))
},false);
})(window, window.location, window.history);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment