您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Enhances your YouTube experience with optimized video playback, improved audio quality, bass boost, and enhanced buffering for maximum performance and enjoyment.
YouTube Optimizer is a user script that enhances your YouTube experience with optimized video playback, improved audio quality, bass boost, and enhanced buffering for maximum performance and enjoyment.
(function() {
// Paste the entire code below into your user script manager
// Example: Tampermonkey
// ==UserScript==
// @name YouTube Optimizer
// @namespace https://gf.zukizuki.org/en/users/1116584-simeonleni
// @description Enhances your YouTube experience with optimized video playback, improved audio quality, bass boost, and enhanced buffering for maximum performance and enjoyment.
// @include https://www.youtube.com/*
// @grant none
// @run-at document-end
// @version 1.0
// ==/UserScript==
// Configuration
const MAX_QUALITY = "2160p"; // Maximum video quality to buffer (change as needed)
const BASS_BOOST_LEVEL = 3; // Bass boost level (adjust as needed)
// Entry point
window.addEventListener("DOMContentLoaded", main);
function main() {
const player = getPlayer();
player.addEventListener("onStateChange", function (event) {
if (event.data === 1) {
updateSettings(player);
}
});
}
function updateSettings(player) {
try {
if (!isPlayerAvailable(player)) {
throw new Error("YouTube player not available.");
}
const currentQuality = player.getPlaybackQuality();
const currentAudioQuality = player.getPlaybackRate();
if (currentQuality !== MAX_QUALITY || currentAudioQuality === null) {
const availableQualities = player.getAvailableQualityLevels();
const targetQualityIndex = availableQualities.indexOf(MAX_QUALITY);
if (targetQualityIndex !== -1) {
const targetQuality = availableQualities[targetQualityIndex];
player.setPlaybackQuality(targetQuality);
} else {
throw new Error(`Target quality '${MAX_QUALITY}' not available.`);
}
}
if (currentAudioQuality === null) {
const availableAudioQualities = player.getAvailablePlaybackRates();
const targetAudioQualityIndex = findBestAudioQualityIndex(availableAudioQualities);
if (targetAudioQualityIndex !== -1) {
const targetAudioQuality = availableAudioQualities[targetAudioQualityIndex];
player.setPlaybackRate(targetAudioQuality);
} else {
throw new Error("No available audio qualities found.");
}
}
setBassBoost(player, BASS_BOOST_LEVEL);
} catch (error) {
console.error("An error occurred:", error.message);
}
}
function isPlayerAvailable(player) {
return (
player &&
/https:\/\/www\.youtube\.com\/watch\?v=.*/.test(window.location.href) &&
document.getElementById("live-chat-iframe") === null
);
}
function findBestAudioQualityIndex(availableAudioQualities) {
// Find the index of the highest available audio quality
let maxQualityIndex = -1;
let maxQuality = -Infinity;
availableAudioQualities.forEach((quality, index) => {
const qualityNumber = Number(quality);
if (!isNaN(qualityNumber) && qualityNumber > maxQuality) {
maxQuality = qualityNumber;
maxQualityIndex = index;
}
});
return maxQualityIndex;
}
function setBassBoost(player, level) {
const bassBoostEffect = {
name: "bassBoost",
parameters: {
gain: level,
},
};
player.applyFilter(bassBoostEffect);
}
function getPlayer() {
const player = document.getElementById("movie_player");
if (!player) {
throw new Error("YouTube player not found.");
}
return player;
}
})();
This script is compatible with the latest version of the YouTube website and its Player API. Please note that updates to the YouTube website may affect the script's functionality. In case of any issues, please check for script updates or report them on the GreasyFork page.
Author: Simeon Tuyoleni
Version: 1.0