function initializePlayer() {
		playerURL = new URL(document.location.href.toString()); // Grab current URL
		streamURL = getURLParam("streamURL"); // Get stream URL from player URL param

		// If there is a Twitch auth token saved from a previous session
		if (localStorage.getItem("rjp-twitchAuthToken") !== null) {
			twitchAuthToken = localStorage.getItem("rjp-twitchAuthToken"); // Get twitchAuthToken
		}

		// If an auth token was included with the URL update the stored one
		if (getURLHashParam("access_token") !== "") {
			twitchAuthToken = getURLHashParam("access_token"); // Get the access token

			// Store it for future requests
			localStorage.setItem("rjp-twitchAuthToken", twitchAuthToken);

			// Clear hashes
			window.history.pushState(null, null, window.location.pathname + window.location.search);
		}

		// If there is an error param from Twitch auth attempt
		if (getURLParam("error") !== "") {
			// If it was because the user denied access
			if (getURLParam("error_description") === "The user denied you access") {
				// Let them know
				alert("To find a random stream or use the followed streams list, please authorize Twitch access.");

				// If the afterAuthAction is "random"
				if (localStorage.getItem("rjp-afterAuthAction") === "random") {
					localStorage.removeItem("rjp-afterAuthAction"); // Remove that action
				}
			}
			// Else it may be because of an expired token
			else {
				// Clear token
				localStorage.removeItem("rjp-twitchAuthToken");

				// Send them to get an auth token
				redirectForTwitchAuthToken("stream");
			}
		}

		// If there is an action saved which needs to be performed
		if (localStorage.getItem("rjp-afterAuthAction") !== null) {
			// If the afterAuthAction is "random"
			if (localStorage.getItem("rjp-afterAuthAction") === "random") {
				document.getElementById("randomStreamButton").click(); // Click the random button again
			}
			// Assume it is a stream URL
			else {
				streamURL = localStorage.getItem("rjp-afterAuthAction"); // Set the streamURL to the saved afterAuthAction
			}
			localStorage.removeItem("rjp-afterAuthAction"); // Remove that action
		}

		// If stream URL param of the player URL is not blank
		if (streamURL != "") {
			streamURLElement.value = streamURL; // Set the stream URL input element to the stream URL
			document.title = `${documentTitle} - ${streamURL}`; // Update document title
			updateStreamFrame(); // Show the stream
			peekUI(); // Briefly show UI
		}
		// Else it is empty
		else {
			document.title = `${documentTitle}`; // Update document title

			// If this is a small screen
			if (window.innerWidth < 768) {
				setUIState("open"); // Open all UI

				// After 3000 seconds
				setTimeout(() => {
					setMenuElementState("close"); // Close menu
				}, 3000);
			}
			// Else is is large enough to open everything
			else {
				setUIState("open"); // Open all UI
			}
		}
	}
// Function for initializing the player based on a new URL
Function for initializing the player based on a new URL
Function for initializing the player based on a new URL
function initializePlayer() {
		playerURL = new URL(document.location.href.toString()); 
		streamURL = getURLParam("streamURL"); 
		if (localStorage.getItem("rjp-twitchAuthToken") !== null) {
			twitchAuthToken = localStorage.getItem("rjp-twitchAuthToken"); 
		}
		if (getURLHashParam("access_token") !== "") {
			twitchAuthToken = getURLHashParam("access_token"); 
			localStorage.setItem("rjp-twitchAuthToken", twitchAuthToken);
			window.history.pushState(null, null, window.location.pathname + window.location.search);
		}
		if (getURLParam("error") !== "") {
			if (getURLParam("error_description") === "The user denied you access") {
				alert("To find a random stream or use the followed streams list, please authorize Twitch access.");
				if (localStorage.getItem("rjp-afterAuthAction") === "random") {
					localStorage.removeItem("rjp-afterAuthAction"); 
				}
			}
			else {
				localStorage.removeItem("rjp-twitchAuthToken");
				redirectForTwitchAuthToken("stream");
			}
		}
		if (localStorage.getItem("rjp-afterAuthAction") !== null) {
			if (localStorage.getItem("rjp-afterAuthAction") === "random") {
				document.getElementById("randomStreamButton").click(); 
			}
			else {
				streamURL = localStorage.getItem("rjp-afterAuthAction"); 
			}
			localStorage.removeItem("rjp-afterAuthAction"); 
		}
		if (streamURL != "") {
			streamURLElement.value = streamURL; 
			document.title = `${documentTitle} - ${streamURL}`; 
			updateStreamFrame(); 
			peekUI(); 
		}
		else {
			document.title = `${documentTitle}`; 
			if (window.innerWidth < 768) {
				setUIState("open"); 
				setTimeout(() => {
					setMenuElementState("close"); 
				}, 3000);
			}
			else {
				setUIState("open"); 
			}
		}
	}
