// ==UserScript==
// @name 抖音直播防暂停脚本
// @namespace http://tampermonkey.net/
// @version 1.0
// @description 通过模拟极微小操作防止抖音网页直播暂停
// @match https://live.douyin.com/*
// @match https://www.douyin.com/follow/live/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 配置参数
const config = {
moveStep: 1, // 每次移动的像素(用户不可见幅度)
interval: 30000, // 操作间隔30秒(低于常见检测阈值)
debug: false // 调试模式
};
// 创建初始位置记录器
let mousePos = { x: 0, y: 0 };
// 随机偏移函数
const randomOffset = () => Math.random() > 0.5 ? config.moveStep : -config.moveStep;
// 模拟鼠标移动(极微小幅度)
function simulateMouseMove() {
mousePos.x += randomOffset();
mousePos.y += randomOffset();
document.dispatchEvent(
new MouseEvent('mousemove', {
view: window,
bubbles: true,
cancelable: true,
clientX: mousePos.x,
clientY: mousePos.y
})
);
if (config.debug) console.log('模拟鼠标移动:', mousePos);
}
// 模拟键盘活动(无实际输入)
function simulateKeyboardActivity() {
window.dispatchEvent(
new KeyboardEvent('keydown', {
key: ' ',
keyCode: 32,
bubbles: true,
cancelable: true
})
);
if (config.debug) console.log('模拟键盘活动');
}
// 随机选择操作模式
function randomAction() {
Math.random() > 0.5 ? simulateMouseMove() : simulateKeyboardActivity();
}
// 启动保活机制
const keepAlive = setInterval(randomAction, config.interval);
// 清除定时器(可选)
// window.addEventListener('beforeunload', () => clearInterval(keepAlive));
if (config.debug) console.log('防暂停脚本已激活');
})();
【油猴/JS脚本】模拟键盘/鼠标活动避免网页版抖音中断直播
最新推荐文章于 2025-03-09 00:14:28 发布