替换亚马逊主图看效果

(自用脚本)替换第一张白底图,替换时需要鼠标选中第一张白底图,网页加载完毕才可以。

目前為 2024-03-18 提交的版本,檢視 最新版本

// ==UserScript==
// @name         替换亚马逊主图看效果
// @namespace    http://tampermonkey.net/
// @version      0.11
// @description  (自用脚本)替换第一张白底图,替换时需要鼠标选中第一张白底图,网页加载完毕才可以。
// @author       z-l.top
// @match        https://www.amazon.com/*
// @icon         https://cdn.h5ds.com/space/files/600972551685382144/20231114/648860499810643968.webp
// @icon         https://blog.z-l.top/img/favicon.png
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to set id of "zoomWindow" to empty
    function setIdToEmpty() {
        var zoomWindow = document.getElementById("zoomWindow");
        if (zoomWindow) {
            zoomWindow.id = "";
        }
    }

    // Create a button
    var button = document.createElement("button");
    button.innerHTML = "换主图";
    button.style.position = "fixed";
    button.style.left = "10px";
    button.style.zIndex = "999";
    button.style.top = "10px";
    //button.style.transform = "translateY(-50%)";
    button.style.padding = "10px";
    button.style.backgroundColor = "#007bff";
    button.style.color = "#fff";
    button.style.border = "none";
    button.style.borderRadius = "5px";
    button.style.cursor = "pointer";
    document.body.appendChild(button);

    // Function to replace images
    function replaceImages() {
        var imageUrl = prompt("Please enter the image URL:", "");
        if (imageUrl !== null && imageUrl !== "") {
            var detailImg = document.getElementById("detailImg");
            if (detailImg) {
                detailImg.src = imageUrl;
            }
            var imgTagWrapper = document.querySelector(".imgTagWrapper");
            if (imgTagWrapper) {
                imgTagWrapper.querySelector("img").src = imageUrl;
            }
            var firstButtonImg = document.querySelector(".a-button-text img");
            if (firstButtonImg) {
                firstButtonImg.src = imageUrl;
            }
        }
    }

    // Attach click event to the button
    button.addEventListener("click", replaceImages);

    // Run setIdToEmpty function
    setIdToEmpty();

    // MutationObserver to detect changes in the DOM
    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            setIdToEmpty();
        });
    });

    var config = { attributes: true, childList: true, subtree: true };
    observer.observe(document.body, config);
})();

QingJ © 2025

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