@alexPencil 对于这位大佬当时发的代码
[JavaScript] 纯文本查看 复制代码 // ==UserScript==
// [url=home.php?mod=space&uid=170990]@name[/url] replaceJS
// [url=home.php?mod=space&uid=467642]@namespace[/url] [url]http://tampermonkey.net/[/url]
// [url=home.php?mod=space&uid=1248337]@version[/url] 0.1
// [url=home.php?mod=space&uid=686208]@AuThor[/url] alexPencil
// [url=home.php?mod=space&uid=195849]@match[/url]
// [url=home.php?mod=space&uid=609072]@grant[/url] none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
const dispatch = (script, target) => {
if(script.tagName !== "SCRIPT") {
return;
}
window.onbeforescriptexecute(script);
}
const observer = new MutationObserver(mutations => {
for(const m of mutations) {
m.addedNodes.forEach(n => {
dispatch(n, m.target);
})
}
})
observer.observe(document, {
childList: true,
subtree: true,
});
window.onbeforescriptexecute = (e) => {
if(!e.textContent) {return;}
replaceTxt(e, `window.location.href = 'x.asp';`, "console.log('alexPencil1')");
replaceTxt(e, `alert("no");`, "console.log('alexPencil2')");
replaceTxt(e, `window.stop();`, "console.log('alexPencil3')");
}
function replaceTxt(script, target, change) {
let textContent = script.textContent;
if (textContent.includes(target)) {
script.textContent = textContent.replace(target,change);
}
}})(); |