Skip to content

Black0S/Youtube-Loop-UserScript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YouTube A/B Loop

A lightweight userscript that adds a native A/B loop panel directly into the YouTube player β€” no extension, no bloat. Works with ScriptCat, Tampermonkey, and any compatible userscript manager.

alt text


Features

  • A β†’ B loop β€” set two timestamps and loop between them indefinitely
  • Full video loop β€” restart the entire video automatically on end
  • Mini timeline β€” draggable thumbs for A, B and the playhead, with a highlighted range overlay
  • Keyboard shortcuts β€” press A or B to set points at the current time
  • Auto-update banner β€” the panel shows a notification when a newer version is available on GitHub
  • Native look β€” glass-morphism panel that matches YouTube's own UI style
  • Zero performance waste β€” RAF-based render loop with per-frame value caching; only writes to the DOM when something actually changes

Screenshots

Panel β€” A/B mode Panel β€” Full video mode
alt text alt text

Installation

Requirements

A userscript manager installed in your browser. Recommended options:

Manager Browsers Link
ScriptCat ⭐ Chrome, Firefox, Edge scriptcat.org
Tampermonkey Chrome, Firefox, Edge, Safari tampermonkey.net
Violentmonkey Chrome, Firefox, Edge violentmonkey.github.io

One-click install

Click the link below β€” your userscript manager will open an install prompt automatically:

β†’ Install YouTube A/B Loop

Manual install

  1. Open ScriptCat (or Tampermonkey) β†’ Create a new script
  2. Paste the contents of youtube-loop.js
  3. Save (Ctrl+S)

Usage

Action How
Open the panel Click the ⊞ button in YouTube's right toolbar
Set point A Click Set on the A card, or press A
Set point B Click Set on the B card, or press B
Clear a point Click βœ• next to the point
Enable loop Toggle the Loop off / Loop on pill switch
Switch mode Click Full video or A β†’ B
Reset everything Click Reset
Seek Click anywhere on the mini-timeline, or drag any thumb

Tip: You can set A and B while the video is playing β€” the loop activates immediately.


Auto-update

ScriptCat and Tampermonkey both check for updates automatically (once per day by default) using the @updateURL and @downloadURL directives in the script header.

When a new version is published on GitHub, a yellow "Update available" banner also appears at the bottom of the panel with a direct Install link.

To bump the version yourself, update both:

  • @version in the userscript header
  • CURRENT_VERSION constant in the code

How it works

tryInject()  β†’  inject()
                  β”œβ”€β”€ mountUI()         β€” injects CSS + builds DOM
                  β”œβ”€β”€ setupModeSelector()
                  β”œβ”€β”€ setupPanelToggle()
                  β”œβ”€β”€ setupLoopToggle()
                  β”œβ”€β”€ setupPointButtons()
                  β”œβ”€β”€ setupTimeline()
                  β”œβ”€β”€ setupKeyboard()
                  β”œβ”€β”€ startRenderLoop() β€” RAF loop, enforces A/B boundary
                  └── checkForUpdate()  β€” async GitHub version fetch

Navigation between YouTube videos is handled via a MutationObserver on <title> (lightweight β€” fires only on SPA navigations, not on every DOM change). Each page gets a fresh isolated session object β€” no stale state between videos.


Development

# Clone
git clone https://github.com/Black0S/Youtube-Loop-UserScript-.git

# Edit
# youtube-loop.js is a single self-contained file β€” no build step required.

# Test
# Install locally via ScriptCat or Tampermonkey, open any YouTube video.

When releasing a new version:

  1. Bump @version in the header (e.g. 1.0.0 β†’ 1.1.0)
  2. Bump CURRENT_VERSION constant to match
  3. Push to main β€” ScriptCat, Tampermonkey, and the in-panel banner will all pick it up automatically

License

MIT Β© Black0S

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Contributors