Amazonの商品画像を追加 [仮]

AmazonアソシエイトのAPIを使用してレス末尾に商品画像のサムネイルを追加します。

目前為 2022-01-18 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Amazonの商品画像を追加 [仮]
// @description  AmazonアソシエイトのAPIを使用してレス末尾に商品画像のサムネイルを追加します。
// @version      1.2.0
// @match        https://img.2chan.net/b/*
// @icon         https://www.2chan.net/favicon.ico
// @grant        none
// @namespace    https://gf.qytechs.cn/users/809755
// @license      MIT
// ==/UserScript==

/* jshint esversion: 8 */

(function () {
    'use strict';
    function a() {
        document.querySelectorAll("blockquote a[href*=amazon]").forEach(a => {
            const m = a.href.match(/amazon[^/]+jp\/.*(?:dp|gp\/(?:product|aw\/d))\/(\w+)/);
            if (m && !a.getAttribute("imgAdded")) {
                a.setAttribute("imgAdded", "1");

                const img = document.createElement('img');
                img.src = `https://ws-fe.amazon-adsystem.com/widgets/q?_encoding=UTF8&MarketPlace=JP&ASIN=${m[1]}&ServiceVersion=20070822&ID=AsinImage&WS=1&Format=_SL120_`;
                img.setAttribute("loading", "lazy");
                img.setAttribute('style', 'margin: 5px; border: 1px solid #ccc;')

                const a2 = document.createElement('a');
                a2.setAttribute('target', '_blank');
                a2.setAttribute("imgAdded", "1");
                a2.href = a.href = a.innerText = `https://www.amazon.co.jp/dp/${m[1]}`;

                a2.appendChild(img);

                let parent = a;
                for (let i = 0; i < 3; i++) {
                    parent = parent.parentNode;
                    if (parent.nodeName === 'BLOCKQUOTE') {
                        let div;
                        if (!(div = parent.querySelector('.amazonThumb'))) {
                            div = document.createElement('div');
                            div.classList.add('amazonThumb');
                            parent.appendChild(div);
                        }
                        div.appendChild(a2);
                        break;
                    }
                }
            }
        })
    }
    setInterval(a, 2 * 1000);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址