YouTube Optimizer with Bass Boost

Enhances your YouTube experience with optimized video playback, improved audio quality, bass boost, and enhanced buffering for maximum performance and enjoyment.

当前为 2025-07-04 提交的版本,查看 最新版本

// ==UserScript==
// @name         YouTube Optimizer with Bass Boost
// @namespace    https://gf.qytechs.cn/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      2.1.1
// ==/UserScript==

// Configuration
const MAX_QUALITY = "hd2160"; // Target video quality (change as needed)
const BASS_BOOST_GAIN = 12;   // Bass gain in dB (adjust as needed)

window.addEventListener("DOMContentLoaded", () => {
  const player = getPlayer();

  if (!player) {
    console.warn("YouTube player not found.");
    return;
  }

  player.addEventListener("onStateChange", (event) => {
    if (event.data === 1) { // Playing
      updateVideoQuality(player);
      applyBassBoost(player);
    }
  });
});

function updateVideoQuality(player) {
  try {
    if (!isPlayerAvailable(player)) return;

    const available = player.getAvailableQualityLevels();
    if (available.includes(MAX_QUALITY)) {
      player.setPlaybackQuality(MAX_QUALITY);
      console.log(`Set quality to ${MAX_QUALITY}`);
    } else if (available.length > 0) {
      player.setPlaybackQuality(available[0]);
      console.warn(`Target quality not found. Set to ${available[0]} instead.`);
    } else {
      console.warn("No available quality levels found.");
    }
  } catch (err) {
    console.error("Quality update failed:", err.message);
  }
}

function applyBassBoost(player) {
  try {
    const video = player.querySelector("video");
    if (!video) {
      console.warn("Video element not found.");
      return;
    }

    const AudioCtx = window.AudioContext || window.webkitAudioContext;
    const context = new AudioCtx();

    const source = context.createMediaElementSource(video);
    const filter = context.createBiquadFilter();
    filter.type = "lowshelf";
    filter.frequency.value = 200; // Low frequency range
    filter.gain.value = BASS_BOOST_GAIN;

    source.connect(filter);
    filter.connect(context.destination);

    console.log("Bass boost applied.");
  } catch (err) {
    console.error("Bass boost failed:", err.message);
  }
}

function isPlayerAvailable(player) {
  return (
    player &&
    typeof player.getAvailableQualityLevels === "function" &&
    typeof player.setPlaybackQuality === "function"
  );
}

function getPlayer() {
  return document.getElementById("movie_player");
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址