Brook 净化互联网模块

Updated at: 2024-04-19

添加模块

  1. 名字自定义
  2. url 可留空
  3. 模块内容粘贴如下内容,然后保存
// Clean the web
// 净化互联网
// [CA]
modules = append(modules, {
    dnsquery: func(m) {
        l := [
            "new.qq.com",
            "news.qq.com",
            "view.inews.qq.com",
            "www.ifanr.com",
            "www.zhihu.com",
            "zhuanlan.zhihu.com",
            "link.zhihu.com",
            "juejin.cn",
            "link.juejin.cn",
            "www.163.com",
            "m.163.com"
        ]
        for v in l {
            if v == m.domain {
                return {} // let it go through fake DNS, avoid subsequent modules from processing
            }
        }
    },
    address: func(m) {
        if m.domainaddress {
            l := [
                "new.qq.com:443",
                "news.qq.com:443",
                "view.inews.qq.com:443",
                "www.ifanr.com:443",
                "www.zhihu.com:443",
                "zhuanlan.zhihu.com:443",
                "link.zhihu.com:443",
                "juejin.cn:443",
                "link.juejin.cn:443",
                "www.163.com:443",
                "m.163.com:443"
            ]
            for v in l {
                if v == m.domainaddress {
                    if m.network == "tcp" {
                        r := {ipaddressfrombypassdns: "A", bypass: true, "mitm": true, "mitmprotocol": "https"}
                        if m.domainaddress != "link.zhihu.com:443" && m.domainaddress != "link.juejin.cn:443" {
                            r.mitmwithbody = true
                            r.mitmautohandlecompress = true
                        }
                        return r
                    }
                    if m.network == "udp" {
                        return { "block": true }
                    }
                }
            }
            l = [
                "www.rfi.fr:443",
                "www.nytimes.com:443",
                "cn.nytimes.com:443",
                "www.dw.com:443",
                "m.dw.com:443",
                "www.zaobao.com.sg:443"
            ]
            for v in l {
                if v == m.domainaddress {
                    if m.network == "tcp" {
                        return {"mitm": true, "mitmprotocol": "https", mitmwithbody: true, mitmautohandlecompress: true}
                    }
                    if m.network == "udp" {
                        return { "block": true }
                    }
                }
            }
            text := import("text")
            if text.has_suffix(m.domainaddress, "medium.com:443") && m.domainaddress != "cdn-client.medium.com:443" && m.domainaddress != "glyph.medium.com:443" && m.domainaddress != "miro.medium.com:443" {
                if m.network == "tcp" {
                    return {"mitm": true, "mitmprotocol": "https", mitmwithbody: true, mitmautohandlecompress: true}
                }
                if m.network == "udp" {
                    return { "block": true }
                }
            }
        }
    },
    httprequest: func(request) {
        text := import("text")
        if text.has_prefix(request["URL"], "https://link.zhihu.com/") {
            brook := import("brook")
            s := brook.parsequery(brook.parseurl(request["URL"]).rawquery)["target"]
            if s {
                return {
                    "StatusCode": 301,
                    "Location": s
                }
            }
        }
        if text.has_prefix(request["URL"], "https://link.juejin.cn/") {
            brook := import("brook")
            s := brook.parsequery(brook.parseurl(request["URL"]).rawquery)["target"]
            if s {
                return {
                    "StatusCode": 301,
                    "Location": s
                }
            }
        }
    },
    httpresponse: func(request, response) {
        text := import("text")
        if false ||
            text.has_prefix(request["URL"], "https://new.qq.com/") || 
            text.has_prefix(request["URL"], "https://news.qq.com/") || 
            text.has_prefix(request["URL"], "https://view.inews.qq.com/") || 
            text.has_prefix(request["URL"], "https://www.rfi.fr/") || 
            text.has_prefix(request["URL"], "https://www.nytimes.com/") || 
            text.has_prefix(request["URL"], "https://cn.nytimes.com/") || 
            text.has_prefix(request["URL"], "https://zhuanlan.zhihu.com/p/") || 
            text.has_prefix(request["URL"], "https://www.zhihu.com/question/") ||
            text.has_prefix(request["URL"], "https://juejin.cn/post/") ||
            (text.has_prefix(request["URL"], "https://medium.com/@") && text.count(request["URL"], "/") == 4) ||
            (text.contains(request["URL"], "medium.com") && !text.has_prefix(request["URL"], "https://medium.com/")) ||
            (text.has_prefix(request["URL"], "https://www.zaobao.com.sg/") && text.contains(request["URL"], "story")) ||
            (text.has_prefix(request["URL"], "https://www.163.com/") && text.contains(request["URL"], "article")) ||
            (text.has_prefix(request["URL"], "https://m.163.com/") && text.contains(request["URL"], "article")) ||
            text.has_prefix(request["URL"], "https://www.dw.com/") ||
            text.has_prefix(request["URL"], "https://m.dw.com/") ||
            text.has_prefix(request["URL"], "https://www.ifanr.com/") ||
            false {
            delete(response, "Alt-Svc") // Avoid upgrading to http3 from http1 or http2
            delete(response, "Content-Security-Policy")
            s := `
<script>
window.addEventListener("DOMContentLoaded", async (e) => {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'https://bash.ooo/static/r.js';
    script.onload = function() {
        var article = new R(document).parse();
        document.querySelector('head').innerHTML = `+"`"+`
                <meta charset="UTF-8">
                <meta name="viewport" content="width=device-width, initial-scale=1">
                <link rel="stylesheet" href="https://bash.ooo/static/m.css" />
                <title>${article.title}</title>
                <style>
                    body: {
                        margin:0;
                        height: 100dvh;
                        overflow-y:auto;
                    }
                    .markdown-body {
                        box-sizing: border-box;
                        min-width: 200px;
                        max-width: 980px;
                        margin: 0 auto;
                        padding: 45px;
                    }
                    @media (max-width: 767px) {
                        .markdown-body {
                            padding: 15px;
                        }
                    }
                    @media (prefers-color-scheme: dark) {
                        body{background-color: #0d1117}
                    }
                </style>
            `+"`"+`;
        requestAnimationFrame(() => {
            document.querySelector('body').innerHTML = `+"`"+`<div class="markdown-body"><h1>${article.title}</h1>${article.content}</div>`+"`"+`;
        });
        // FIXME: sometimes zhuanlan.zhihu.com does not scroll
        window.dispatchEvent(new Event('scroll'));
    };
    document.body.appendChild(script);
});
</script>
`
            response["Body"] = bytes(text.replace(string(response["Body"]), "</body>", s +"</body>", 1))
            return response
        }
    }
})

模块顺序

这是我的


讨论