diff --git a/goodtube.js b/goodtube.js index 70c0317..6bd381d 100644 --- a/goodtube.js +++ b/goodtube.js @@ -366,6 +366,12 @@ // Debug message console.log('[GoodTube] Ads removed'); + // Hide the main Youtube player + cssOutput += ` + body:not('.goodTube_fallback) ytd-player { + visibility: hidden !important; + } + `; // Hide the miniplayer cssOutput += ` @@ -375,7 +381,6 @@ } `; - // Hide shorts if they're not enabled if (goodTube_shorts === 'false') { cssOutput += ` @@ -442,8 +447,7 @@ } // Hide shorts (real time) - let goodTube_youtube_hideShortsRealtime_timeout = setTimeout(() => {}, 0); - function goodTube_youtube_hideShortsRealtime() { + function goodTube_youtube_hideShortsRealTime() { // If shorts are enabled, don't do anything if (goodTube_shorts === 'true') { return; @@ -476,12 +480,6 @@ // Mark this element as checked to save on resources element.classList.add('goodTube_checked'); }); - - // Clear timeout first to solve memory leak issues - clearTimeout(goodTube_youtube_hideShortsRealtime_timeout); - - // Loop this function - goodTube_youtube_hideShortsRealtime_timeout = setTimeout(goodTube_youtube_hideShortsRealtime, 100); } // Support timestamp links in comments @@ -513,45 +511,6 @@ }); } - // Hide all Youtube players - let goodTube_youtube_hidePlayers_timeout = setTimeout(() => {}, 0); - function goodTube_youtube_hidePlayers() { - // Don't do this if shorts are enabled and we're viewing a short - if (goodTube_shorts === 'true' && window.location.href.indexOf('/shorts') !== -1) { - // Clear timeout first to solve memory leak issues - clearTimeout(goodTube_youtube_hidePlayers_timeout); - - // Loop this function - goodTube_youtube_hidePlayers_timeout = setTimeout(goodTube_youtube_hidePlayers, 100); - - // Don't hide the players - return; - } - - // Target the Youtube player - let youtubePlayer = document.getElementById('ytd-player'); - - // If we found the Youtube player - if (youtubePlayer) { - // If the "hide and mute ads" fallback is active - if (goodTube_fallback) { - // Show the Youtube player - youtubePlayer.style.visibility = 'visible'; - } - // Otherwise we're using the regular method - else { - // Hide the Youtube player - youtubePlayer.style.visibility = 'hidden'; - } - } - - // Clear timeout first to solve memory leak issues - clearTimeout(goodTube_youtube_hidePlayers_timeout); - - // Loop this function - goodTube_youtube_hidePlayers_timeout = setTimeout(goodTube_youtube_hidePlayers, 100); - } - // Mute and pause all Youtube videos let goodTube_youtube_pauseMuteVideos_timeout = setTimeout(() => {}, 0); function goodTube_youtube_pauseMuteVideos() { @@ -1414,15 +1373,9 @@ // Add CSS classes to hide elements (without Youtube knowing) goodTube_helper_showHide_init(); - // Hide the youtube players - goodTube_youtube_hidePlayers(); - // Hide page elements goodTube_youtube_hidePageElements(); - // Hide shorts (real time) - goodTube_youtube_hideShortsRealtime(); - // Init our player goodTube_player_init(); @@ -1572,6 +1525,11 @@ else if (event.data === 'goodTube_fallback_enable') { goodTube_fallback = true; + // Add a class to the + if (document.body && !document.body.classList.contains('goodTube_fallback')) { + document.body.classList.add('goodTube_fallback'); + } + // Unset the aspect ratio goodTube_youtube_unsetAspectRatio(); @@ -1600,6 +1558,11 @@ else if (event.data === 'goodTube_fallback_disable') { goodTube_fallback = false; + // Remove the class from the + if (document.body && !document.body.classList.contains('goodTube_fallback')) { + document.body.classList.add('goodTube_fallback'); + } + // If we're in fullscreen already if (document.fullscreenElement) { // Exit fullscreen @@ -1681,6 +1644,9 @@ goodTube_youtube_removeAreYouStillWatchingPopup(); } + // Hide shorts (real time) + goodTube_youtube_hideShortsRealTime(); + // Clear timeout first to solve memory leak issues clearTimeout(goodTube_actions_timeout);