bilibili BufferTime Change

BufferTime Set 250s

当前为 2023-08-05 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         bilibili BufferTime Change
// @version      0.0.1
// @description  BufferTime Set 250s
// @author       Vanisoul
// @match        https://www.bilibili.com/*
// @license      MIT
// @namespace https://greasyfork.org/users/429936
// ==/UserScript==

window.addEventListener('DashPlayerReady', function(e) {
  const DashPlayer = e.detail;
  const origFire = DashPlayer.prototype.fire;
  DashPlayer.prototype.fire = function (...args) {
      console.log(`BufferLength : ${this.player.getBufferLength()}`);
      if (this.player.getStableBufferTime() !== 250) {
          this.player.setBufferPruningInterval(3);
          this.player.setStableBufferTime(250);
          this.player.setBufferTimeAtTopQuality(250);
          this.player.setBufferTimeAtTopQualityLongForm(250);
          this.player.setBufferAheadToKeep(250 + 10);
          this.player.setBufferToKeep(30000);
          console.log("hook set buffer time 250");
      }
      origFire.apply(this, args)
  }
});

// Tampermonkey 無法直接存取 Window 物件
var script = document.createElement("script");
var checkDashPlayerIntervalFunction = function () {
    if (window.DashPlayer) {
        var event = new CustomEvent('DashPlayerReady', { detail: window.DashPlayer });
        window.dispatchEvent(event);
        clearInterval(window.checkDashPlayerInterval);
    }
};
script.innerHTML = `window.checkDashPlayerInterval = setInterval(${checkDashPlayerIntervalFunction}, 100);`;
document.head.appendChild(script);