disable qq.com beacon

disable qq.com beacon which will cause the CPU is under high load due to continuous reporting of incorrect data

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         disable qq.com beacon
// @namespace    https://github.com/Kyouichirou
// @version      1.2
// @description  disable qq.com beacon which will cause the CPU is under high load due to continuous reporting of incorrect data
// @author       HLA
// @license      MIT
// @match        https://*.qq.com/*
// @grant        none
// @compatible   chrome; just test on chrome 80+
// @noframes
// @run-at       document-start
// ==/UserScript==

(() => {
    "use strict";
    const Interceptor = {
        image: {
            anti_createElement() {
                document.createElement = new Proxy(document.createElement, {
                    apply(...args) {
                        const node = Reflect.apply(...args);
                        if (args.length === 3 && args[2][0] === "img")
                            Object.defineProperty(node, "src", { set(v) {} });
                        return node;
                    },
                });
            },
            anti_construct() {
                window.Image = new Proxy(window.Image, {
                    construct(target, args) {
                        let img = new target(...args);
                        if (args.length === 2 && args[1] === 1 && args[0] === 1)
                            Object.defineProperty(img, "src", { set(v) {} });
                        return img;
                    },
                });
            },
            initial() {
                this.anti_construct();
                this.anti_createElement();
            },
        },
        object() {
            const trap = (v) => {
                Object.defineProperties(v.prototype, {
                    fail: {
                        value: () => {
                            throw new Error("fuck tencent");
                        },
                    },
                    action: {
                        value: () => null,
                    },
                    check: {
                        value: () => null,
                    },
                });
            };
            let o = null;
            Object.defineProperty(window, "Beacon", {
                set(a) {
                    o = a;
                    trap(a);
                },
                get() {
                    return o;
                },
            });
        },
        anti_interval() {
            window.setInterval = new Proxy(window.setInterval, {
                apply(...args) {
                    if (args.length === 3) args[2][1] = 10000000;
                    Reflect.apply(...args);
                },
            });
        },
        network: {
            anti_fecth() {
                const fetch = window.fetch;
                window.fetch = (...args) =>
                    (async (args) => {
                        const url = args[0];
                        const ad_list = ["trace", "beacon"];
                        if (ad_list.some((e) => url.includes(e)))
                            throw new SyntaxError("fuck tencent");
                        else return await fetch(...args);
                    })(args);
            },
            anti_xmlHTTP() {
                window.XMLHttpRequest = class extends window.XMLHttpRequest {
                    open(...args) {
                        const url = args[1];
                        const ad_list = ["trace", "beacon"];
                        if (ad_list.some((e) => url.includes(e)))
                            throw new SyntaxError("fuck tencent");
                        else return super.open(...args);
                    }
                };
            },
        },
        start() {
            this.object();
            this.image.initial();
            if (location.hostname === "v.qq.com") this.network.anti_xmlHTTP();
            else {
                //this.anti_interval();
                this.network.anti_fecth();
                this.network.anti_xmlHTTP();
            }
        },
    };
    Interceptor.start();
})();