Hook

hook function in crawling

目前為 2023-08-13 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Hook
// @namespace    https://github.com/JaycgbEDC/Script/Js
// @version      0.1
// @description  hook function in crawling
// @author       Kribe
// @homepage     https://github.com/JaycgbEDC/Script/blob/main/Js/Hook/Hook.user.js
// @supportURL   https://github.com/JaycgbEDC/Script/issues
// @match        *://*/*
// @icon         https://s1.imagehub.cc/images/2023/08/12/default.th.jpeg
// @grant        GM_registerMenuCommand
// @grant        GM_log
// @grant        GM_setValue
// @grant        GM_getValue
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';
    debugger;
    const hookFunctionDebugger = () => {
        Function.prototype.constructor_ = Function.prototype.constructor;
        Function.prototype.constructor = function (a) {
            if(a == "debugger") {
                return function (){};
            }
            return Function.prototype.constructor_(a);
        };
    };

    const hookCookie = () => {
        var cookie_cache = document.cookie;
        Object.defineProperty(document, 'cookie', {
            get: function () {
                return cookie_cache;
            },

            set: function (val) {
                GM_log('Setting cookie', val);
                // 填写cookie名
                if (val.indexOf('m=') != -1) {
                    debugger;
                }
                var cookie = val.split(";")[0];
                var ncookie = cookie.split("=");
                var flag = false;
                var cache = cookie_cache.split("; ");
                cache = cache.map(function (a) {
                    if (a.split("=")[0] === ncookie[0]) {
                        flag = true;
                        return cookie;
                    }
                    return a;
                })
                cookie_cache = cache.join("; ");
                if (!flag) {
                    cookie_cache += cookie + "; ";
                }
                return cookie_cache;
            }
        });
    };

    const hookSetInterval = () => {
        let setInterval_ = setInterval;
        setInterval = function() {GM_log("setInterval")};
        setInterval.toString = function() {
            GM_log("有函数正在检测setInterval是否被hook");
            return setInterval_.toString();
        }
    }

    (() => {
        /* 注册用户脚本菜单 */
        const menu1 = GM_registerMenuCommand(`${GM_getValue("hookFunctionDebugger") === true ? '✅' : '⬜'} Hook FunctionDebugger`, (event) => {
            if (GM_getValue("hookFunctionDebugger") === true) {
                GM_setValue("hookFunctionDebugger", false);
            } else {
                GM_setValue("hookFunctionDebugger", true);
            }
            window.location.reload(true);
        });

        const menu2 = GM_registerMenuCommand(`${GM_getValue("hookCookie") === true ? '✅' : '⬜'} Hook Cookie`, (event) => {
            if (GM_getValue("hookCookie") === true) {
                GM_setValue("hookCookie", false);
            } else {
                GM_setValue("hookCookie", true);
            }
            window.location.reload(true);
        });

        const menu3 = GM_registerMenuCommand(`${GM_getValue("hookSetInterval") === true ? '✅' : '⬜'} Hook setInterval`, (event) => {
            if (GM_getValue("hookSetInterval") === true) {
                GM_setValue("hookSetInterval", false);
            } else {
                GM_setValue("hookSetInterval", true);
            }
            window.location.reload(true);
        });
    })();

    if (GM_getValue("hookFunctionDebugger") === true) {
        hookFunctionDebugger();
    }
    if (GM_getValue("hookCookie") === true) {
        hookCookie();
    }
    if (GM_getValue("hookSetInterval") === true) {
        hookSetInterval();
    }
})();