Created
May 23, 2020 02:00
-
-
Save frakman1/4a1ab7f89eaa2d2abe64f1ad38485620 to your computer and use it in GitHub Desktop.
Amazon URL Cleaner
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 Cleaner | |
// @description Show the shortest possible URL for Amazon items. | |
// @namespace http://tampermonkey.net/ | |
// @match https://www.amazon.com/dp/* | |
// @match https://www.amazon.com/*/dp/* | |
// @match https://www.amazon.com/gp/product/* | |
// @match https://www.amazon.com/*/ASIN/* | |
// @run-at document-start | |
// @version 0.2 | |
// @grant none | |
// @icon https://www.amazon.com/favicon.ico | |
// ==/UserScript== | |
function getProductId() { | |
var m; | |
m = document.location.href.match(/(?:.+\/)?dp\/([^/?]+)/); | |
if (m) return m[1]; | |
m = document.location.href.match(/gp\/product\/([^/?]+)/); | |
if (m) return m[1]; | |
m = document.location.href.match(/ASIN\/([^/?]+)/); | |
if (m) return m[1]; | |
} | |
var productId = getProductId(); | |
if (productId) { | |
history.replaceState( | |
{}, document.title, 'https://www.amazon.com/dp/' + productId); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment