Enable Ad Markers

Bring back ad markers on YouTube videos.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Enable Ad Markers
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Bring back ad markers on YouTube videos.
// @author       BowDown097
// @match        *://*.youtube.com/*
// @match        *://*.youtu.be/*
// @icon         https://www.google.com/s2/favicons?domain=youtube.com
// ==/UserScript==

// Big thanks to https://greasyfork.org/en/scripts/32626-disable-youtube-video-ads for the youtubei player patching logic

((window, fn) => {
    var ytiPlayer;
    JSON.parseOG = JSON.parse;
    JSON.parse = function(obj) {
        if (ytiPlayer) {
            obj = ytiPlayer;
            if (obj.forEach) {
                obj.forEach((p, a) => {
                    if (p.player?.args?.player_response) {
                        a = p.player_response_;
                        patchPlayerResponse(a);
                        p.player_response = JSON.stringify(a);
                    } else if (p.playerResponse) {
                        patchPlayerResponse(p.playerResponse);
                    }
                });
            } else patchPlayerResponse(obj);
            ytiPlayer = null;
        } else {
            obj = JSON.parseOG(obj);
            if (obj.playerResponse) patchPlayerResponse(obj.playerResponse);
        }
        return obj;
    };

    var rt = Response.prototype.text;
    Response.prototype.text = function() {
        const rtThis = this, text = rt.apply(this, arguments), thenOG = text.then;
        text.then = function(fn) {
            var fnOG = fn;
            fn = function(t) {
                if (/\/v1\/player\?/.test(rtThis.url)) ytiPlayer = JSON.parseOG(t);
                if (typeof fnOG === "function") return fnOG.apply(this, arguments);
            };
            return thenOG.apply(this, arguments);
        };
        return text;
    };

    function patchPlayerResponse(playerResponse) {
        playerResponse.adPlacements?.forEach(p => {
            p.adPlacementRenderer.config.adPlacementConfig.hideCueRangeMarker = false;
        });
    }
})();