forked from ape-byte/DouyinBarrageGrab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
|
||
|