Last active
March 16, 2024 21:35
-
-
Save mat-1/cbe94281f8de116b1107c4b0c9c59dae to your computer and use it in GitHub Desktop.
Allow rewinding in YouTube livestreams that have it disabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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