mirror of
https://github.com/goodtube4u/goodtube.git
synced 2025-11-22 10:16:11 +00:00
Fallback fixes, URL fixes for live videos
This commit is contained in:
103
goodtube.js
103
goodtube.js
@@ -27,6 +27,25 @@
|
||||
getParams[decode(arguments[1])] = decode(arguments[2]);
|
||||
});
|
||||
|
||||
// For some users, the URL will contain the video ID as part of the URL
|
||||
// Example - "/watch/xxxx" or "/live/xxxx"
|
||||
// In this case, we want to add it manually as "v" (just like for /watch?v=xxxx)
|
||||
if (goodTube_helper_watchingVideo() && typeof getParams['v'] === 'undefined') {
|
||||
let splitString = '';
|
||||
if (window.location.href.indexOf('/watch') !== -1) {
|
||||
splitString = '/watch';
|
||||
}
|
||||
else {
|
||||
splitString = '/live';
|
||||
}
|
||||
|
||||
let bits = window.location.href.split(splitString);
|
||||
if (bits.length === 2) {
|
||||
let endBits = bits[1].split('?');
|
||||
getParams['v'] = endBits[endBits.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
return getParams;
|
||||
}
|
||||
|
||||
@@ -123,6 +142,18 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we're watching a video
|
||||
function goodTube_helper_watchingVideo() {
|
||||
// If the URL contains "/watch" or "/live", we're viewing a video
|
||||
if (window.location.href.indexOf('/watch') !== -1 || window.location.href.indexOf('/live') !== -1) {
|
||||
return true;
|
||||
}
|
||||
// Otherwise, we're not viewing a video
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Global variables
|
||||
------------------------------------------------------------------------------------------ */
|
||||
@@ -495,7 +526,7 @@
|
||||
if (
|
||||
(goodTube_shorts === 'true' && window.location.href.indexOf('/shorts') !== -1)
|
||||
||
|
||||
window.location.href.indexOf('/watch?') === -1
|
||||
!goodTube_helper_watchingVideo()
|
||||
) {
|
||||
// Clear timeout first to solve memory leak issues
|
||||
clearTimeout(goodTube_youtube_pauseMuteVideos_timeout);
|
||||
@@ -591,7 +622,7 @@
|
||||
let goodTube_youtube_checkAdsState_timeout = setTimeout(() => {}, 0);
|
||||
function goodTube_youtube_checkAdsState() {
|
||||
// If we're viewing a video
|
||||
if (window.location.href.indexOf('/watch?') !== -1) {
|
||||
if (goodTube_helper_watchingVideo()) {
|
||||
// Get the ads DOM elements
|
||||
let adsElement = document.querySelector('.video-ads');
|
||||
let sponsoredAdsElement = document.querySelector('.ad-simple-attributed-string');
|
||||
@@ -700,7 +731,7 @@
|
||||
let goodTube_clearedPlayer = false;
|
||||
function goodTube_player_positionAndSize() {
|
||||
// If we're viewing a video
|
||||
if (window.location.href.indexOf('/watch?') !== -1) {
|
||||
if (goodTube_helper_watchingVideo()) {
|
||||
// If the "hide and mute ads" fallback is inactive
|
||||
if (goodTube_fallback) {
|
||||
if (!goodTube_clearedPlayer) {
|
||||
@@ -815,7 +846,7 @@
|
||||
// If we're loading for the first time
|
||||
if (goodTube_firstLoad) {
|
||||
// If we're not viewing a video
|
||||
if (window.location.href.indexOf('/watch?') === -1) {
|
||||
if (!goodTube_helper_watchingVideo()) {
|
||||
// Clear and hide the player
|
||||
goodTube_player_clear();
|
||||
}
|
||||
@@ -867,7 +898,7 @@
|
||||
}
|
||||
|
||||
// Make sure we're watching a video
|
||||
if (window.location.href.indexOf('/watch?') === -1) {
|
||||
if (!goodTube_helper_watchingVideo()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1147,7 +1178,7 @@
|
||||
let keyPressed = event.key.toLowerCase();
|
||||
|
||||
// Don't do anything IF we're holding control OR alt OR the command key (mac) OR we're not watching a video
|
||||
if (event.ctrlKey || event.altKey || event.metaKey || window.location.href.indexOf('/watch?') === -1) {
|
||||
if (event.ctrlKey || event.altKey || event.metaKey || !goodTube_helper_watchingVideo()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1555,7 +1586,7 @@
|
||||
}
|
||||
|
||||
// Sync main player (only if we're viewing a video page AND the "hide and mute ads" fallback is inactive)
|
||||
else if (event.data.indexOf('goodTube_syncMainPlayer_') !== -1 && window.location.href.indexOf('/watch?') !== -1 && !goodTube_fallback) {
|
||||
else if (event.data.indexOf('goodTube_syncMainPlayer_') !== -1 && goodTube_helper_watchingVideo() && !goodTube_fallback) {
|
||||
// Parse the data
|
||||
let syncTime = parseFloat(event.data.replace('goodTube_syncMainPlayer_', ''));
|
||||
|
||||
@@ -1670,7 +1701,7 @@
|
||||
goodTube_getParams = goodTube_helper_setupGetParams();
|
||||
|
||||
// If we're viewing a video
|
||||
if (window.location.href.indexOf('/watch?') !== -1) {
|
||||
if (goodTube_helper_watchingVideo()) {
|
||||
// Load the video
|
||||
goodTube_player_load();
|
||||
|
||||
@@ -1688,7 +1719,7 @@
|
||||
}
|
||||
|
||||
// If we're viewing a video
|
||||
if (window.location.href.indexOf('/watch?') !== -1) {
|
||||
if (goodTube_helper_watchingVideo()) {
|
||||
// Show or hide the end screen (based on autoplay, not the setting)
|
||||
goodTube_nav_showHideEndScreen();
|
||||
|
||||
@@ -2488,7 +2519,7 @@
|
||||
// Disable some shortcuts while the overlay is enabled
|
||||
function disableShortcuts(event) {
|
||||
// Make sure we're watching a video and the overlay state is disabled
|
||||
if (window.location.href.indexOf('/watch?') === -1 || goodTube_hideAndMuteAds_state !== 'enabled') {
|
||||
if (!goodTube_helper_watchingVideo() || goodTube_hideAndMuteAds_state !== 'enabled') {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2548,7 +2579,7 @@
|
||||
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 && window.location.href.indexOf('/watch?') !== -1) {
|
||||
if (goodTube_fallback && goodTube_helper_watchingVideo()) {
|
||||
// If ads are showing
|
||||
if (goodTube_adsShowing) {
|
||||
// Enable the "hide and mute ads" overlay
|
||||
@@ -2560,6 +2591,10 @@
|
||||
goodTube_hideAndMuteAdsFallback_disable();
|
||||
}
|
||||
}
|
||||
// Otherwise reset the "hide and mute ads" state
|
||||
else {
|
||||
goodTube_hideAndMuteAds_state = '';
|
||||
}
|
||||
|
||||
// Clear timeout first to solve memory leak issues
|
||||
clearTimeout(goodTube_hideAndMuteAdsFallback_check_timeout);
|
||||
@@ -2578,7 +2613,7 @@
|
||||
}
|
||||
|
||||
// Get the Youtube video element
|
||||
let videoElement = document.querySelector('#player video');
|
||||
let videoElement = document.querySelector('#movie_player video');
|
||||
|
||||
// If we found the video element
|
||||
if (videoElement) {
|
||||
@@ -2636,7 +2671,7 @@
|
||||
}
|
||||
|
||||
// Play the video (this solves an edge case)
|
||||
goodTube_hideAndMuteAdsFallback_play();
|
||||
goodTube_hideAndMuteAdsFallback_play(true);
|
||||
|
||||
// Make sure we only do this once
|
||||
goodTube_hideAndMuteAds_state = 'enabled';
|
||||
@@ -2650,23 +2685,23 @@
|
||||
}
|
||||
|
||||
// Get the Youtube video element
|
||||
let videoElement = document.querySelector('#player video');
|
||||
let videoElement = document.querySelector('#movie_player video');
|
||||
|
||||
// If we found the video element
|
||||
if (videoElement) {
|
||||
// Restore the playback speed
|
||||
videoElement.playbackRate = goodTube_playbackSpeed;
|
||||
|
||||
// Restore the volume (only if muted, otherwise leave it alone)
|
||||
if (videoElement.volume <= 0 || videoElement.muted) {
|
||||
videoElement.muted = false;
|
||||
videoElement.volume = 1;
|
||||
// Get the page API
|
||||
goodTube_page_api = document.getElementById('movie_player');
|
||||
|
||||
// Get the page API
|
||||
goodTube_page_api = document.getElementById('movie_player');
|
||||
// Make sure we have access to the functions we need
|
||||
if (goodTube_page_api && typeof goodTube_page_api.unMute === 'function' && typeof goodTube_page_api.setVolume === 'function' && typeof goodTube_page_api.getVolume === 'function') {
|
||||
// Restore the volume (only if muted, otherwise leave it alone)
|
||||
if (videoElement.volume <= 0 || videoElement.muted || goodTube_page_api.getVolume() === 0) {
|
||||
videoElement.muted = false;
|
||||
videoElement.volume = 1;
|
||||
|
||||
// Make sure we have access to the functions we need
|
||||
if (goodTube_page_api && typeof goodTube_page_api.unMute === 'function' && typeof goodTube_page_api.setVolume === 'function') {
|
||||
// Unmute and set the volume via the API (this is required, doing it via the <video> element alone won't work)
|
||||
goodTube_page_api.unMute();
|
||||
goodTube_page_api.setVolume(100);
|
||||
@@ -2765,9 +2800,9 @@
|
||||
|
||||
// Play video
|
||||
let goodTube_hideAndMuteAdsFallback_play_timeout = setTimeout(() => {}, 0);
|
||||
function goodTube_hideAndMuteAdsFallback_play() {
|
||||
function goodTube_hideAndMuteAdsFallback_play(mute = false) {
|
||||
// Make sure that the "hide and mute ads" fallback is active AND we're viewing a video
|
||||
if (!goodTube_fallback || window.location.href.indexOf('/watch?') === -1) {
|
||||
if (!goodTube_fallback || !goodTube_helper_watchingVideo()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2775,15 +2810,27 @@
|
||||
goodTube_page_api = document.getElementById('movie_player');
|
||||
|
||||
// Make sure we have what we need from the API
|
||||
if (goodTube_page_api && typeof goodTube_page_api.playVideo === 'function') {
|
||||
if (goodTube_page_api && typeof goodTube_page_api.playVideo === 'function' && typeof goodTube_page_api.mute === 'function' && typeof goodTube_page_api.setVolume === 'function') {
|
||||
// Get the video element
|
||||
let videoElement = document.querySelector('#movie_player video');
|
||||
|
||||
// Play the video
|
||||
goodTube_page_api.playVideo();
|
||||
|
||||
// Get the video element
|
||||
let videoElement = document.querySelector('#player video');
|
||||
if (mute) {
|
||||
// Mute the video via the page API (playing it re-enables audio)
|
||||
goodTube_page_api.mute();
|
||||
goodTube_page_api.setVolume(0);
|
||||
}
|
||||
|
||||
// If we found it
|
||||
if (videoElement) {
|
||||
if (mute) {
|
||||
// Mute the video via HTML (playing it re-enables audio)
|
||||
videoElement.muted = true;
|
||||
videoElement.volume = 0;
|
||||
}
|
||||
|
||||
// Save the starting video time
|
||||
let startingVideoTime = videoElement.currentTime;
|
||||
|
||||
@@ -3277,7 +3324,7 @@
|
||||
let goodTube_iframe_addCustomEvents_timeout = setTimeout(() => {}, 0);
|
||||
function goodTube_iframe_addCustomEvents() {
|
||||
// Target the video element
|
||||
let videoElement = document.querySelector('#player video');
|
||||
let videoElement = document.querySelector('#movie_player video');
|
||||
|
||||
// Make sure it exists before continuing
|
||||
if (!videoElement) {
|
||||
|
||||
Reference in New Issue
Block a user