Last active
August 13, 2020 17:15
-
-
Save caj380/cdf4b0ef88a50394ad6c8570f32a212a to your computer and use it in GitHub Desktop.
Amazon URL Cleaner: Show the shortest possible URL for Amazon items.
This file contains hidden or 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/* | |
| // | |
| // @match https://smile.amazon.com/dp/* | |
| // @match https://smile.amazon.com/*/dp/* | |
| // @match https://smile.amazon.com/gp/product/* | |
| // @match https://smile.amazon.com/*/ASIN/* | |
| // | |
| // @run-at document-start | |
| // @version 0.2 | |
| // @grant none | |
| // @icon https://www.amazon.com/favicon.ico | |
| // ==/UserScript== | |
| function getProductId(url) { | |
| var m; | |
| m = url.match(/(?:.+\/)?dp\/([^/?]+)/); | |
| if (m) return m[1]; | |
| m = url.match(/gp\/product\/([^/?]+)/); | |
| if (m) return m[1]; | |
| m = url.match(/ASIN\/([^/?]+)/); | |
| if (m) return m[1]; | |
| } | |
| var url; | |
| url = document.location.href; | |
| var productId = getProductId(url); | |
| if (productId) { | |
| if (url.includes("smile.amazon")) { | |
| history.replaceState( | |
| {}, document.title, 'https://smile.amazon.com/dp/' + productId); | |
| } | |
| else { | |
| 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