Greasy Fork 支持简体中文。

亚马逊标题显示(shopthelook页面)

Add a button to the page; clicking it extracts all ASIN values, combines them with Amazon product URL, displays for easy copying, and auto-closes the display on copy. Also adds a function to extract titles from linked pages and display them on the original page.

// ==UserScript==
// @name         亚马逊标题显示(shopthelook页面)
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Add a button to the page; clicking it extracts all ASIN values, combines them with Amazon product URL, displays for easy copying, and auto-closes the display on copy. Also adds a function to extract titles from linked pages and display them on the original page.
// @author       You
// @match        https://www.amazon.com/s?k=*
// @match        https://www.amazon.com/gp/bestsellers/*
// @match        https://www.amazon.de/*
// @match        https://www.amazon.es/*
// @match        https://www.amazon.it/*
// @match        https://www.amazon.fr/*
// @match        https://www.amazon.co.uk/*
// @match        https://www.amazon.com/shopthelook?q=*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // 提取标题并更新页面的函数
    async function updatePageWithTitles() {
        const targetElements = document.querySelectorAll('#product_grid_container > div > section > article');
        for (const element of targetElements) {
            const linkElement = element.querySelector('a');
            if (linkElement && linkElement.href) {
                try {
                    const response = await fetch(linkElement.href);
                    const text = await response.text();
                    const parser = new DOMParser();
                    const doc = parser.parseFromString(text, 'text/html');
                    const titleElement = doc.querySelector('#productTitle');
                    if (titleElement && titleElement.textContent) {
                        const span = document.createElement('span');
                        span.textContent = titleElement.textContent;
                        linkElement.appendChild(span);
                    }
                } catch (error) {
                    console.error(`Error fetching title for ${linkElement.href}: ${error}`);
                }
            }
        }
    }

    // 在页面加载或刷新时执行标题提取和更新
    window.addEventListener('load', async () => {
        if (window.location.href.includes('https://www.amazon.com/shopthelook?q=*')) {
            await updatePageWithTitles();
        }
    });
})();