Skip to content

Tame YouTube's CPU usage with a hybrid MutationObserver + requestAnimationFrame timer strategy. Lightweight, dynamic, and optimized for performance.

License

Notifications You must be signed in to change notification settings

koyasi777/youtube-cpu-tamer-hybrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎯 YouTube CPU Tamer – Hybrid Edition (Improved)

🧩 Overview

This userscript dramatically reduces CPU usage on YouTube and YouTube Music. It dynamically switches between requestAnimationFrame and MutationObserver based on tab visibility to optimize the behavior of timer APIs like setTimeout. The script also intelligently handles YouTube's SPA (Single Page Application) transitions to ensure continued stability and avoid freezes.

  • βš™οΈ Hybrid trigger strategy: Automatically switches based on visibility state
  • πŸ”„ SPA-aware repatching: Uses yt-navigate-finish events and DOM observation for automatic recovery
  • 🧠 Minimum delay threshold: Prevents interference with critical player functions
  • 🧼 Native timers from iframe: Ensures a clean and safe execution context

πŸš€ How to Install

  1. Install Violentmonkey or Tampermonkey in your browser
  2. Add the script using the link below: πŸ‘‰ Install this script

πŸ“Œ Supported Sites

  • https://www.youtube.com/
  • https://music.youtube.com/
  • https://www.youtube.com/embed/
  • https://www.youtube-nocookie.com/embed/

πŸ” Technical Highlights

  • πŸŽ› Wraps setTimeout/setInterval with hybrid throttling logic
  • πŸ‘ Uses MutationObserver in background tabs to reduce unnecessary CPU cycles
  • πŸ”§ Repatches after SPA navigation using DOM monitoring and timeout fallback
  • πŸ§ͺ Preserves .toString() on patched functions to prevent detection
  • 🧼 Utilizes native timers from sandboxed iframe to avoid contamination

πŸ‘¨β€πŸ’» Developer Notes

  • Written in modern ES2020 JavaScript
  • No pollution of global namespace
  • Uses @inject-into: page for seamless integration with YouTube internals

πŸ“œ License

MIT License You are free to use, modify, and redistribute this script at your own risk.


πŸŽ₯ Enjoy a smoother YouTube experience with a quieter CPU.

About

Tame YouTube's CPU usage with a hybrid MutationObserver + requestAnimationFrame timer strategy. Lightweight, dynamic, and optimized for performance.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published