FunctionHooker.js

Hook most functions on runtime via the function name

此脚本不应被直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.greasyfork.org/scripts/469993/1214452/FunctionHookerjs.js

脚本作者
TetteDev
版本
0.1
创建日期
2023-07-02
最近更新
2023-07-02
许可证
暂无

Example Usage

const hooker = new FunctionHooker();
hooker.hook('window.addEventListener', (...args) => 
{
    const dissallowedEvents = ["pagehide"]
    if (dissallowedEvents.includes(args[0])) return;

    // gets the unhooked original function if you need to call it in the hook
    const o = hooker.getOriginal("window.addEventListener");

    // addEventListener only has either 2 or 3 arguments
    if (args.length == 3) o(args[0], args[1], args[2]);
    else if (args.length == 2) o(args[0], args[1]);
});