YTBetter - Enable Rewind/DVR

Unlocks rewind for YouTube live streams with disabled DVR

< YTBetter - Enable Rewind/DVR 피드백

리뷰: 좋음 - 잘 동작함

Very good script!

But sometimes I am tired to turn on and off in multi layer extension setting, so I add a button to toggle that on or off.

// Retrieve DVR status from local storage, default is false
let isDvrEnabled = JSON.parse(localStorage.getItem("isDvrEnabled")) || false;

Object.defineProperty(Object.prototype, "playerResponse", {
    set(value) {
        if (isObject(value)) {
            const { videoDetails } = value;
            if (isObject(videoDetails)) {
                videoDetails.isLiveDvrEnabled = isDvrEnabled;
            }
        }
        setter.call(this, value);
    },
    get() {
        return getter.call(this);
    },
    configurable: true,
});

// Wait for the page to load completely before adding the button
window.addEventListener('load', () => {
    const targetElement = document.querySelector("div.ytp-time-display.notranslate.ytp-live");

    if (targetElement) {
        const button = document.createElement("button");
        button.textContent = `DVR: ${isDvrEnabled ? "ON" : "OFF"}`;
        button.style.position = "relative";
        button.style.zIndex = 1000;
        button.style.marginLeft = "10px";
        button.style.background = "none";
        button.style.color = "white";
        button.style.border = "none";
        button.style.fontSize = "13px";
        button.style.cursor = "pointer";
        button.style.transition = "background-color 0.3s ease, transform 0.3s ease";


        button.addEventListener("click", () => {
            isDvrEnabled = !isDvrEnabled;
            localStorage.setItem("isDvrEnabled", JSON.stringify(isDvrEnabled));
            button.textContent = `DVR: ${isDvrEnabled ? "ON" : "OFF"}`;
            alert(`DVR is now ${isDvrEnabled ? "enabled" : "disabled"}. Please reload the video.`);
        });

        targetElement.appendChild(button);
    }
});
copyMister개발자
§
작성: 2024-07-09

Interesting, thanks for the code!

Though there shouldn't be any conflicts between YTBetter and other scripts that also modify playerResponse since it uses this[Symbol.for("YTBetter")] to assign values.

A similar approach can be seen here, for example: https://github.com/pepeloni-away/userscripts/blob/main/youtube-hls-enabler.user.js#L671

However, I don't use many scripts for YouTube myself, so I'm sure someone will find your code helpful 👍

I see. Thanks for your reply.

댓글 남기기

댓글을 남기려면 로그인하세요.