修改名字,刷新不掉
// ==UserScript==
// @name KIM WOONHAK
// @namespace http://tampermonkey.net/
// @version 4.0
// @description 修改名字,刷新不掉
// @author You
// @match *://*/*
// @match *://*.nol.yanolja.com/*
// @match *://nol.yanolja.com/*
// @match *://*.interpark.com/*
// @match *://*.interparkglobal.com/*
// @match *://m.interpark.com/*
// @match *://m.interparkglobal.com/*
// @match *://*.nol.com/*
// @icon https://interpark.com/favicon.ico
// @license MIT
// @grant none
// @run-at document-start
// ==/UserScript==
(function () {
'use strict';
const OLD_NAME = "김운학";
const NEW_NAME = "kim woonhak";
function replaceNameInPage() {
if (!document.body) return;
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false);
let textNode;
while ((textNode = walker.nextNode())) {
if (textNode.nodeValue.includes(OLD_NAME)) {
textNode.nodeValue = textNode.nodeValue.replaceAll(OLD_NAME, NEW_NAME);
}
}
}
/*** MutationObserver 防抖 + 无闪烁处理 ***/
let timer = null;
const observer = new MutationObserver(mutations => {
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
replaceNameInPage();
}, 30); // 30ms 延迟,防抖动,避免页面卡顿
});
// 监听整个文档的变化,包括文本发生改变的情况
observer.observe(document.documentElement, {
childList: true,
subtree: true,
characterData: true // 这个属性确保即便数据是异步加载的,也能被捕捉到
});
// 网页初次加载时运行一次
document.addEventListener("DOMContentLoaded", replaceNameInPage);
})();