yoharnu / Twitch Auto-Set Source Quality (Invisible)

Published:

Version: 1.1+8eec854 updated

Summary: Automatically sets Twitch player quality to Source, 1440p, or 1080p (in that order) using an invisible menu interaction. Features robust retry logic and supports Single Page Application (SPA) navigation.

Copyright: 2026, yoharnu (https://openuserjs.org/users/yoharnu)

License: MIT

Antifeature: unspecified

Twitch Auto-Set Source Quality (Invisible)

Description

This userscript automatically sets the Twitch video player quality to Source (or the highest available quality) immediately upon loading a stream.

Unlike standard automation scripts that may fail due to slow UI loading or leave menus open, this script utilizes a "Ghost Interaction" mode. It temporarily hides the settings menu using a CSS mask while navigating the options programmatically, ensuring the quality change is seamless and unobtrusive to the user.

Key Features

  • Invisible Execution: The script injects a temporary CSS mask that hides the settings menu and its container while it operates. This prevents the menu from visually popping up and obscuring the stream.
  • Smart Fallback System: It intelligently searches for quality options in a specific priority order:
    1. Source (Best)
    2. 1440p (If Source is unavailable)
    3. 1080p (Standard HD)
  • SPA & Navigation Support: The script includes full support for Twitch's Single Page Application (SPA) architecture. It detects when you navigate from the directory to a channel, or between streamers, and re-applies the settings automatically without requiring a page refresh.
  • Robust Retry Logic: It implements a retry mechanism to handle variable loading times. If the Twitch player takes several seconds to initialize, the script patiently waits and retries the interaction until it succeeds.
  • Storage Optimization: It preemptively updates the browser's localStorage to hint to the player that "Source" quality is preferred before the video begins buffering.

How It Works

  1. Detection: When a stream loads, the script monitors the DOM for the video player settings button (gear icon).
  2. Masking: It applies an opacity: 0 style to the settings menu container. This keeps the menu interactive for the script but invisible to the user.
  3. Interaction: It programmatically navigates the menu: Settings > Quality > Source.
  4. Cleanup: Once the quality is successfully selected, it closes the menu and removes the invisible mask.

Installation

  1. Install a userscript manager such as Tampermonkey (Chrome, Edge, Safari, Opera) or Violentmonkey (Firefox).
  2. Click the Install button on this page.
  3. Refresh any open Twitch tabs for the changes to take effect.

FAQ

Q: Will this break if Twitch updates their site layout?
A: The script uses robust attribute selectors (e.g., data-a-target) rather than specific CSS classes. This makes it highly resistant to Twitch's frequent layout updates and randomized class names.

Q: Why do I sometimes see a momentary flash of the menu?
A: The script attempts to hide the menu container immediately upon detection. on systems with high CPU load or slow rendering, a single frame of the menu might render before the script can apply the invisibility mask. This is rare and does not affect functionality.

Q: Does this work on VODs and Clips?
A: Yes, the script works on live streams, VODs (Video on Demand), and clips.

Rating: 0