哔哩哔哩直播防止自动停止播放

模拟鼠标移动,防止直播间自动停止播放。

Instalar o script?
Script sugerido do autor

Você também pode gostar de 哔哩哔哩直播精简+.

Instalar o script
// ==UserScript==
// @name             哔哩哔哩直播防止自动停止播放
// @description      模拟鼠标移动,防止直播间自动停止播放。
// @include          https://live.bilibili.com/*
// @icon             https://www.bilibili.com//favicon.ico
// @run-at           document-idle
// @version          2024.11.13
// @license          MIT
// @namespace        https://greasyfork.org/users/228292
// ==/UserScript==

"use strict";

// 获取当前时间并格式化为 YYYY/MM/DD HH:MM:SS
const getCurrentTime = () => {
  const now = new Date();
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, '0');
  const day = String(now.getDate()).padStart(2, '0');
  const hours = String(now.getHours()).padStart(2, '0');
  const minutes = String(now.getMinutes()).padStart(2, '0');
  const seconds = String(now.getSeconds()).padStart(2, '0');
  return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`;
};

// 模拟鼠标移动,防止休眠
const preventAutoPause = () => {
  document.body.dispatchEvent(new MouseEvent("mousemove", { bubbles: true }));
  console.log(`[${getCurrentTime()}] 模拟鼠标移动防止自动暂停播放。`);
};

// 模拟鼠标移动每隔5分钟执行一次
preventAutoPause();
setInterval(preventAutoPause, 5 * 60 * 1000);