websocket拦截器

Created at 23 days ago
Updated at 23 days ago
websocket 拦截消息,解密
Total Installs
10
Today's New
+0
User Rating
- / 5.0 (0)
Current Version
1.0.0
// @require https://scriptcat.org/lib/4694/1.0.0/websocket%E6%8B%A6%E6%88%AA%E5%99%A8.js?sha384-xoE36onqY9AJDQ+gyyNPcCQIsRG0rSewCjPok9On2xpig8kDkIHjukmAhuYu5p/8
Library Details
This is a library used by userscripts, you can reference it directly in your scripts.

📖 API 使用

初始化

// 初始化 WebSocket 拦截器
WebSocketInterceptor.init();

注册消息回调

// 注册消息处理回调
WebSocketInterceptor.onMessage(function(parsedMessage, rawMessage, event) {
    // parsedMessage: 解析后的JSON对象(如果是JSON格式)
    // rawMessage: 原始文本消息
    // event: 原始WebSocket事件对象
    
    console.log('收到消息:', parsedMessage);
});

配置过滤器

// 启用调试模式
WebSocketInterceptor.setDebugMode(true);

// 添加排除过滤器(不打印包含这些关键字的消息)
WebSocketInterceptor.addExcludeFilter('PING');
WebSocketInterceptor.addExcludeFilter('PONG');

// 添加包含过滤器(只打印包含这些关键字的消息)
WebSocketInterceptor.addIncludeFilter('CHAT_ROOM_UPDATED');

// 清除所有过滤器
WebSocketInterceptor.clearExcludeFilters();
WebSocketInterceptor.clearIncludeFilters();

调试技巧

// 开启调试模式查看所有WebSocket消息
WebSocketInterceptor.setDebugMode(true);

// 只查看包含"签到"的消息
WebSocketInterceptor.clearIncludeFilters();
WebSocketInterceptor.addIncludeFilter('签到');
WebSocketInterceptor.setDebugMode(true);