mirror of
https://github.com/goodtube4u/goodtube.git
synced 2025-11-22 10:16:11 +00:00
Test
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @name GoodTube Testing
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 1.002
|
||||
// @version 1.003
|
||||
// @description A testing ground for GoodTube.
|
||||
// @author GoodTube - Embed
|
||||
// @match *://m.youtube.com/*
|
||||
@@ -401,6 +401,7 @@
|
||||
/* Player functions
|
||||
------------------------------------------------------------------------------------------ */
|
||||
// Init player
|
||||
let goodTube_proxyIframeLoaded = false;
|
||||
function goodTube_player_init() {
|
||||
// Get the page API
|
||||
goodTube_page_api = document.getElementById('movie_player');
|
||||
@@ -482,6 +483,11 @@
|
||||
goodTube_playerWrapper = document.querySelector('#goodTube_playerWrapper');
|
||||
goodTube_player = goodTube_playerWrapper.querySelector('iframe');
|
||||
|
||||
// Expose when the proxy iframe has loaded
|
||||
goodTube_player.addEventListener('load', function () {
|
||||
goodTube_proxyIframeLoaded = true;
|
||||
});
|
||||
|
||||
// Setup player dynamic positioning and sizing
|
||||
goodTube_player_positionAndSize();
|
||||
|
||||
@@ -490,6 +496,7 @@
|
||||
}
|
||||
|
||||
// Position and size the player
|
||||
let goodTube_loadTimeout = setTimeout(() => {}, 0);
|
||||
function goodTube_player_positionAndSize() {
|
||||
// If we're viewing a video
|
||||
if (window.location.href.indexOf('.com/watch') !== -1) {
|
||||
@@ -556,58 +563,98 @@
|
||||
}
|
||||
|
||||
// Load a video
|
||||
let goodTube_player_firstLoad = true;
|
||||
function goodTube_player_load() {
|
||||
// Debug message
|
||||
console.log('[GoodTube] Loading video ' + goodTube_getParams['v'] + '...');
|
||||
|
||||
// Pause the video first (this helps to prevent audio flashes)
|
||||
goodTube_player_pause();
|
||||
|
||||
// On first load, or we're not in picture in picture (we fully refresh the iframe normally as this helps to stop audio flashes, temp fix as this is kinda sucky)
|
||||
// if (goodTube_player_firstLoad || !goodTube_pip) {
|
||||
if (goodTube_player_firstLoad) {
|
||||
// On iframe load
|
||||
goodTube_player.addEventListener('load', function () {
|
||||
// Set the video source (we need to use this weird method so it doesn't mess with browser history)
|
||||
// This also tells the embed if it's mobile or not
|
||||
let mobileText = 'false';
|
||||
if (goodTube_mobile) {
|
||||
mobileText = 'true';
|
||||
}
|
||||
|
||||
goodTube_player.contentWindow.postMessage('goodTube_src_https://www.youtube.com/embed/' + goodTube_getParams['v'] + '?autoplay=1&mobile=' + mobileText, '*');
|
||||
|
||||
// Ensure we're still viewing a video (sometimes you can browse to another page before the iframe loads)
|
||||
if (window.location.href.indexOf('.com/watch') !== -1) {
|
||||
// If a restore time exists, skip to it
|
||||
if (typeof goodTube_getParams['t'] !== 'undefined') {
|
||||
goodTube_player_skipTo(goodTube_getParams['t'].replace('s', ''));
|
||||
}
|
||||
|
||||
// Set autoplay initial state
|
||||
goodTube_player.contentWindow.postMessage('goodTube_autoplay_' + goodTube_autoplay, '*');
|
||||
}
|
||||
// If we're not still viewing a video
|
||||
else {
|
||||
// Clear and hide the player
|
||||
goodTube_player_clear();
|
||||
}
|
||||
});
|
||||
|
||||
// Turn first load off
|
||||
goodTube_player_firstLoad = false;
|
||||
// Make sure the proxy iframe has loaded
|
||||
if (!goodTube_proxyIframeLoaded) {
|
||||
clearTimeout(goodTube_loadTimeout);
|
||||
goodTube_loadTimeout = setTimeout(goodTube_player_load, 100);
|
||||
}
|
||||
// On other loads (picture in picture only currently)
|
||||
|
||||
// Ensure we're still viewing a video (sometimes you can browse to another page before the iframe loads)
|
||||
if (window.location.href.indexOf('.com/watch') !== -1) {
|
||||
// If a restore time exists, skip to it
|
||||
if (typeof goodTube_getParams['t'] !== 'undefined') {
|
||||
goodTube_player_skipTo(goodTube_getParams['t'].replace('s', ''));
|
||||
}
|
||||
|
||||
// Set autoplay initial state
|
||||
goodTube_player.contentWindow.postMessage('goodTube_autoplay_' + goodTube_autoplay, '*');
|
||||
}
|
||||
// If we're not still viewing a video
|
||||
else {
|
||||
// Load the video via the iframe api
|
||||
goodTube_player.contentWindow.postMessage('goodTube_load_' + goodTube_getParams['v'], '*');
|
||||
// Clear and hide the player
|
||||
goodTube_player_clear();
|
||||
}
|
||||
|
||||
// Set the video source (we need to use this weird method so it doesn't mess with browser history)
|
||||
// This also tells the embed if it's mobile or not
|
||||
let mobileText = 'false';
|
||||
if (goodTube_mobile) {
|
||||
mobileText = 'true';
|
||||
}
|
||||
goodTube_player.contentWindow.postMessage('goodTube_src_https://www.youtube.com/embed/' + goodTube_getParams['v'] + '?autoplay=1&mobile=' + mobileText, '*');
|
||||
|
||||
|
||||
// Show the player
|
||||
goodTube_helper_showElement(goodTube_playerWrapper);
|
||||
}
|
||||
|
||||
// // Load a video
|
||||
// let goodTube_player_firstLoad = true;
|
||||
// function goodTube_player_load() {
|
||||
// // Debug message
|
||||
// console.log('[GoodTube] Loading video ' + goodTube_getParams['v'] + '...');
|
||||
|
||||
// // Pause the video first (this helps to prevent audio flashes)
|
||||
// goodTube_player_pause();
|
||||
|
||||
// // On first load, or we're not in picture in picture (we fully refresh the iframe normally as this helps to stop audio flashes, temp fix as this is kinda sucky)
|
||||
// // if (goodTube_player_firstLoad || !goodTube_pip) {
|
||||
// if (goodTube_player_firstLoad) {
|
||||
// // On iframe load
|
||||
// goodTube_player.addEventListener('load', function () {
|
||||
// // Set the video source (we need to use this weird method so it doesn't mess with browser history)
|
||||
// // This also tells the embed if it's mobile or not
|
||||
// let mobileText = 'false';
|
||||
// if (goodTube_mobile) {
|
||||
// mobileText = 'true';
|
||||
// }
|
||||
|
||||
// goodTube_player.contentWindow.postMessage('goodTube_src_https://www.youtube.com/embed/' + goodTube_getParams['v'] + '?autoplay=1&mobile=' + mobileText, '*');
|
||||
|
||||
// // Ensure we're still viewing a video (sometimes you can browse to another page before the iframe loads)
|
||||
// if (window.location.href.indexOf('.com/watch') !== -1) {
|
||||
// // If a restore time exists, skip to it
|
||||
// if (typeof goodTube_getParams['t'] !== 'undefined') {
|
||||
// goodTube_player_skipTo(goodTube_getParams['t'].replace('s', ''));
|
||||
// }
|
||||
|
||||
// // Set autoplay initial state
|
||||
// goodTube_player.contentWindow.postMessage('goodTube_autoplay_' + goodTube_autoplay, '*');
|
||||
// }
|
||||
// // If we're not still viewing a video
|
||||
// else {
|
||||
// // Clear and hide the player
|
||||
// goodTube_player_clear();
|
||||
// }
|
||||
// });
|
||||
|
||||
// // Turn first load off
|
||||
// goodTube_player_firstLoad = false;
|
||||
// }
|
||||
// // On other loads (picture in picture only currently)
|
||||
// else {
|
||||
// // Load the video via the iframe api
|
||||
// goodTube_player.contentWindow.postMessage('goodTube_load_' + goodTube_getParams['v'], '*');
|
||||
// }
|
||||
|
||||
// // Show the player
|
||||
// goodTube_helper_showElement(goodTube_playerWrapper);
|
||||
// }
|
||||
|
||||
// Clear and hide the player
|
||||
function goodTube_player_clear() {
|
||||
// Stop the video via the iframe api (but not if we're in picture in picture)
|
||||
|
||||
Reference in New Issue
Block a user