WS Hook

WebSocket Hook

ของเมื่อวันที่ 19-09-2021 ดู เวอร์ชันล่าสุด

สคริปต์นี้ไม่ควรถูกติดตั้งโดยตรง มันเป็นคลังสำหรับสคริปต์อื่น ๆ เพื่อบรรจุด้วยคำสั่งเมทา // @require https://update.greasyfork.org/scripts/432651/972034/WS%20Hook.js

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

var webHook=(function() {
    'use strict';
    var backup={};
    var api={
        filter:(args)=>{return true;},
        WSList:[],
        messageHandler:(event)=>{
            var e = new Event('globalWebsocketMessage')
            e.data=event.data
            window.document.dispactEvent(e);
        },
        closeHandler:(event)=>{
            var e = new Event('globalWebsocketClose')
            e.data=event.data
            window.document.dispactEvent(e);
            event.target.removeEventListener('message', api.messageHandler);
            event.target.removeEventListener('close', api.closeHandler);
        },
        beginSend:(webSocket,args)=>{},
        endSend:(webSocket,args)=>{},
        filterSend:(webSocket,args)=>{return true;}

    }
    backup.WebSocket=window.WebSocket;
    window.WebSocket=new Proxy(window.WebSocket,{
        construct:function(target,args){
            if(api.filter(args)){
                let ws=new target(...args);
                api.WSList.push(ws);
                ws.addEventListener('message', api.messageHandler);
                ws.addEventListener('close', api.closeHandler);
                backup.WSSend==ws.send;
                ws.send= new Proxy(ws.send, {
                    apply: function(target, _this, _arguments) {
                        if(ws.readyState === ws.OPEN && api.filterSend(_this, _arguments)){
                            api.beginSend(_this,_arguments)
                            Function.prototype.apply.apply(target, [_this, _arguments]);
                            api.endSend(_this,_arguments);

                        }
                    }
                });
            }
        }
    });
    console.log(api);
    return api;
})();