Sleazy Fork is available in English.

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)

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

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

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