function initializePlayer ( ) { playerURL = new URL ( document . location . href . toString ( ) ) ; streamURL = getURLParam ( "streamURL" ) ; if ( localStorage . getItem ( "rjp-twitchAuthToken" ) !== null ) { twitchAuthToken = localStorage . getItem ( "rjp-twitchAuthToken" ) ; } if ( getURLHashParam ( "access_token" ) !== "" ) { twitchAuthToken = getURLHashParam ( "access_token" ) ; localStorage . setItem ( "rjp-twitchAuthToken" , twitchAuthToken ) ; window . history . pushState ( null , null , window . location . pathname + window . location . search ) ; } if ( getURLParam ( "error" ) !== "" ) { if ( getURLParam ( "error_description" ) === "The user denied you access" ) { alert ( "To find a random stream or use the followed streams list, please authorize Twitch access." ) ; if ( localStorage . getItem ( "rjp-afterAuthAction" ) === "random" ) { localStorage . removeItem ( "rjp-afterAuthAction" ) ; } } else { localStorage . removeItem ( "rjp-twitchAuthToken" ) ; redirectForTwitchAuthToken ( "stream" ) ; } } if ( localStorage . getItem ( "rjp-afterAuthAction" ) !== null ) { if ( localStorage . getItem ( "rjp-afterAuthAction" ) === "random" ) { document . getElementById ( "randomStreamButton" ) . click ( ) ; } else { streamURL = localStorage . getItem ( "rjp-afterAuthAction" ) ; } localStorage . removeItem ( "rjp-afterAuthAction" ) ; } if ( streamURL != "" ) { streamURLElement . value = streamURL ; document . title = ` ${ documentTitle } ${ streamURL } ` ; updateStreamFrame ( ) ; peekUI ( ) ; } else { document . title = ` ${ documentTitle } ` ; if ( window . innerWidth < 768 ) { setUIState ( "open" ) ; setTimeout ( ( ) => { setMenuElementState ( "close" ) ; } , 3000 ) ; } else { setUIState ( "open" ) ; } } }
Function for initializing the player based on a new URL
Function for initializing the player based on a new URL
// Grab current URL // Get stream URL from player URL param // If there is a Twitch auth token saved from a previous session // Get twitchAuthToken // If an auth token was included with the URL update the stored one // Get the access token // Store it for future requests // Clear hashes // If there is an error param from Twitch auth attempt // If it was because the user denied access // Let them know // If the afterAuthAction is "random" // Remove that action // Else it may be because of an expired token // Clear token // Send them to get an auth token // If there is an action saved which needs to be performed // If the afterAuthAction is "random" // Click the random button again // Assume it is a stream URL // Set the streamURL to the saved afterAuthAction // Remove that action // If stream URL param of the player URL is not blank // Set the stream URL input element to the stream URL // Update document title // Show the stream // Briefly show UI // Else it is empty // Update document title // If this is a small screen // Open all UI // After 3000 seconds // Close menu // Else is is large enough to open everything // Open all UI