Xhamster - AUTO Video Infinite LOOP v.10 Fix by smartacephale

Video Auto Infinite Replay - Fix by smartacephale (https://greasyfork.org/fr/scripts/493935-xhamster-improved)

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

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 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            Xhamster - AUTO Video Infinite LOOP v.10 Fix by smartacephale

// @version         v.10.00
// @description	    Video Auto Infinite Replay - Fix by smartacephale (https://greasyfork.org/fr/scripts/493935-xhamster-improved)
// @icon            https://external-content.duckduckgo.com/ip3/fr.xhamster.com.ico
//
// @namespace       https://greasyfork.org/fr/users/7434-janvier56
// @homepage        https://greasyfork.org/fr/users/7434-janvier56

// @match           https://*.xhamster.com/videos/*
// @grant           none
// ==/UserScript==

function waitForElementExists(parent, selector, callback) {
	const observer = new MutationObserver((_mutations) => {
		const el = parent.querySelector(selector);
		if (el) {
			observer.disconnect();
			callback(el);
		}
	});
	observer.observe(document.body, { childList: true, subtree: true });
}

waitForElementExists(document, "video", forceInfinitePlay);

function forceInfinitePlay() {
	let video = document.querySelector("video");
	// if (!video) {
	// 	video = document
	// 		.querySelector("iframe")
	// 		.contentDocument.querySelector("video");
	// }
	console.log("Video element:", video);

	// const overlayMenu = document.querySelector(
	// 	"html:not(.tablet) .xplayer.overlay-menu-opened .xp-aftershot",
	// );
	// console.log("Overlay menu:", overlayMenu);
	// if (overlayMenu) {
	// 	overlayMenu.remove();
	// }

	// Add an event listener to loop the video
	video.addEventListener("ended", () => {
		console.log("Video ended, looping...");
		video.currentTime = 0;
		video.play();
	});
}