Skip to content

Commit

Permalink
直播页脚本注入
Browse files Browse the repository at this point in the history
  • Loading branch information
ape-byte committed Aug 17, 2023
1 parent b2e9ab7 commit e11372b
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions BarrageGrab/Scripts/inject/livePage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//上下文常量将在上方由程序注入
//const PROCESS_NAME = "进程名";

/**
* Web/PC端 直播页JS注入
* 正则: @".*:\/\/live.douyin\.com\/\d+"
**/

/*注入脚本 定时触发全局keydown,避免直播流被无操作阻断*/

// 创建一个虚拟的按键事件
const simulatedEvent = new KeyboardEvent('keydown', {
key: 'Virtual_Alt',
keyCode: 18, //alt
bubbles: true,
cancelable: true
});

// 获取要分派事件的目标元素,例如文档的根元素
const targetElement = document.documentElement;

// 设置定时器,每隔60秒模拟一次按键事件
setInterval(() => {
targetElement.dispatchEvent(simulatedEvent);
}, 1000 * 60);

// 订阅 keydown 事件 (Debug)
targetElement.addEventListener('keydown', event => {
if (event.key == "Virtual_Alt") {
console.log('[防挂机处理] 按下了', event.key);
}
});

/*禁止关闭 Websocket*/
WebSocket.prototype.close = function () { return; }


0 comments on commit e11372b

Please sign in to comment.