佬们,第一次写篡改猴,我的脚本总是提示不执行,这是咋回事嘞
// ==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树的变化
});
})();