Skip to content

Instantly share code, notes, and snippets.

@eremin
Created February 13, 2017 13:05
Show Gist options
  • Save eremin/e692873b9629ab3f9b132c48a3f369d8 to your computer and use it in GitHub Desktop.
Save eremin/e692873b9629ab3f9b132c48a3f369d8 to your computer and use it in GitHub Desktop.
aliexpress+ebay+gearbest url shortener
// ==UserScript==
// @name aliexpress+ebay+gearbest url shortener
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author hedgehog
// @match https://*.aliexpress.com/item/*
// @match http://*.aliexpress.com/item/*
// @match http://*.ebay.de/itm/*
// @match https://*.ebay.de/itm/*
// @match http://*.ebay.com/itm/*
// @match https://*.ebay.com/itm/*
// @match http://*.gearbest.com/*
// @match https://*.gearbest.com/*
// @grant none
// ==/UserScript==
(function(w, l, h) {
'use strict';
var shops = {
aliexpress: /^(https?:\/\/[a-z]+\.aliexpress\.com\/item\/)[^/]+(\/[0-9]+\.html)\??.*$/,
ebay: /^(https?:\/\/www\.ebay(?:\.[a-z]+)+\/itm\/)[^\/]+(\/[0-9]+)\??.*$/,
gearbest: /^(https?:\/\/www\.gearbest\.com\/)[^\/]+(\/pp_[0-9]+\.html)\??.*$/
};
w.addEventListener("load", function load(event){
w.removeEventListener("load", load, false);
for (var replace in shops) {
if (shops.hasOwnProperty(replace) && shops[replace].test(l.href)) {
h.pushState({}, "", l.href.replace(shops[replace], "$1HUY$2"));
return;
}
}
},false);
})(window, window.location, window.history);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment