// ==UserScript== // @name Aliexpress Url Cleaner // @version 0.1 // @description Removes unnecessary parameters to Aliexpress urls // @match *://*.aliexpress.com/* // @require https://code.jquery.com/jquery-3.1.1.slim.min.js // @require https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.20.0/polyfill.min.js // @namespace https://greasyfork.org/users/168 // @grant none // @downloadURL none // ==/UserScript== /* global jQuery */ let reg = /(\/\/(?:\w+\.)*aliexpress\.com\/store\/product\/[^\/]+\/\d+_\d+\.html)(\?[^#\r\n]+)?(#.+)?/; function toCanonical(original) { let match = original.match(reg); if (match && match[1]) { return match[1] + (match[3] || ''); } return null; } (new Promise(jQuery)).then(() => { let canonical = toCanonical(window.location.href) || toCanonical(jQuery('link[rel=canonical]').attr('href') + window.location.hash); if (canonical) { window.history.replaceState({}, '', canonical); } jQuery('a').each((i, e) => { var canonical = toCanonical(e.href); if (canonical) { e.href = canonical; } }); });