写了个油猴脚本,发现在win chrome可以,在mac chrome不生效

也不知道是啥原因?

运行页面

// ==UserScript==
// @name         Mac App Store图片下载
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://apps.apple.com/*
// @icon         https://apps.apple.com/favicon.ico
// @grant        none
// ==/UserScript==

(function () {
  "use strict";
  let url1 = document.getElementsByClassName("we-artwork--macos-app-icon")[0].querySelector('source[type="image/png"]').srcset
  // console.log(url1.split(',').indexOf("492w"))
  let arr = url1.split(',')
  for (let i = 0; i < arr.length; i++) {
    if (arr[i].indexOf('492w') > -1){
      // console.log(arr[i].replace(/\s492w/g, ""))
      let button = document.createElement("a");
      button.innerText = "下载缩略图";
      button.style =
          "position: fixed;top: 100px;right: 80px;z-index: 99999999;background: #FFF;padding: 6px 12px;border-radius: 6px;box-shadow: 0 0 10px 0 rgba(0,0,0,.3);";
      button.href = arr[i].replace(/\s492w/g, "");
      button.target = '_blank';
      document.body.appendChild(button);
    }
  }

  /*let url2 = document.getElementsByClassName("we-screenshot-viewer__screenshots-list").querySelector('source[type="image/webp"]').srcset
  console.log(url2)*/
  const el = document.querySelector('.we-screenshot-viewer__screenshots-list')
  const liList = el.querySelectorAll('li')
  let strImg = '<div style="position: fixed;top: 140px;right: 80px;z-index: 99999999;">';
  for(let i = 0;i<liList.length;i++){
    const j = i+1
    const srcset = liList[i].querySelectorAll('source[type="image/webp"]')[0].getAttribute('srcset')
    const urlList = srcset.split(',')
    const url = urlList.find(_=>_.includes('1286w'))
    // console.log(url)
    strImg += '<a href="' + url.replace(/\s1286w/g, "") + '" style="background: #FFF;padding: 6px 12px;border-radius: 6px;box-shadow: 0 0 10px 0 rgba(0,0,0,.3);display: block;margin-top: 8px;" target="_blank">图片'+j+'</a>';
  }
  strImg += "</div>";
  let container = document.createElement("div");
  container.innerHTML = strImg;
  document.body.appendChild(container);
  /*let arr2 = url2.split(',')
  console.log(arr2)*/

  // Your code here...
})();

CleanShot 2023-06-08 at 12.07.56

将运行时期更改为 document-start, 然后代码加个 setTimeout(1000) 就可以了

多谢大佬,已经搞定

// ==UserScript==
// @name         Mac App Store图片下载
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://apps.apple.com/*
// @icon         https://apps.apple.com/favicon.ico
// @grant        none
// ==/UserScript==

(function () {
    "use strict";
    function go(){//定义函数
        // alert('1111')
        let url1 = document.getElementsByClassName("we-artwork--macos-app-icon")[0].querySelector('source[type="image/png"]').srcset
        // console.log(url1.split(',').indexOf("492w"))
        let arr = url1.split(',')
        for (let i = 0; i < arr.length; i++) {
            if (arr[i].indexOf('492w') > -1){
                // console.log(arr[i].replace(/\s492w/g, ""))
                let button = document.createElement("a");
                button.innerText = "下载缩略图";
                button.style =
                    "position: fixed;top: 100px;right: 80px;z-index: 99999999;background: #FFF;padding: 6px 12px;border-radius: 6px;box-shadow: 0 0 10px 0 rgba(0,0,0,.3);";
                button.href = arr[i].replace(/\s492w/g, "");
                button.target = '_blank';
                document.body.appendChild(button);
            }
        }

        /*let url2 = document.getElementsByClassName("we-screenshot-viewer__screenshots-list").querySelector('source[type="image/webp"]').srcset
        console.log(url2)*/
        const el = document.querySelector('.we-screenshot-viewer__screenshots-list')
        const liList = el.querySelectorAll('li')
        let strImg = '<div style="position: fixed;top: 140px;right: 80px;z-index: 99999999;">';
        for(let i = 0;i<liList.length;i++){
            const j = i+1
            const srcset = liList[i].querySelectorAll('source[type="image/webp"]')[0].getAttribute('srcset')
            const urlList = srcset.split(',')
            const url = urlList.find(_=>_.includes('1286w'))
            // console.log(url)
            strImg += '<a href="' + url.replace(/\s1286w/g, "") + '" style="background: #FFF;padding: 6px 12px;border-radius: 6px;box-shadow: 0 0 10px 0 rgba(0,0,0,.3);display: block;margin-top: 8px;" target="_blank">图片'+j+'</a>';
        }
        strImg += "</div>";
        let container = document.createElement("div");
        container.innerHTML = strImg;
        document.body.appendChild(container);
    }
    window.setTimeout(function(){go()},1000);//1秒后执行函数go
    
    /*let arr2 = url2.split(',')
    console.log(arr2)*/

    // Your code here...
})();