吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 765|回复: 5
收起左侧

[学习记录] [已关闭主题记录]油猴脚本有没有可能做到使html中这段内嵌js失效

[复制链接]
hrdom 发表于 2024-4-29 21:40

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| hrdom 发表于 2024-4-29 21:41
@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);
        }
    }})();
 楼主| hrdom 发表于 2024-4-29 21:44
本帖最后由 hrdom 于 2024-4-29 21:45 编辑

onbeforescriptexecute在chrome系的浏览器中是不支持的,仅在Firefox中支持
参考https://stackoverflow.com/questi ... nt-side-or-tweak-it
Pwaerm 发表于 2024-4-30 06:47
在插件的background.js里面可以做到
tab标签 loading时就注入改写方法的代码
三滑稽甲苯 发表于 2024-4-30 09:08
run-at document-start 试试?
xieemengxin 发表于 2024-4-30 10:53
写浏览器插件吧,这个好实现点儿。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-17 23:54

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表