var results; var loading_icon = document.getElementById("loading_icon"); var p_email = document.getElementById("p_email").value; var p_email = p_email.replace(/[&\/\\#,+()$~%:*?<>{}]/g, ''); stats_form = { "p_email" : p_email }; var stats_data = JSON.stringify(stats_form); var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { load_page(this.responseText); } }; xhttp.withCredentials = true; xhttp.open("post", "api/get_stats.php"); xhttp.send(stats_data); loading_icon.style.display = "inline"; function load_page(data){ results = JSON.parse(data); if(results.error == "true") { $('#results_error').html(results.message); loading_icon.style.display = "none"; search_button("SEARCH"); exit(1); } var search_box = document.getElementById("search_input"); search_box.style.display = "none"; var text = ""; //INTRODUCTION text += "
"; text += "

Hey there, " + results.user.name + "!

"; text += "

2020 kinda sucked, but hopefully you watched some cool stuff...

" text += "

"; //MOVIES text += "
"; text += "

Let's look at some movies."; text += "


You watched " + results.user.user_movies.data.movies.length + " movies. That's a lot of movies!


(or not, I am pre-programmed to say that)" text += "

"; text += "
"; text += "
"; text += "
"; text += "

Your top 10 movies in 2020

"; for(i = 0; (i < results.user.user_movies.data.movies.length && i < 10); i++) { text += "
"; text += "
"; text += i+1 + ". "; text += "
"; text += "
"; text += results.user.user_movies.data.movies[i].title; var movie_hour = time_hours(results.user.user_movies.data.movies[i].duration) text += " - " + movie_hour[0] + " hours, " + movie_hour[1] + " minutes"; text += "
"; text += "
"; } text += "
"; text += "
"; text += "
"; text += "
"; text += "
"; var str = JSON.stringify(results.user.user_movies.data.user_movie_finishing_percent); var percent = str.split('.'); text += "

Your average movie finishing percentage in 2020 was " + percent[0] + "%

"; text += "

You're not watching the credits like a nerd, are you?"; text += "
"; text += "
"; text += "Your longest movie pause was watching

" + results.user.user_movies.data.user_movie_most_paused.title + ".

"; var str = JSON.stringify(results.user.user_movies.data.user_movie_most_paused.paused_counter / 60); var minutes = str.split('.'); text += "
It was paused for " + minutes[0] + " minutes..."; text += "
"; text += "
"; text += "
"; //SHOWS text += "
"; text += "

Now, let's have a look at some shows!"; text += "


You watched " + results.user.user_shows.data.shows.length + " different shows.


(No, watching The Office twice in a year doesn't count as two shows)" text += "

"; text += "
"; text += "
"; text += "
"; text += "

Your top 10 shows in 2020

"; for(i = 0; (i < results.user.user_shows.data.shows.length && i < 10); i++) { text += "
"; text += "
"; text += i+1 + ". "; text += "
"; text += "
"; text += results.user.user_shows.data.shows[i].title; var show_hour = time_hours(results.user.user_shows.data.shows[i].duration) text += " - " + show_hour[0] + " hours, " + show_hour[1] + " minutes"; text += "
"; text += "
"; } text += "
"; text += "
"; text += "
"; if(results.user.user_shows.data.shows.length > 0) { text += "
"; text += "
"; text += "

Your top show was " + results.user.user_shows.data.shows[0].title + "


"; var buddy_error = JSON.stringify(results.user.user_shows.data.show_buddy.error); if(buddy_error == "true") { text += "
That means you're a hipster, because you're the only viewer of that show in 2020 😎"; } else { text += "And you're not alone! Your " + results.user.user_shows.data.shows[0].title + "-buddy is "; text += "" + results.user.user_shows.data.show_buddy.user.user + "!

"; var combined = results.user.user_shows.data.show_buddy.user.duration + parseInt(results.user.user_shows.data.shows[0].duration); var combined_2 = time_hours(combined); text += "Your combined efforts resulted in " + combined_2[0] + " hours and " + combined_2[1] + " minutes of " + results.user.user_shows.data.shows[0].title + "!

😎"; } text += "
"; text += "
"; } text += "
"; //TOP USERS text += "
"; text += "

Finally, let's look at the top users, movies and shows in 2020!"; text += "



It's okay to feel shame if you are on the list.

(or missing from it...)" text += "

"; text += "
"; text += "
"; text += "
"; text += "

Top users from the past year

"; for(i = 0; i < 10 && i < results.year_stats.data.users.length; i++) { text += "
"; text += "
"; text += i+1 + ". "; text += "
"; text += "
"; text += results.year_stats.data.users[i].user; text += "
"; text += "
"; } text += "
"; text += "
"; text += "
"; text += "
"; text += "
"; text += "
"; text += "

Top movies from the past year

"; for(i = 0; i < 10 && i < results.year_stats.data.top_movies.length; i++) { text += "
"; text += "
"; text += i+1 + ". "; text += "
"; text += "
"; text += results.year_stats.data.top_movies[i].title; var movie_hour = time_hours(results.year_stats.data.top_movies[i].duration) text += "
" + movie_hour[0] + " hours and " + movie_hour[1] + " minutes"; text += "
"; text += "
"; } text += "
"; text += "
"; text += "
"; text += "
"; text += "
"; text += "
"; text += "

Top shows from the past year

"; for(i = 0; i < 10 && i < results.year_stats.data.top_shows.length; i++) { text += "
"; text += "
"; text += i+1 + ". "; text += "
"; text += "
"; text += results.year_stats.data.top_shows[i].title; var show_hour = time_hours(results.year_stats.data.top_shows[i].duration) text += "
" + show_hour[0] + " hours and " + show_hour[1] + " minutes"; text += "
"; text += "
"; } text += "
"; text += "
"; text += "
"; text += "
"; //SHOWS text += "
"; text += "

Hope you are staying safe!



Goodybye.

"; text += "
"; $('#search_results').html(text); }