disable qq.com beacon

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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();
})();