// ==UserScript== // @name ASIN链接生成器 // @namespace your-namespace // @version 1.0 // @description 生成ASIN链接并跳转到对应的Amazon页面 // @match *://*.amazon.* // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; function openASINLink() { var asin = prompt("请输入ASIN"); if (asin !== null) { var domain = window.location.hostname; var url = ""; if (domain.includes("amazon.com")) { url = "https://www.amazon.com/dp/" + asin; } else if (domain.includes("amazon.ca")) { url = "https://www.amazon.ca/dp/" + asin; } else if (domain.includes("amazon.co.uk")) { url = "https://www.amazon.co.uk/dp/" + asin; } else if (domain.includes("amazon.de")) { url = "https://www.amazon.de/dp/" + asin; } window.location.href = url; } } function openBatchASINLink() { var asinList = prompt("请输入批量ASIN,以换行符分隔"); if (asinList !== null) { var domain = window.location.hostname; var url = ""; if (domain.includes("amazon.com")) { url = "https://www.amazon.com/s?rh=p_78%3A" + asinList.replace(/\n/g, "%7C"); } else if (domain.includes("amazon.ca")) { url = "https://www.amazon.ca/s?rh=p_78%3A" + asinList.replace(/\n/g, "%7C"); } else if (domain.includes("amazon.co.uk")) { url = "https://www.amazon.co.uk/s?rh=p_78%3A" + asinList.replace(/\n/g, "%7C"); } else if (domain.includes("amazon.de")) { url = "https://www.amazon.de/s?rh=p_78%3A" + asinList.replace(/\n/g, "%7C"); } window.location.href = url; } } function createButton(text, clickHandler) { var button = document.createElement("button"); button.textContent = text; button.style.position = "fixed"; button.style.top = "50%"; button.style.transform = "translateY(-50%)"; button.style.left = "10px"; button.style.zIndex = "9999"; button.addEventListener("click", clickHandler); document.body.appendChild(button); } createButton("打开ASIN", openASINLink); createButton("打开批量ASIN", openBatchASINLink); })();