Skip to content

Instantly share code, notes, and snippets.

@mazzarito
Last active July 5, 2026 11:46
Show Gist options
  • Select an option

  • Save mazzarito/d53299bbdfecf6df3b873ac58a501b21 to your computer and use it in GitHub Desktop.

Select an option

Save mazzarito/d53299bbdfecf6df3b873ac58a501b21 to your computer and use it in GitHub Desktop.
YouTube Playback Rate Resync Hotfix
// ==UserScript==
// @name YouTube Playback Rate Resync Hotfix
// @namespace https://tampermonkey.net/
// @version 1.2
// @description Re-sync YouTube audio/video after slowing playback speed on YouTube in Firefox
// @match https://www.youtube.com/*
// @run-at document-idle
// @grant none
// ==/UserScript==
(function () {
'use strict';
function attachHotfix(video) {
if (!video || video.dataset.ytSpeedHotfixAttached === 'true') return;
video.dataset.ytSpeedHotfixAttached = 'true';
let delayId = null;
let lastPlaybackRate = video.playbackRate;
video.addEventListener('ratechange', () => {
const oldPlaybackRate = lastPlaybackRate;
const newPlaybackRate = video.playbackRate;
const slowedDown = newPlaybackRate < oldPlaybackRate;
clearTimeout(delayId);
if (slowedDown) {
delayId = setTimeout(() => {
if (!video.paused && !video.seeking) {
video.currentTime = video.currentTime;
console.log(
`YouTube playback resynced after slowing from ${oldPlaybackRate}x to ${newPlaybackRate}x`
);
}
}, 300);
}
lastPlaybackRate = newPlaybackRate;
});
}
function findAndAttach() {
const video = document.querySelector('video');
if (video) attachHotfix(video);
}
findAndAttach();
const observer = new MutationObserver(findAndAttach);
observer.observe(document.documentElement, {
childList: true,
subtree: true,
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment