YTAdSkip

Skips YouTube pre-roll ads as fast as possible

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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         YTAdSkip
// @description  Skips YouTube pre-roll ads as fast as possible
// @version      1.2
// @author       Gerg0Vagyok
// @match        https://www.youtube.com/watch*
// @license      MIT
// @run-at       document-start
// @namespace    https://lmao.sbs
// ==/UserScript==

(function () {
	// Deletes overlays
	function DeleteOverlays() {
		document.querySelector('div.video-ads.ytp-ad-module')?.remove();
		document.querySelector("div#player-ads.style-scope.ytd-watch-flexy")?.remove()
		document.querySelector("div#panels.style-scope.ytd-watch-flexy")?.remove()
	}

	// Adds a event listener to skip ads, deletes overlays too
	function SetupAdSkip() {
		const player = document.getElementById('movie_player');
		const video = document.querySelector('video');
		if (!player || !video) return false;

		DeleteOverlays();
		video.addEventListener('durationchange', () => {
			DeleteOverlays();
			if (player.classList.contains('ad-showing') && video.duration) {
				console.log("[YTAdSkip] Skipping ad");
				video.currentTime = video.duration;

				// Pause and unpause with a slight delay to go to actual video
				setTimeout(() => player.pauseVideo(), 10);
				setTimeout(() => player.playVideo(), 20);
			}
		});

		return true;
	}

	// Wait until movie_player and the video player is in the DOM
	const observer = new MutationObserver(() => {
		if (SetupAdSkip()) observer.disconnect();
	});
	observer.observe(document, { childList: true, subtree: true });
})();