Open Johnnycyan opened 11 months ago
This is really good!
Whilst I like minimal urls, that seems to go beyond this addon's purpose (https://github.com/ClearURLs/Addon#Features) and might break things for some situations.
It's easy to do yourself with Greasemonkey though.
// ==UserScript==
// @name Amazon URL Cleaner
// @namespace http://amazon.com/
// @version 1.0
// @description Remove section between domain extension and /dp/ in Amazon URLs
// @match https://www.amazon.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Get the current URL
var url = window.location.href;
// Check if the URL is an Amazon product page
if (url.includes("/dp/")) {
// Find the positions of the domain extension and "/dp/"
var domainExtPos = url.indexOf(".com/") + 4;
var dpPos = url.indexOf("/dp/");
// Check if there is a section between the domain extension and "/dp/"
if (dpPos > domainExtPos) {
// Extract the desired parts of the URL
var newURL = url.slice(0, domainExtPos) + url.slice(dpPos);
// Replace the current URL with the cleaned version
window.history.replaceState({}, document.title, newURL);
}
}
})();
Whilst I like minimal urls, that seems to go beyond this addon's purpose (https://github.com/ClearURLs/Addon#Features) and might break things for some situations.
It's easy to do yourself with Greasemonkey though.
// ==UserScript== // @name Amazon URL Cleaner // @namespace http://amazon.com/ // @version 1.0 // @description Remove section between domain extension and /dp/ in Amazon URLs // @match https://www.amazon.com/* // @grant none // ==/UserScript== (function() { 'use strict'; // Get the current URL var url = window.location.href; // Check if the URL is an Amazon product page if (url.includes("/dp/")) { // Find the positions of the domain extension and "/dp/" var domainExtPos = url.indexOf(".com/") + 4; var dpPos = url.indexOf("/dp/"); // Check if there is a section between the domain extension and "/dp/" if (dpPos > domainExtPos) { // Extract the desired parts of the URL var newURL = url.slice(0, domainExtPos) + url.slice(dpPos); // Replace the current URL with the cleaned version window.history.replaceState({}, document.title, newURL); } } })();
Thank you that works great!
Thanks @nascentt for the idea!
I found this to be a better script, that also removes URL parameters. Copying source code below for amazon.de
// ==UserScript==
// @name Amazon URL Cleaner DE
// @description Show the shortest possible URL for Amazon items.
// @namespace https://arantius.com/misc/greasemonkey/
// @match https://www.amazon.de/dp/*
// @match https://www.amazon.de/*/dp/*
// @match https://www.amazon.de/gp/product/*
// @match https://www.amazon.de/*/ASIN/*
// @run-at document-start
// @version 9
// @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.de/dp/' + productId);
}
When going to a product page with ClearURLs I get the link
https://www.amazon.com/Sabrent-Right-Angle-Locking-Drives/dp/B08FTL9XPF
But this could be shortened even further to
https://www.amazon.com/dp/B08FTL9XPF
So would it be possible to remove the information before the
/dp/
part?I'm using the extension on Firefox if that matters.