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 για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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