[已解决]篡改猴不知道为啥脚本不运行

佬们,第一次写篡改猴,我的脚本总是提示不执行,这是咋回事嘞
image

// ==UserScript==
// @name         vertin替换合包
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       bwdream
// @match        *://*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
        // 用于查找并修改图片的函数
    function modifyImageSrc() {
        // 查找具有指定class和src的img元素
        const imgElement = document.querySelector('img.robotImgHeadPortrait[src="../src/images/robot01.gif"]');

        if (imgElement) {
            // 修改src为你想要的URL
            imgElement.src = 'https://pic.imgdb.cn/item/66e4e10fd9c307b7e96c3125.gif'; // 替换为你的新图片URL
            console.log("图片src已被修改为: " + imgElement.src);
        }
    }

    // 初始修改尝试
    modifyImageSrc();

    // 监听DOM变化,处理动态加载的情况
    const observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (mutation.type === 'childList') {
                modifyImageSrc(); // 当DOM变化时再次尝试修改图片src
            }
        });
    });

    // 观察整个页面的DOM树
    observer.observe(document.body, {
        childList: true, // 监控子节点变化
        subtree: true // 监控整个DOM树的变化
    });
})();
1 个赞

f12 看看有没有加载这个js

1 个赞

看看文档
https://wiki.greasespot.net/Include_and_exclude_rules

1 个赞

网页代码中没有找到js脚本中的内容,然后调用的js文件一大堆,找了半天好像也没有看到

本来是自己写的,但是调试了好久也不运行,就让gpt修改了一下(js现学的)

你用的是Chrome吗

1 个赞

是chrome,自己原先写的在控制台试过能成功的

1 个赞

是的话可能是你浏览器插件管理的开发者模式没开

1 个赞

感谢佬,成功了

1 个赞

啊,为啥你们都把自己的回复删掉了

mv3的问题
不能跨域访问好像 得开开发者模式给monkey提权

2 个赞

优秀啊,点个赞

这个估计是插件的版本问题,我的bitwarden也是有时不工作,但我关了重新打开又好了