Greasy Fork

Greasy Fork is available in English.

Amazon ASIN Links

Generate Amazon ASIN links from input and open corresponding pages

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Amazon ASIN Links
// @namespace    your-namespace
// @version      1.0
// @description  Generate Amazon ASIN links from input and open corresponding pages
// @author       Your Name
// @match        https://www.amazon.com/*
// @match        https://www.amazon.ca/*
// @match        https://www.amazon.co.uk/*
// @match        https://www.amazon.de/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Create a button for opening single ASIN page
    function createOpenASINButton() {
        const button = document.createElement('button');
        button.innerHTML = '打开ASIN详情页';
        button.style.position = 'fixed';
        button.style.left = '10px';
        button.style.top = '50px';
        button.addEventListener('click', function() {
            const asin = prompt('请输入ASIN');
            if (asin) {
                const link = window.location.origin + '/dp/' + asin;
                window.open(link);
            }
        });
        document.body.appendChild(button);
    }

    // Create a button for opening batch ASIN page
    function createOpenBatchASINButton() {
        const button = document.createElement('button');
        button.innerHTML = '打开批量ASIN';
        button.style.position = 'fixed';
        button.style.left = '10px';
        button.style.top = '90px';
        button.addEventListener('click', function() {
            const asinInput = prompt('请以换行符分隔输入ASIN');
            if (asinInput) {
                const asins = asinInput.split('\n');
                const link = window.location.origin + '/s?rh=p_78%3A' + asins.join('%7C');
                window.open(link);
            }
        });
        document.body.appendChild(button);
    }

    // Check the current domain and create appropriate buttons
    const currentURL = window.location.href;
    if (currentURL.includes('amazon.com')) {
        createOpenASINButton();
        createOpenBatchASINButton();
    } else if (currentURL.includes('amazon.ca')) {
        createOpenASINButton();
        createOpenBatchASINButton();
    } else if (currentURL.includes('amazon.co.uk')) {
        createOpenASINButton();
        createOpenBatchASINButton();
    } else if (currentURL.includes('amazon.de')) {
        createOpenASINButton();
        createOpenBatchASINButton();
    }
})();