Greasy Fork

Greasy Fork is available in English.

ASIN Link Generator

Generates ASIN links for Amazon websites

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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);
            }
        }
    });

})();