var loaded = false; function get_stats() { var loading_icon = document.getElementById("loading_icon"); stats_form = { "cookie" : cookie, "caching" : false, "plex_identity" : plex_identity }; var stats_data = JSON.stringify(stats_form); var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && (this.status == 200 || this.status == 400 || this.status == 500)) { try { var result= JSON.parse(this.responseText); } catch(error) { if(this.responseText.includes('Maximum execution time of')) { loading_icon.style.display = "none"; document.getElementById("search_wrapped_button").disabled = false; document.getElementById("search_wrapped_button").style.opacity = '1'; document.getElementById("plex_signout_button").disabled = false; document.getElementById("plex_signout_button").style.opacity = '1'; document.getElementById('results_error').innerHTML = 'PHP runtime exceeded and stopped execution. Admin must shorten wrapped period or perform caching.'; } else { console.log('Error: ' + error); console.log(this.responseText); loading_icon.style.display = "none"; document.getElementById("search_wrapped_button").disabled = false; document.getElementById("search_wrapped_button").style.opacity = '1'; document.getElementById("plex_signout_button").disabled = false; document.getElementById("plex_signout_button").style.opacity = '1'; document.getElementById('results_error').innerHTML = "API response can't be parsed."; } return; } if(result.error) { loading_icon.style.display = "none"; document.getElementById("search_wrapped_button").disabled = false; document.getElementById("search_wrapped_button").style.opacity = '1'; document.getElementById("plex_signout_button").disabled = false; document.getElementById("plex_signout_button").style.opacity = '1'; document.getElementById('results_error').innerHTML = result.message; } else { results = result; load_page(results); } } }; xhttp.withCredentials = true; xhttp.open("post", "api/get_stats.php"); xhttp.send(stats_data); loading_icon.style.display = "inline"; } function load_page(data){ // Remove snow document.getElementById('snowflakes').style.display = 'none'; // Set body background color to introduction document.getElementById("body").classList.add('color-red'); // Enable changing background colors JS loaded = true; if(results.error) { $('#results_error').html(results.message); loading_icon.style.display = "none"; search_button("SEARCH"); return } // Find HTML elements and hide them var search_box = document.getElementById("search_input"); var login_content = document.getElementById("login_content"); var footer = document.getElementById("footer"); search_box.style.display = "none"; login_content.style.display = "none"; footer.style.display = "none"; // Load the introduction load_introduction(); // Load the segments based on configuration if(!results.user.user_movies.error && functions.get_user_movie_stats) { load_movies(); } if(!results.user.user_shows.error && functions.get_user_show_stats) { load_shows(); } if(!results.user.user_music.error && functions.get_user_music_stats) { load_music(); } if(!results.year_stats.error && (functions.get_year_stats_movies || functions.get_year_stats_shows || functions.get_year_stats_music)) { load_users(); } // Load the outro load_outro(); } //INTRODUCTION function load_introduction() { var text = ""; text += "
" + functions.get_user_movie_stats_subsubtitle + "
"; text += "" + functions.get_user_movie_stats_subsubtitle_one + "
"; text += "" + functions.get_user_movie_stats_subsubtitle_none + "
"; text += '" + functions.get_user_show_stats_subsubtitle + "
"; text += "" + functions.get_user_show_stats_subsubtitle_one + "
"; text += "" + functions.get_user_show_stats_subsubtitle_none + "
"; text += '" + functions.get_user_music_stats_subsubtitle + "
"; text += "" + functions.get_user_music_stats_subsubtitle_one + "
"; text += "" + functions.get_user_music_stats_subsubtitle_none + "
"; text += '" + functions.get_year_stats_subsubtitle + "
"; text += "