Created
September 29, 2019 10:11
-
-
Save Aikufurr/14f6f0734a3f686c89b030ac56de5ae9 to your computer and use it in GitHub Desktop.
Replaces the long URL with a simpler shorter one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Amazon URL Shortener | |
// @namespace https://gist.github.com/Aikufurr | |
// @version 0.1 | |
// @description Replaces the long URL with a simpler shorter one | |
// @author Aikufurr | |
// @match https://www.amazon.co.uk/* | |
// @match https://www.amazon.com/* | |
// @match https://www.amazon.de/* | |
// @match https://www.amazon.co.jp/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var shortURL = /(dp\/.*?-?[^a-zA-Z0-9])/g; | |
var currentURL = window.location.href; | |
var website = /(amazon.*?\/)/g; | |
var domain = "https://www."; | |
if (!currentURL.match(website)[0].endsWith("/")){ | |
domain += currentURL.match(website)[0] + "/" | |
} else { | |
domain += currentURL.match(website)[0] | |
} | |
var longURL = /(amazon.*\/[a-zA-Z0-9].*\/dp)/g; | |
if (longURL.test(currentURL)){ | |
if (shortURL.test(currentURL)){ | |
var newURL = domain + currentURL.match(shortURL)[0].substring(0,currentURL.match(shortURL)[0].length-1); | |
} else { | |
var newURL = domain + currentURL.match(/(dp.*)/g)[0].substring(0,currentURL.match(/(dp.*)/g)[0].length-1); | |
} | |
window.history.pushState(newURL, "Title", newURL); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment