货捕头 Replace Img Src with Id in ImageMenu

Replace img src attribute with id attribute in div id="imageMenu" 2023/3/13下午9:31:20

目前為 2023-03-13 提交的版本,檢視 最新版本

// ==UserScript==
// @name        货捕头 Replace Img Src with Id in ImageMenu
// @namespace   Violentmonkey Scripts
//
// @include     https://www.hznzcn.com/product-*.html
// @match       https://www.hznzcn.com/product-*.html
// @grant       GM_registerMenuCommand
// @grant       GM_info
// @run-at document-end
// @version     1.0
// @author      -
// @description Replace img src attribute with id attribute in div id="imageMenu" 2023/3/13下午9:31:20
// ==/UserScript==

(function() {
    'use strict';
    window.onload = function() {
        try {
          if (window.location.href.includes("hznzcn.com")) {
            const div = document.querySelector("#imageMenu");
            const images = div.querySelectorAll("img");
            images.forEach(img => {
                // console.log(img.src);
                // 将 id 属性的值设置为 src 属性的值
                img.src = img.id;
            });

            // 获取id为J_playVideo的div元素
            const videoDiv = document.getElementById("J_playVideo");
            // 如果元素存在
            if (videoDiv) {
              const videoUrl = videoDiv.getAttribute("videourl");

              const newLink = document.createElement("a");
              newLink.setAttribute("href", videoUrl);
              newLink.setAttribute("target", "_blank");
              newLink.setAttribute("class", "aLabel buyShow");
              newLink.textContent = "视频地址";
              const oldLink = document.querySelector(".aLabel.buyShow");
              oldLink.parentNode.replaceChild(newLink, oldLink);


              const link = document.createElement("a");
              // 设置a元素的href属性为videourl属性值
              link.href = videoUrl;
              link.textContent = "视频地址";

              // 获取要插入链接的目标元素
              const target = document.querySelector(".shopData-li2");
              // 如果目标元素存在
              if (target) {
                target.appendChild(link);
              } else {
                console.log("目标元素不存在");
              }


            // 內置的下載 fix
            // 获取 allCount 元素
            const allCount = document.getElementById("allCount");
            // 创建一个新的 a 标签
            const downloadLink = document.createElement("a");
            downloadLink.id = "imagePackBtn";
            downloadLink.href = "javascript:;";
            downloadLink.rel = "nofollow";
            downloadLink.textContent = "立即下载";
            // 将新的 a 标签插入到 allCount 元素的后面
            allCount.insertAdjacentElement("afterend", downloadLink);


            } else {
              console.log("J_playVideo元素不存在");
            }
          }else{
            alert('作用域出错')
          }
        } catch (error) {
          console.error('出现错误:', error);
        }
    };



})();