Greasy Fork is available in English.

ASIN Link Generator

Generates ASIN links for Amazon websites

// ==UserScript==
// @name         ASIN Link Generator
// @namespace    asin-link-generator
// @version      1.0
// @description  Generates ASIN links for Amazon websites
// @match        *://*.amazon.com/*
// @match        *://*.amazon.ca/*
// @match        *://*.amazon.co.uk/*
// @match        *://*.amazon.de/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Create button elements
    var openASINButton = document.createElement('button');
    var openBatchASINButton = document.createElement('button');

    // Set button text
    openASINButton.textContent = '打开ASIN详情页';
    openBatchASINButton.textContent = '打开批量ASIN';

    // Set button styles
    openASINButton.style.position = 'fixed';
    openASINButton.style.left = '20px';
    openASINButton.style.top = '50%';
    openASINButton.style.transform = 'translateY(-50%)';

    openBatchASINButton.style.position = 'fixed';
    openBatchASINButton.style.left = '20px';
    openBatchASINButton.style.top = 'calc(50% + 30px)';
    openBatchASINButton.style.transform = 'translateY(-50%)';

    // Append buttons to the document body
    document.body.appendChild(openASINButton);
    document.body.appendChild(openBatchASINButton);

    // Button click event handlers
    openASINButton.addEventListener('click', function() {
        var asin = prompt('请输入ASIN:');
        if (asin) {
            var url = '';
            if (location.hostname.endsWith('.com')) {
                url = 'https://www.amazon.com/dp/' + asin;
            } else if (location.hostname.endsWith('.ca')) {
                url = 'https://www.amazon.ca/dp/' + asin;
            } else if (location.hostname.endsWith('.co.uk')) {
                url = 'https://www.amazon.co.uk/dp/' + asin;
            } else if (location.hostname.endsWith('.de')) {
                url = 'https://www.amazon.de/dp/' + asin;
            }
            if (url) {
                window.open(url);
            }
        }
    });

    openBatchASINButton.addEventListener('click', function() {
        var asins = prompt('请输入多个ASIN,以换行符分隔:');
        if (asins) {
            var url = '';
            if (location.hostname.endsWith('.com')) {
                url = 'https://www.amazon.com/s?rh=p_78%3A' + asins.replace(/\n/g, '%7C');
            } else if (location.hostname.endsWith('.ca')) {
                url = 'https://www.amazon.ca/s?rh=p_78%3A' + asins.replace(/\n/g, '%7C');
            } else if (location.hostname.endsWith('.co.uk')) {
                url = 'https://www.amazon.co.uk/s?rh=p_78%3A' + asins.replace(/\n/g, '%7C');
            } else if (location.hostname.endsWith('.de')) {
                url = 'https://www.amazon.de/s?rh=p_78%3A' + asins.replace(/\n/g, '%7C');
            }
            if (url) {
                window.open(url);
            }
        }
    });

})();