ich teste das script gerade im kiwi browser auf der quest - der fullscreen button…
- User
ich teste das script gerade im kiwi browser auf der quest -
der fullscreen button schaltet nicht in den youtube vollbildmodus. (auf dem desktop im bravebrowser funktioniert es). das hover der buttons funktioniert gut, aber die buttons sind insgesamt sehr schwer zu "drücken" man muss eigentlich auf den rand klicken damit sie aktiviert werden. (auf dem desktop im brave browser funktioniert es sauber) die buttons haben beim klicken einen quadratischen blauen hintergrund (die buttons sind ja rund, und sollen auch keinen blauen hintergrund haben beim klicken.)
hier ist der aktuelle code - ich habe ein paar kleinigkeiten angepasst:
// ==UserScript== // @name YouTube Enhancer für Kiwi Browser auf Meta Quest 3 // @version 2.4 // @description Verbesserte Steuerung von YouTube-Videos auf der Meta Quest 3 im Kiwi Browser // @match ://.youtube.com/* // @match ://youtube.com/ // @match ://m.youtube.com/ // @grant none // ==/UserScript==
let isBlockingEnabled = false; // Warte darauf, dass die YouTube-Seite vollständig geladen ist function waitForElement(selector, timeout = 10000) { return new Promise((resolve, reject) => { const intervalTime = 100; let elapsedTime = 0; const interval = setInterval(() => { const element = document.querySelector(selector); if (element) { clearInterval(interval); resolve(element); } else { elapsedTime += intervalTime; if (elapsedTime >= timeout) { clearInterval(interval); reject(`Timeout: Element ${selector} nicht gefunden`); } } }, intervalTime); }); } function isMobileYouTube() { return window.location.hostname.includes('m.youtube.com'); } function addButtonsToPage() { // Vermeide das doppelte Hinzufügen der Buttons if (document.getElementById('customButtonContainer')) return; const buttonContainer = document.createElement('div'); buttonContainer.id = "customButtonContainer"; buttonContainer.style.cssText = ` position: fixed; top: 10px; left: 10px; z-index: 10000; display: flex; flex-direction: row; gap: 8px; background-color: rgba(0, 0, 0, 0.1); padding: 8px; border-radius: 8px; `; // Vollbild-Button const fullscreenButton = createImageButton('fullscreen', 'https://cdn1.iconfinder.com/data/icons/material-core/14/fullscreen-512.png', toggleYouTubeFullscreen); // Blockieren-Button const blockButton = createImageButton( 'block', 'https://cdn1.iconfinder.com/data/icons/smoothline-gesture/30/gesture_002-tap-hand-touch-finger-512.png', () => { isBlockingEnabled = !isBlockingEnabled; updateBlockButton(blockButton, isBlockingEnabled); } ); // Play/Pause-Button const playPauseButton = createSVGButton('play_pause', togglePlayPause); // Füge alle Buttons hinzu buttonContainer.appendChild(fullscreenButton); buttonContainer.appendChild(blockButton); buttonContainer.appendChild(playPauseButton); // Platziere den Container im Body document.body.appendChild(buttonContainer); } function createImageButton(id, imgSrc, onClick) { const button = document.createElement('button'); button.id = `customButton_${id}`; button.style.cssText = ` width: 40px; height: 40px; background-color: rgb(248, 248, 248); border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; border-radius: 50%; `; const img = document.createElement('img'); img.src = imgSrc; img.style.cssText = ` width: 17px; height: 17px; `; img.alt = id; button.appendChild(img); button.addEventListener('click', onClick); button.addEventListener('mouseenter', () => { if (id !== 'block' || !button.classList.contains('active')) { button.style.backgroundColor = 'rgba(255, 255, 255)'; button.style.borderRadius = '50%'; } }); button.addEventListener('mouseleave', () => { if (id !== 'block' || !button.classList.contains('active')) { button.style.backgroundColor = 'rgb(248, 248, 248)' } }); return button; } function createSVGButton(id, onClick) { const button = document.createElement('button'); button.id = `customButton_${id}`; button.style.cssText = ` width: 40px; height: 40px; background-color: rgb(248, 248, 248); border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; padding-left: 9px; padding-right: 0px; padding-top: 18px; border-radius: 50%; `; // Initial SVG Icon (Play) const svg = createSVGIcon(playIconPath); button.appendChild(svg); button.addEventListener('click', onClick); button.addEventListener('mouseenter', () => { button.style.backgroundColor = 'rgba(255, 255, 255)'; //button.style.borderRadius = '50%'; }); button.addEventListener('mouseleave', () => { button.style.backgroundColor = 'rgba(255, 255, 255, 0.8)'; }); return button; } function createSVGIcon(pathData) { const svgNS = "http://www.w3.org/2000/svg"; const svg = document.createElementNS(svgNS, "svg"); svg.setAttribute("height", "24"); svg.setAttribute("width", "24"); svg.setAttribute("viewBox", "0 0 36 36"); svg.style.objectFit = "contain"; const path = document.createElementNS(svgNS, "path"); path.setAttribute("d", pathData); path.setAttribute("fill", "#3d3d3d"); svg.appendChild(path); return svg; } // SVG-Pfade für die Play/Pause-Icons const playIconPath = "M8 5v14l11-7z"; const pauseIconPath = "M6 19h4V5H6v14zm8-14v14h4V5h-4z"; // SVG-Pfade für aktive/inaktive Block-Icons (falls benötigt) const blockInactiveIconPath = ""; // Bereits mit ImageButton umgesetzt const blockActiveIconPath = ""; // Bereits mit ImageButton umgesetzt function togglePlayPause() { const video = document.querySelector('video'); if (video) { video.paused ? video.play() : video.pause(); updatePlayPauseButton(video.paused); } } function updatePlayPauseButton(isPaused) { const playPauseButton = document.getElementById('customButton_play_pause'); if (playPauseButton) { const svg = playPauseButton.querySelector('svg path'); if (svg) { svg.setAttribute("d", isPaused ? playIconPath : pauseIconPath); } } } function updateBlockButton(button, isActive) { const img = button.querySelector('img'); if (img) { img.src = isActive ? 'https://cdn3.iconfinder.com/data/icons/user-interface-essential-4/64/cancel-failed-decline-cross-round-ui-user-interface-512.png' : 'https://cdn1.iconfinder.com/data/icons/smoothline-gesture/30/gesture_002-tap-hand-touch-finger-512.png'; } if (isActive) { button.classList.add('active'); button.style.backgroundColor = 'rgba(255, 255, 255)'; } else { button.classList.remove('active'); //button.style.backgroundColor = '#e3e3e3e6'; } } async function toggleYouTubeFullscreen() { const ytpFullscreenButton = document.querySelector('.ytp-fullscreen-button'); if (ytpFullscreenButton) { console.log("schalte fullscreen"); ytpFullscreenButton.click(); } } function applyMobileCSSChanges() { if (!isMobileYouTube()) return; const style = document.createElement('style'); style.textContent = ` yt-progress-bar { top: 35px !important; bottom: auto !important; } .player-controls-bottom { top: 60px !important; bottom: auto !important; } .mobile-topbar-header-sign-in-button { display: none !important; } `; document.head.appendChild(style); } function blockEvents() { const eventsToBlock = ['click', 'touchstart', 'touchend']; eventsToBlock.forEach(eventType => { document.addEventListener(eventType, function(event) { if (!isBlockingEnabled) return; const allowedSelectors = [ '.ytp-chrome-bottom', '#customButtonContainer', '.ytp-progress-bar-container', '.ytp-chrome-top', '.ytp-play-button', '.ytp-pause-button', '.ytp-volume-slider', '.ytp-volume-button', '.ytp-time-current', '.ytp-time-duration', '.ytp-progress-bar' // Sicherstellen, dass die gesamte Fortschrittsleiste erlaubt ist ]; if (allowedSelectors.some(selector => event.target.closest(selector))) { return; } event.preventDefault(); event.stopPropagation(); }, { capture: true, passive: false }); }); } function moveControlsToTop() { const style = document.createElement('style'); style.textContent = ` .ytp-chrome-bottom { top: 60px !important; bottom: auto !important; } .ytp-progress-bar-container { top: -6px !important; bottom: auto !important; } .ytp-gradient-bottom { top: 0 !important; bottom: auto !important; background: linear-gradient(to bottom, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0) 100%) !important; } .ytp-preview, .ytp-tooltip { top: -37px !important; bottom: auto !important; transform: translateY(100%) !important; } .ytp-big-mode .ytp-tooltip { top: -96px !important; } .ytp-tooltip-edu { display: none !important; } `; document.head.appendChild(style); } function enableTimelineClick() { if (!isMobileYouTube()) return; const observer = new MutationObserver((mutations) => { const timeline = document.querySelector('.ytp-progress-bar'); if (timeline) { // Entferne bestehende Event-Listener, um doppelte Listener zu vermeiden timeline.replaceWith(timeline.cloneNode(true)); const newTimeline = document.querySelector('.ytp-progress-bar'); function seekVideo(event) { event.preventDefault(); event.stopPropagation(); const video = document.querySelector('video'); if (video) { const rect = newTimeline.getBoundingClientRect(); const clientX = event.clientX || (event.touches && event.touches[0].clientX); if (clientX === undefined) return; const clickPosition = (clientX - rect.left) / rect.width; video.currentTime = clickPosition * video.duration; } } newTimeline.addEventListener('click', seekVideo, { passive: false }); newTimeline.addEventListener('touchstart', seekVideo, { passive: false }); newTimeline.addEventListener('mousedown', seekVideo, { passive: false }); observer.disconnect(); // Stoppe den Observer nach dem Hinzufügen der Listener } }); observer.observe(document.body, { childList: true, subtree: true }); } function isInCinemaMode() { return document.fullscreenElement !== null; } function enableCinemaMode() { let timeoutId; function checkAndEnableCinemaMode() { if (!isInCinemaMode()) { const cinemaButton = document.querySelector('.ytp-size-button'); if (cinemaButton) { cinemaButton.click(); console.log('Kinomodus aktiviert'); // Überprüfe, ob die Aktivierung erfolgreich war setTimeout(() => { if (isInCinemaMode()) { if (timeoutId) { clearTimeout(timeoutId); } console.log('Kinomodus erfolgreich aktiviert, Timeout gelöscht'); } else { console.warn('Kinomodus konnte nicht aktiviert werden'); } }, 500); } } else { if (timeoutId) { clearTimeout(timeoutId); } console.log('Bereits im Kinomodus, Timeout gelöscht'); } } // Prüfe sofort checkAndEnableCinemaMode(); // Setze einen Timeout für eine erneute Prüfung, falls die Seite noch lädt timeoutId = setTimeout(checkAndEnableCinemaMode, 2000); // Prüfe bei Navigationsereignissen (für Single-Page-Apps) window.addEventListener('yt-navigate-finish', checkAndEnableCinemaMode); } function adjustLayout() { const videoPlayer = document.querySelector('.html5-video-player'); if (videoPlayer) { videoPlayer.style.width = '100%'; videoPlayer.style.height = '100%'; console.log("Layout angepasst"); } } function setupResizeHandler() { let resizeTimer; window.addEventListener('resize', () => { clearTimeout(resizeTimer); resizeTimer = setTimeout(adjustLayout, 350); }); } function initializeLayout() { adjustLayout(); enableCinemaMode(); } function applyCustomCSS() { const style = document.createElement('style'); style.textContent = ` /* Kinomodus Anpassungen */ .html5-video-player { background-color: black !important; } /* Anpassung der Button-Größe für bessere Bedienbarkeit */ #customButtonContainer button { font-size: 16px; padding: 10px 14px; } /* Stil für aktiven Block-Button */ #customButton_block.active { background-color: rgb(255, 255, 255) !important; } /* Weitere kosmetische Änderungen */ body { overflow: hidden !important; } `; document.head.appendChild(style); } function blockUnwantedClicks() { document.addEventListener('click', function(event) { if (!isBlockingEnabled) return; const allowedSelectors = [ '.ytp-chrome-bottom', '#customButtonContainer', '.ytp-progress-bar-container', '.ytp-chrome-top', '.ytp-play-button', '.ytp-pause-button', '.ytp-volume-slider', '.ytp-volume-button', '.ytp-time-current', '.ytp-time-duration', '.ytp-progress-bar' // Sicherstellen, dass die gesamte Fortschrittsleiste erlaubt ist ]; if (allowedSelectors.some(selector => event.target.closest(selector))) { return; } event.preventDefault(); event.stopPropagation(); }, true); } async function init() { try { // Warte auf den Videoplayer //await waitForElement('.html5-video-player'); addButtonsToPage(); applyMobileCSSChanges(); applyCustomCSS(); blockEvents(); blockUnwantedClicks(); if (isMobileYouTube()) { enableTimelineClick(); } initializeLayout(); moveControlsToTop(); setupResizeHandler(); console.log("YouTube Enhancer erfolgreich aktiviert"); } catch (error) { console.error("YouTube Enhancer Fehler:", error); } } // Warte, bis das DOM vollständig geladen ist if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } - Assistant