Unlock YT Live Rewind

Força o modo DVR em transmissões ao vivo no YouTube com DVR desativado

// ==UserScript==
// @name         Unlock YT Live Rewind
// @namespace    custom.scripts.youtube
// @version      1.0.0
// @description  Força o modo DVR em transmissões ao vivo no YouTube com DVR desativado
// @author       CustomDev
// @match        https://www.youtube.com/*
// @match        https://m.youtube.com/*
// @run-at       document-start
// @grant        none
// @license      MIT
// ==/UserScript==

(() => {
  'use strict';

  // Acesso indireto ao getter/setter original de playerResponse
  const originalDescriptor = Object.getOwnPropertyDescriptor(Object.prototype, 'playerResponse');

  const originalGet = originalDescriptor?.get?.bind(Object.prototype) ?? function () {
    return this.__rewindPatch__;
  };

  const originalSet = originalDescriptor?.set?.bind(Object.prototype) ?? function (val) {
    this.__rewindPatch__ = val;
  };

  function isPlainObject(val) {
    return val && typeof val === 'object';
  }

  Object.defineProperty(Object.prototype, 'playerResponse', {
    configurable: true,
    get() {
      return originalGet.call(this);
    },
    set(newData) {
      if (!isPlainObject(newData)) {
        return originalSet.call(this, newData);
      }

      const video = newData.videoDetails;
      const stream = newData.streamingData;
      const config = newData.playerConfig;

      if (isPlainObject(video) && video.isLive && !video.isLiveDvrEnabled) {
        video.isLiveDvrEnabled = true;

        if (isPlainObject(config) && isPlainObject(config.mediaCommonConfig)) {
          config.mediaCommonConfig.useServerDrivenAbr = false;
        }

        if (isPlainObject(stream) && stream.serverAbrStreamingUrl) {
          delete stream.serverAbrStreamingUrl;
        }
      }

      originalSet.call(this, newData);
    }
  });
})();