Created
February 10, 2025 19:45
-
-
Save a1678991/6a1af6a48efd1a3bca9b29ca920b176c to your computer and use it in GitHub Desktop.
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 Enhanced URL Processor | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Processes Amazon URLs for various enhancements. | |
// @author ChatGPT with assistance from a1678991 | |
// @match https://www.amazon.co.jp/* | |
// @grant none | |
// @run-at document-start | |
// ==/UserScript== | |
(function () { | |
"use strict"; | |
/** | |
* @param {URL} url | |
*/ | |
function processSearchPage(url) { | |
if (url.pathname.startsWith("/s") && !url.searchParams.has("emi")) { | |
url.searchParams.set("emi", "AN1VRQENFRJN5"); | |
} | |
} | |
/** | |
* @param {URL} url | |
*/ | |
function simplifyProductURL(url) { | |
const asinMatch = url.pathname.match(/\/(dp|gp\/product)\/([A-Z0-9]{10})/); | |
if (asinMatch && asinMatch[2] && asinMatch[2].length === 10) { | |
url.pathname = `/dp/${asinMatch[2]}`; | |
url.search = ""; | |
} | |
} | |
/** | |
* @param {URL} url | |
* @param {string[]} params | |
*/ | |
function removeParameters(url, params) { | |
params.forEach((param) => url.searchParams.delete(param)); | |
} | |
function updateUrl() { | |
/** @type {URL} */ | |
let currentUrl = new URL(window.location.href); | |
/** @type {string} */ | |
let originalUrlString = currentUrl.toString(); | |
processSearchPage(currentUrl); | |
simplifyProductURL(currentUrl); | |
removeParameters(currentUrl, [ | |
"ref", | |
"ref_", | |
"pf_rd_p", | |
"pf_rd_r", | |
"pd_rd_wg", | |
"pd_rd_r", | |
"pd_rd_w", | |
]); | |
if (originalUrlString !== currentUrl.toString()) { | |
window.location.href = currentUrl.toString(); | |
} | |
} | |
updateUrl(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment