Skip to content

Instantly share code, notes, and snippets.

@mat-1
Last active March 16, 2024 21:35
Show Gist options
  • Save mat-1/cbe94281f8de116b1107c4b0c9c59dae to your computer and use it in GitHub Desktop.
Save mat-1/cbe94281f8de116b1107c4b0c9c59dae to your computer and use it in GitHub Desktop.
Allow rewinding in YouTube livestreams that have it disabled
// ==UserScript==
// @name Force enable YouTube Live Dvr
// @namespace http://tampermonkey.net/
// @version 2024-01-08
// @description Allow rewinding in YouTube livestreams that have it disabled
// @author mat
// @match https://www.youtube.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant GM_webRequest
// @run-at document-start
// @downloadURL https://gist.githubusercontent.com/mat-1/cbe94281f8de116b1107c4b0c9c59dae/raw/youtube-livedvr.js
// @updateURL https://gist.githubusercontent.com/mat-1/cbe94281f8de116b1107c4b0c9c59dae/raw/youtube-livedvr.js
// ==/UserScript==
unsafeWindow.XMLHttpRequest.prototype.open = new Proxy(self.XMLHttpRequest.prototype.open, {
apply: async (target, thisArg, args) => {
thisArg.addEventListener('readystatechange', function() {
if (thisArg.readyState !== 4) return
if (thisArg.responseURL !== 'https://www.youtube.com/youtubei/v1/player?prettyPrint=false') return
const parsed = JSON.parse(thisArg.responseText)
if (!parsed.videoDetails.isLiveDvrEnabled) {
console.log('livedvr is disabled!')
parsed.videoDetails.isLiveDvrEnabled = true
}
const patchedResponse = JSON.stringify(parsed)
Object.defineProperty(thisArg, 'response', { value: patchedResponse });
Object.defineProperty(thisArg, 'responseText', { value: patchedResponse });
});
return Reflect.apply(target, thisArg, args);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment