-
Notifications
You must be signed in to change notification settings - Fork 0
/
AmazonURLShortener.js
47 lines (44 loc) · 1.58 KB
/
AmazonURLShortener.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// ==UserScript==
// @name Amazon URL Shortener
// @namespace https://github.com/b1naryzer0/b1scripts/blob/main/AmazonURLShortener.js
// @version 0.2.0
// @description automatically shorten Amazon product URLs
// @author forked & modified by Fritz R., original by r7kamura
// @match https://smile.amazon.com/*
// @match https://www.amazon.ae/*
// @match https://www.amazon.au/*
// @match https://www.amazon.ca/*
// @match https://www.amazon.cn/*
// @match https://www.amazon.co.jp/*
// @match https://www.amazon.co.uk/*
// @match https://www.amazon.com/*
// @match https://www.amazon.com.br/*
// @match https://www.amazon.com.mx/*
// @match https://www.amazon.com.tr/*
// @match https://www.amazon.de/*
// @match https://www.amazon.es/*
// @match https://www.amazon.fr/*
// @match https://www.amazon.in/*
// @match https://www.amazon.it/*
// @match https://www.amazon.nl/*
// @match https://www.amazon.sa/*
// @match https://www.amazon.se/*
// @match https://www.amazon.sg/*
// ==/UserScript==
(function () {
function replaceState(path) {
window.history.replaceState({}, "", path);
}
const asinElement = document.querySelector(
'#ASIN, input[name="idx.asin"], input[name="ASIN.0"], input[name="titleID"]'
);
if (asinElement) {
replaceState(`/dp/${asinElement.value}`);
} else {
const href = window.location.href;
const match = href.match(/\/(?:dp|gp\/product)\/([A-Z0-9]{10})[/?]?/);
if (match) {
replaceState(`/dp/${match[1]}`);
}
}
})();