4.4 KiB
YouTube Music Auto-Confirm & Anti-Pause
A lightweight, highly effective Tampermonkey userscript that ensures uninterrupted listening on YouTube Music. It automatically dismisses "Are you still there?" prompts, auto-accepts viewer discretion warnings, and spoofs user activity to prevent playback from pausing in the background.
✨ Features
- Anti-Pause Activity Spoofing: Silently spoofs user activity (simulating keypresses and updating internal trackers) every minute to prevent YouTube's inactivity timer from triggering.
- Auto-Dismiss "Are you still there?": If the inactivity popup does manage to appear, the script instantly detects it, clicks "Yes", and resumes playback.
- Auto-Accept Discretion Warnings: Automatically clicks "I understand and wish to proceed" on content warnings (e.g., suicide/self-harm topics) and resumes the video/song.
- Native UI Integration: Injects a sleek, non-intrusive status badge into the top-right YouTube Music navigation bar. It features a pulsing green dot and tracks how many times activity has been spoofed.
- Smart Loop Prevention: Includes a 3-second action cooldown and promise-based error handling to prevent infinite play/pause loops caused by strict browser autoplay policies.
🚀 Installation
- Install a Userscript Manager:
- Tampermonkey (Recommended)
- Violentmonkey
- Greasemonkey
- Install the Script:
- Option A (Direct Install): Click on the
YouTube_Music_Auto_Confirm_-Are_You_Still_There-_&_Discretion_Warning-1.9.user.jsfile in this repository, click the Raw button, and your userscript manager should prompt you to install it. - Option B (Manual): Open your userscript manager dashboard, click "Create a new script", copy the entire contents of the
.user.jsfile from this repository, paste it into the editor, and save (Ctrl+S / Cmd+S).
- Option A (Direct Install): Click on the
- Refresh YouTube Music: Reload any open
music.youtube.comtabs for the script to take effect.
💡 Recommended Setup
For the best, truly uninterrupted listening experience, it is highly recommended to run this script in Mozilla Firefox with the uBlock Origin extension installed.
While this script perfectly handles YouTube's native inactivity and discretion prompts, uBlock Origin will effectively block audio and video ads. Together, they provide a seamless, ad-free, and pause-free music experience.
💻 Usage
Once installed, the script runs completely in the background. You don't need to configure anything.
To verify it is working:
- Open YouTube Music.
- Look at the top right corner of the navigation bar (next to your profile picture/cast icon).
- You should see a subtle Anti-Pause: 0 badge with a pulsing dot. The number will increase every minute as the script spoofs activity to keep your session alive.
🛠️ How It Works (Technical Details)
- Activity Spoofing: YouTube tracks inactivity via the
window._lactvariable. The script updates this timestamp toDate.now()and dispatches a harmlessShiftkeyup event every 60 seconds. - DOM Monitoring: The script polls the DOM every 2 seconds (and listens for HTML5
<video>pauseevents) to check for the presence ofytmusic-you-there-rendereror#player-error-message-container. - Visibility Checks: It uses
.offsetParent !== nullto ensure it only interacts with popups that are actually visible on the screen, avoiding false positives from hidden DOM elements. - Autoplay Handling: Browsers often block scripts from calling
video.play()if the user hasn't interacted with the page recently. The script catchesDOMExceptionautoplay rejections gracefully to prevent console spam and infinite loops.
⚠️ Troubleshooting
- The video stays paused after a warning: If you open a link in a new background tab and a discretion warning appears, the script will click "Proceed", but your browser's Autoplay Policy might block the video from resuming until you physically click anywhere on the page. This is a browser security feature, not a bug in the script.
- Badge isn't showing: The script waits for the YouTube Music navigation bar to load. If you have a slow connection, it might take a few extra seconds for the "Anti-Pause" badge to appear.
📄 License
This project is open-source and available under the MIT License. Feel free to fork, modify, and improve it!