From bd407502c8bfb766f64930ab21410c4e21fa2f5a Mon Sep 17 00:00:00 2001 From: goodtube4u Date: Tue, 9 Jul 2024 17:08:03 +1000 Subject: [PATCH] Mobile fixes --- goodtube.user.js | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/goodtube.user.js b/goodtube.user.js index 1cc00f6..6d2bf41 100644 --- a/goodtube.user.js +++ b/goodtube.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name GoodTube // @namespace http://tampermonkey.net/ -// @version 4.514 +// @version 4.518 // @description Loads Youtube videos from different sources. Also removes ads, shorts, etc. // @author GoodTube // @match https://*.youtube.com/* @@ -1197,36 +1197,38 @@ youtubePageElement.appendChild(player_wrapper1); setInterval(function() { - if (typeof goodTube_getParams['v'] !== 'undefined') { - // Match width and height of mobile player - let youtubeSize_element = document.querySelector('.player-size.player-placeholder'); - if (youtubeSize_element) { - if (youtubeSize_element.offsetHeight > 0) { - player_wrapper1.style.height = youtubeSize_element.offsetHeight+'px'; - player_wrapper1.style.width = youtubeSize_element.offsetWidth+'px'; - } - else { - youtubeSize_element = document.querySelector('#player'); + window.requestAnimationFrame(function() { + if (typeof goodTube_getParams['v'] !== 'undefined') { + // Match width and height of mobile player + let youtubeSize_element = document.querySelector('.player-size.player-placeholder'); + if (youtubeSize_element) { if (youtubeSize_element.offsetHeight > 0) { player_wrapper1.style.height = youtubeSize_element.offsetHeight+'px'; player_wrapper1.style.width = youtubeSize_element.offsetWidth+'px'; } + else { + youtubeSize_element = document.querySelector('#player'); + if (youtubeSize_element.offsetHeight > 0) { + player_wrapper1.style.height = youtubeSize_element.offsetHeight+'px'; + player_wrapper1.style.width = youtubeSize_element.offsetWidth+'px'; + } + } + } + + // Match sticky mode of mobile player + let youtubeSticky_element = document.querySelector('.player-container.sticky-player'); + if (youtubeSticky_element) { + player_wrapper1.style.position = 'fixed'; + } + else { + player_wrapper1.style.position = 'absolute'; } } - - // Match sticky mode of mobile player - let youtubeSticky_element = document.querySelector('.player-container.sticky-player'); - if (youtubeSticky_element) { - player_wrapper1.style.position = 'fixed'; - } else { - player_wrapper1.style.position = 'absolute'; + player_wrapper1.style.height = '0'; + player_wrapper1.style.width = '0'; } - } - else { - player_wrapper1.style.height = '0'; - player_wrapper1.style.width = '0'; - } + }); }, 1); }