mirror of
https://github.com/goodtube4u/goodtube.git
synced 2025-11-22 10:16:11 +00:00
More optimisation
This commit is contained in:
127
goodtube.js
127
goodtube.js
@@ -547,7 +547,6 @@
|
||||
}
|
||||
|
||||
// Turn off autoplay
|
||||
let goodTube_youtube_turnOffAutoplay_timeout = setTimeout(() => {}, 0);
|
||||
function goodTube_youtube_turnOffAutoplay() {
|
||||
// If we've already turned off autoplay, just return
|
||||
if (goodTube_turnedOffAutoplay) {
|
||||
@@ -567,14 +566,6 @@
|
||||
// Set a variable if autoplay has been turned off
|
||||
goodTube_turnedOffAutoplay = true;
|
||||
}
|
||||
|
||||
// Keep doing this, Youtube is causing autoplay issues lately...it doesn't want to stay off?
|
||||
|
||||
// Clear timeout first to solve memory leak issues
|
||||
clearTimeout(goodTube_youtube_turnOffAutoplay_timeout);
|
||||
|
||||
// Run actions again in 100ms to loop this function
|
||||
goodTube_youtube_turnOffAutoplay_timeout = setTimeout(goodTube_youtube_turnOffAutoplay, 100);
|
||||
}
|
||||
|
||||
// Remove the "are you still watching" popup
|
||||
@@ -704,57 +695,44 @@
|
||||
goodTube_playerWrapper = document.querySelector('#goodTube_playerWrapper');
|
||||
goodTube_player = goodTube_playerWrapper.querySelector('iframe');
|
||||
|
||||
// Setup player dynamic positioning and sizing
|
||||
goodTube_player_positionAndSize();
|
||||
|
||||
// Run the actions
|
||||
goodTube_actions();
|
||||
// Run the actions every 100ms
|
||||
setInterval(goodTube_actions, 100);
|
||||
}
|
||||
|
||||
// Position and size the player
|
||||
let goodTube_player_positionAndSize_timeout = setTimeout(() => {}, 0);
|
||||
let goodTube_clearedPlayer = false;
|
||||
function goodTube_player_positionAndSize() {
|
||||
// If we're viewing a video
|
||||
if (goodTube_helper_watchingVideo()) {
|
||||
// If the "hide and mute ads" fallback is inactive
|
||||
if (goodTube_fallback) {
|
||||
if (!goodTube_clearedPlayer) {
|
||||
// Hide and clear the embedded player
|
||||
goodTube_player_clear(true);
|
||||
goodTube_clearedPlayer = true;
|
||||
}
|
||||
}
|
||||
// Otherwise, the "hide and mute ads" fallback is inactive
|
||||
else {
|
||||
goodTube_clearedPlayer = false;
|
||||
|
||||
// Show the GoodTube player
|
||||
goodTube_helper_showElement(goodTube_playerWrapper);
|
||||
|
||||
// Get the Youtube player
|
||||
let youtubePlayer = document.querySelector('#ytd-player, .player-size');
|
||||
|
||||
// If we found the Youtube player
|
||||
if (youtubePlayer && youtubePlayer.offsetHeight > 0) {
|
||||
// Make our custom player match the position of the Youtube player
|
||||
// Note: Our custom player uses "position: absolute" so take into account the window scroll
|
||||
let rect = youtubePlayer.getBoundingClientRect();
|
||||
goodTube_playerWrapper.style.top = (rect.top + window.scrollY) + 'px';
|
||||
goodTube_playerWrapper.style.left = (rect.left + window.scrollX) + 'px';
|
||||
|
||||
// Make our custom player match the size of the Youtube player
|
||||
goodTube_playerWrapper.style.width = youtubePlayer.offsetWidth + 'px';
|
||||
goodTube_playerWrapper.style.height = youtubePlayer.offsetHeight + 'px';
|
||||
}
|
||||
// If the "hide and mute ads" fallback is inactive
|
||||
if (goodTube_fallback) {
|
||||
if (!goodTube_clearedPlayer) {
|
||||
// Hide and clear the embedded player
|
||||
goodTube_player_clear(true);
|
||||
goodTube_clearedPlayer = true;
|
||||
}
|
||||
}
|
||||
// Otherwise, the "hide and mute ads" fallback is inactive
|
||||
else {
|
||||
goodTube_clearedPlayer = false;
|
||||
|
||||
// Clear timeout first to solve memory leak issues
|
||||
clearTimeout(goodTube_player_positionAndSize_timeout);
|
||||
// Show the GoodTube player
|
||||
goodTube_helper_showElement(goodTube_playerWrapper);
|
||||
|
||||
// Create a new timeout
|
||||
goodTube_player_positionAndSize_timeout = setTimeout(goodTube_player_positionAndSize, 100);
|
||||
// Get the Youtube player
|
||||
let youtubePlayer = document.querySelector('#ytd-player, .player-size');
|
||||
|
||||
// If we found the Youtube player
|
||||
if (youtubePlayer && youtubePlayer.offsetHeight > 0) {
|
||||
// Make our custom player match the position of the Youtube player
|
||||
// Note: Our custom player uses "position: absolute" so take into account the window scroll
|
||||
let rect = youtubePlayer.getBoundingClientRect();
|
||||
goodTube_playerWrapper.style.top = (rect.top + window.scrollY) + 'px';
|
||||
goodTube_playerWrapper.style.left = (rect.left + window.scrollX) + 'px';
|
||||
|
||||
// Make our custom player match the size of the Youtube player
|
||||
goodTube_playerWrapper.style.width = youtubePlayer.offsetWidth + 'px';
|
||||
goodTube_playerWrapper.style.height = youtubePlayer.offsetHeight + 'px';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Populate the playlist info
|
||||
@@ -859,10 +837,6 @@
|
||||
goodTube_player_syncStartingTime();
|
||||
}
|
||||
|
||||
// Set the Youtube player to auto quality
|
||||
goodTube_player_setQualitySucceeded = false;
|
||||
goodTube_player_setAutoQuality();
|
||||
|
||||
// Show the player
|
||||
goodTube_helper_showElement(goodTube_playerWrapper);
|
||||
|
||||
@@ -870,15 +844,6 @@
|
||||
goodTube_player_play();
|
||||
}
|
||||
|
||||
// Set the Youtube player quality
|
||||
let goodTube_player_setQualitySucceeded = false;
|
||||
let goodTube_player_setQuality_timeout = setTimeout(() => {}, 0);
|
||||
function goodTube_player_setAutoQuality(quality = 'highest') {
|
||||
// DISABLE FOR NOW THIS IS CAUSING ISSUES
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// Sync the starting time
|
||||
let goodTube_player_syncStartingTime_timeout = setTimeout(() => {}, 0);
|
||||
function goodTube_player_syncStartingTime() {
|
||||
@@ -1563,7 +1528,6 @@
|
||||
}
|
||||
|
||||
// Actions
|
||||
let goodTube_actions_timeout = setTimeout(() => {}, 0);
|
||||
function goodTube_actions() {
|
||||
// Get the previous and current URL
|
||||
|
||||
@@ -1622,16 +1586,16 @@
|
||||
|
||||
// Remove the "are you still watching" popup
|
||||
goodTube_youtube_removeAreYouStillWatchingPopup();
|
||||
|
||||
// Position and size the player
|
||||
goodTube_player_positionAndSize();
|
||||
|
||||
// Check to enable or disable the "hide and mute ads" fallback overlay
|
||||
goodTube_hideAndMuteAdsFallback_check();
|
||||
}
|
||||
|
||||
// Hide shorts (real time)
|
||||
goodTube_youtube_hideShortsRealTime();
|
||||
|
||||
// Clear timeout first to solve memory leak issues
|
||||
clearTimeout(goodTube_actions_timeout);
|
||||
|
||||
// Run actions again in 100ms to loop this function
|
||||
goodTube_actions_timeout = setTimeout(goodTube_actions, 100);
|
||||
}
|
||||
|
||||
// Init menu
|
||||
@@ -2441,9 +2405,6 @@
|
||||
style.textContent = cssOutput;
|
||||
document.head.appendChild(style);
|
||||
|
||||
// Check to enable or disable the overlay
|
||||
goodTube_hideAndMuteAdsFallback_check();
|
||||
|
||||
// Disable some shortcuts while the overlay is enabled
|
||||
function disableShortcuts(event) {
|
||||
// Make sure we're watching a video and the overlay state is disabled
|
||||
@@ -2504,7 +2465,6 @@
|
||||
}
|
||||
|
||||
// Check to enable or disable the overlay
|
||||
let goodTube_hideAndMuteAdsFallback_check_timeout = setTimeout(() => {}, 0);
|
||||
function goodTube_hideAndMuteAdsFallback_check() {
|
||||
// If the "hide and mute ads" fallback is active AND we're viewing a video
|
||||
if (goodTube_fallback && goodTube_helper_watchingVideo()) {
|
||||
@@ -2523,12 +2483,6 @@
|
||||
else {
|
||||
goodTube_hideAndMuteAds_state = '';
|
||||
}
|
||||
|
||||
// Clear timeout first to solve memory leak issues
|
||||
clearTimeout(goodTube_hideAndMuteAdsFallback_check_timeout);
|
||||
|
||||
// Run actions again in 1ms to loop this function
|
||||
goodTube_hideAndMuteAdsFallback_check_timeout = setTimeout(goodTube_hideAndMuteAdsFallback_check, 100);
|
||||
}
|
||||
|
||||
// Enable the the overlay
|
||||
@@ -2862,15 +2816,14 @@
|
||||
// Restore playback speed, and update it if it changes
|
||||
goodTube_iframe_playbackSpeed();
|
||||
|
||||
// Run the iframe actions
|
||||
goodTube_iframe_actions();
|
||||
// Run the iframe actions every 100ms
|
||||
setInterval(goodTube_iframe_actions, 100);
|
||||
|
||||
// Let the parent frame know it's loaded
|
||||
window.top.postMessage('goodTube_playerIframe_loaded', '*');
|
||||
}
|
||||
|
||||
// Actions
|
||||
let goodTube_iframe_actions_timeout = setTimeout(() => {}, 0);
|
||||
function goodTube_iframe_actions() {
|
||||
// Check to see if the "hide and mute ads" fallback should be active
|
||||
goodTube_iframe_hideMuteAdsFallback();
|
||||
@@ -2891,12 +2844,6 @@
|
||||
|
||||
// Sync the aspect ratio
|
||||
goodTube_iframe_syncAspectRatio();
|
||||
|
||||
// Clear timeout first to solve memory leak issues
|
||||
clearTimeout(goodTube_iframe_actions_timeout);
|
||||
|
||||
// Create a new timeout
|
||||
goodTube_iframe_actions_timeout = setTimeout(goodTube_iframe_actions, 100);
|
||||
}
|
||||
|
||||
// Check to see if the "hide and mute ads" fallback should be active
|
||||
|
||||
Reference in New Issue
Block a user