优化使用hls.js库的视频站

设置缓存区大小

目前為 2025-03-19 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        优化使用hls.js库的视频站
// @description 设置缓存区大小
// @namespace   set-hls.js-cache
// @match       https://www.miguvideo.com/p/detail/*
// @match       https://vip.1905.com/play/*
// @match       https://www.1905.com/vod/play/*
// @match       https://www.olevod.com/player/vod/*
// @match       https://nnyy.in/*/*.html
// @match       https://www.nunuyy5.com/vod/*
// @match       https://www.dandanzan.me/vod/*
// @match       https://dandanzan.net/*.html
// @match       https://www.iyf.tv/play/*
// @match       https://www.iyf.tv/watch?v=*
// @version     1.3
// @author      ray
// @license     MIT
// @run-at      document-start
// @grant       unsafeWindow
// ==/UserScript==

const buffSize = 80; // 视频缓存区大小:20 - 800秒

(function() {
	const fn = MediaSource.isTypeSupported;
	unsafeWindow.MediaSource.isTypeSupported = function(...args) {
		if (unsafeWindow.Hls) {
			unsafeWindow.MediaSource.isTypeSupported = fn;
			unsafeWindow.Hls = new Proxy(Hls, {
				construct(target, args, newTarget) {
					const opts = {
						maxBufferSize: 36 << 20, // 36MB
						maxBufferLength: buffSize,
						maxMaxBufferLength: buffSize + 9,
						backBufferLength: 9
					};
					args[0] = Object.assign(args[0] || {}, opts);
					return new target(...args);
				}
			});
			setTimeout(after,99);
		}
		return fn(args);
	};
})();

function after() {
	console.log('成功设置Hls缓存区!');
	const v = document.getElementsByTagName('video')[0];
	v.muted = !1;

	let tip = document.createElement('span');
	if (location.hostname == 'nnyy.in') {
		document.querySelector('#e-tip').after(tip);
	}
	else if (location.hostname == 'dandanzan.net') {
		tip = document.querySelector('#mytip');
	}
	else if (location.hostname.endsWith('nunuyy5.com')||location.hostname.endsWith('dandanzan.me')) {
		document.querySelector('span.current-route').after(tip);
	}
	else return;

	v.addEventListener('loadedmetadata', () => {
		v.playbackRate = +localStorage.mvPlayRate || 1.4;
		tip.innerText = `   分辨率:${v.videoWidth}x${v.videoHeight}P`;
	});
}