Greasy Fork

Greasy Fork is available in English.

ASIN链接生成器

生成ASIN链接并跳转到对应的Amazon页面

当前为 2023-06-14 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         ASIN链接生成器
// @namespace    your-namespace
// @version      1.0
// @description  生成ASIN链接并跳转到对应的Amazon页面
// @match        *://*.amazon.*
// @grant        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);
})();