Greasy Fork is available in English.

YTBetter - Enable Rewind/DVR

Позволяет перематывать YouTube-стримы, где такая возможность заблокирована

< Обсуждения 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);
    }
});

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.

Ответить

Войдите, чтобы ответить.