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)

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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