Greasy Fork is available in English.

Enable Ad Markers

Bring back ad markers on YouTube videos.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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;
        });
    }
})();