Skip to content

Instantly share code, notes, and snippets.

@frakman1
Created May 23, 2020 02:00
Show Gist options
  • Save frakman1/4a1ab7f89eaa2d2abe64f1ad38485620 to your computer and use it in GitHub Desktop.
Save frakman1/4a1ab7f89eaa2d2abe64f1ad38485620 to your computer and use it in GitHub Desktop.
Amazon URL Cleaner
// ==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