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

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1863|回复: 19
收起左侧

[求助] 油猴脚本有没有可能做到使html中这段内嵌js失效

  [复制链接]
hrdom 发表于 2022-9-14 19:29
50吾爱币
fiddler大概可以在响应上直接拦截替换,不知道纯油猴能不能做到?
<html>
<head>
下面这段<SCRIPT LANGUAGE="JavaScript">
if (parent.location.href == self.location.href)
{
window.location.href = 'x.asp';
alert('no');
window.stop();
}
//  End -->
</script>

......

最佳答案

查看完整内容

[mw_shl_code=javascript,true] // ==UserScript== // @name replaceJS // @namespace http://tampermonkey.net/ // @version 0.1 // @AuThor alexPencil // @match // @grant none // @run-at document-start // ==/UserScript== (function() { 'use strict'; const dispatch = (script, target) => { if(script.tagName !== "SCRIPT") { ...

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

alexPencil 发表于 2022-9-14 19:29
本帖最后由 alexPencil 于 2022-9-15 18:09 编辑

[JavaScript] 纯文本查看 复制代码
// ==UserScript==
// @name         replaceJS
// @namespace    http://tampermonkey.net/
// @version      0.1
// @AuThor       alexPencil
// @match        
// @grant        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);
        }
    }})();


尝试将以上代码添加到 tampermonkey,记得修改 match 为你的目标网站
jidesheng6 发表于 2022-9-14 20:14
 楼主| hrdom 发表于 2022-9-14 21:28
本帖最后由 hrdom 于 2022-9-14 21:38 编辑
jidesheng6 发表于 2022-9-14 20:14
可以用Ajaxhook,就是你想要的效果

试了一下似乎不行,因为这个是直接鼠标点击,打开的一个html页面,不是xmlhttprequest,拦截不到
 楼主| hrdom 发表于 2022-9-14 21:33
写了段fiddler脚本,暂时可以了,不过开着fiddler可能有些处理导致的延迟
外酥内嫩 发表于 2022-9-14 21:52
修改js然后本地替换
夜泉 发表于 2022-9-14 22:25
hrdom 发表于 2022-9-14 21:28
试了一下似乎不行,因为这个是直接鼠标点击,打开的一个html页面,不是xmlhttprequest,拦截不到

hook点击不行吗????
5omggx 发表于 2022-9-15 07:01
只有firefox扩展api具备拦截修改html的能力,参见localCDN扩展说明

免费评分

参与人数 1吾爱币 +2 热心值 +1 收起 理由
hrdom + 2 + 1 我很赞同!

查看全部评分

Nonchalant 发表于 2022-9-15 09:02
油猴应该是可以,页面加载完后,把鼠标点击事件给替换掉
sqcsl888 发表于 2022-9-15 09:41
你直接在浏览器里把这个地址的JavaScript禁止了不好了

免费评分

参与人数 1吾爱币 +2 热心值 +1 收起 理由
hrdom + 2 + 1 我很赞同!

查看全部评分

您需要登录后才可以回帖 登录 | 注册[Register]

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

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

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

GMT+8, 2024-5-15 22:27

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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