Enable Ad Markers

Bring back ad markers on YouTube videos.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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