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 += "
"; text += "
"; text += "
"; text += ''; text += "
"; text += "
"; text += "

" + functions.stats_intro_title.replaceAll('{user}', results.user.name) + "

"; text += "

" + functions.stats_intro_subtitle + "

"; text += "
"; text += "
"; text += "
"; document.getElementById("search_results").innerHTML += text; } // Toggle list to plays or duration function top_list_sort_by(array, title, music, year, div_id, button_id, functions_data) { document.getElementById(div_id).outerHTML = top_list(array, title, music, year, div_id); var button_text = document.getElementById(button_id + '_text'); if(button_text.innerHTML.includes(functions_data.wrapperr_sort_plays)) { button_text.innerHTML = functions_data.wrapperr_sort_duration; } else { button_text.innerHTML = functions_data.wrapperr_sort_plays; } var button = document.getElementById(button_id); if(button.getAttribute('onclick').includes('_duration')) { button.setAttribute( "onclick", button.getAttribute('onclick').replaceAll('_duration', '_plays')); } else { button.setAttribute( "onclick", button.getAttribute('onclick').replaceAll('_plays', '_duration')); } } //MOVIES function load_movies() { var text = ""; if(results.user.user_movies.data.movie_plays > 1) { text += "
"; // Get custom text fron functions text += "
"; text += "

" + functions.get_user_movie_stats_title + "

"; text += "
"; // Replace custom string with movie plays text += "
"; text += "

" + functions.get_user_movie_stats_subtitle.replaceAll('{movie_count}', number_with_spaces(results.user.user_movies.data.movie_plays)) + "

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

" + functions.get_user_movie_stats_subsubtitle + "

"; text += "
"; // Place stats text += "
"; text += "
"; if(functions.stats_order_by_plays !== false && functions.stats_order_by_duration !== false) { text += ''; } if(functions.stats_order_by_plays == false) { text += top_list(results.user.user_movies.data.movies_duration, functions.get_user_movie_stats_top_movie_plural, false, true, 'user_movies_data_movies'); } else { text += top_list(results.user.user_movies.data.movies_plays, functions.get_user_movie_stats_top_movie_plural, false, true, 'user_movies_data_movies'); } text += "
"; text += "
"; text += "
"; text += completion_movie(results.user.user_movies.data.user_movie_finishing_percent, false, functions); text += "
"; text += "
"; text += paused_movie(results.user.user_movies.data.user_movie_most_paused, false, functions); text += "
"; if(!results.user.user_movies.data.user_movie_oldest.error) { text += "
"; text += oldest_movie(results.user.user_movies.data.user_movie_oldest, functions); text += "
"; } text += "
"; text += you_spent(results.user.user_movies.data.movie_duration, 'movies', functions); text += "
"; text += "
"; text += "
"; text += "
"; } else if(results.user.user_movies.data.movie_plays == 1) { text += "
"; text += "
"; text += "

" + functions.get_user_movie_stats_title + "

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

" + functions.get_user_movie_stats_subtitle_one + "

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

" + functions.get_user_movie_stats_subsubtitle_one + "

"; text += "
"; text += "
"; text += "
"; text += top_list(results.user.user_movies.data.movies_duration, functions.get_user_movie_stats_top_movie, false, true); text += "
"; text += "
"; text += "
"; text += completion_movie(results.user.user_movies.data.user_movie_finishing_percent, true, functions); text += "
"; text += "
"; text += paused_movie(results.user.user_movies.data.user_movie_most_paused, true, functions); text += "
"; text += "
"; text += "
"; text += "
"; } else { text += "
"; text += "
"; text += "
"; text += "
"; text += "

" + functions.get_user_movie_stats_title + "

"; text += "

" + functions.get_user_movie_stats_subtitle_none + "

"; text += "

" + functions.get_user_movie_stats_subsubtitle_none + "

"; text += ''; text += "
"; text += "
"; text += "
"; text += "
"; } document.getElementById("search_results").innerHTML += text; } //SHOWS function load_shows() { var text = ""; if(results.user.user_shows.data.show_plays > 1) { text += "
"; text += "
"; text += "

" + functions.get_user_show_stats_title + "

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

" + functions.get_user_show_stats_subtitle.replaceAll('{show_count}', number_with_spaces(results.user.user_shows.data.show_plays)) + "

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

" + functions.get_user_show_stats_subsubtitle + "

"; text += "
"; text += "
"; text += "
"; if(functions.stats_order_by_plays !== false && functions.stats_order_by_duration !== false) { text += ''; } if(functions.stats_order_by_plays == false) { text += top_list(results.user.user_shows.data.shows_duration, functions.get_user_show_stats_top_show_plural, false, true, 'user_shows_data_shows'); } else { text += top_list(results.user.user_shows.data.shows_plays, functions.get_user_show_stats_top_show_plural, false, true, 'user_shows_data_shows'); } text += "
"; text += "
"; if(results.user.user_shows.data.shows_duration.length > 0 && !results.user.user_shows.data.show_buddy.error && functions.get_user_show_stats_buddy) { text += "
"; text += load_showbuddy(results.user.user_shows.data.show_buddy, results.user.user_shows.data.shows_duration[0], functions); text += "
"; } if(results.user.user_shows.data.episode_duration_longest.plays != 0 && results.user.user_shows.data.episode_duration_longest.duration != 0) { text += "
"; text += load_longest_episode(results.user.user_shows.data.episode_duration_longest, functions); text += "
"; } text += "
"; text += you_spent(results.user.user_shows.data.show_duration, 'shows', functions); text += "
"; text += "
"; text += "
"; text += "
"; } else if(results.user.user_shows.data.show_plays == 1) { text += "
"; text += "
"; text += "

" + functions.get_user_show_stats_title + "

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

" + functions.get_user_show_stats_subtitle_one + "

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

" + functions.get_user_show_stats_subsubtitle_one + "

"; text += "
"; text += "
"; text += "
"; text += top_list(results.user.user_shows.data.shows_duration, functions.get_user_show_stats_top_show, false, true); text += "
"; if(results.user.user_shows.data.shows_duration.length > 0 && !results.user.user_shows.data.show_buddy.error && functions.get_user_show_stats_buddy) { text += "
"; text += load_showbuddy(results.user.user_shows.data.show_buddy, results.user.user_shows.data.shows_duration[0], functions); text += "
"; } if(results.user.user_shows.data.episode_duration_longest.plays != 0 && results.user.user_shows.data.episode_duration_longest.duration != 0) { text += "
"; text += load_longest_episode(results.user.user_shows.data.episode_duration_longest, functions); text += "
"; } text += "
"; text += "
"; } else { text += "
"; text += "
"; text += "
"; text += "
"; text += "

" + functions.get_user_show_stats_title + "

"; text += "

" + functions.get_user_show_stats_subtitle_none + "

"; text += "

" + functions.get_user_show_stats_subsubtitle_none + "

"; text += ''; text += "
"; text += "
"; text += "
"; text += "
"; } document.getElementById("search_results").innerHTML += text; } //MUSIC function load_music() { var text = ""; if(results.user.user_music.data.track_plays > 1) { text += "
"; text += "
"; text += "

" + functions.get_user_music_stats_title + "

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

" + functions.get_user_music_stats_subtitle.replaceAll('{track_count}', number_with_spaces(results.user.user_music.data.track_plays)) + "

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

" + functions.get_user_music_stats_subsubtitle + "

"; text += "
"; text += "
"; text += "
"; if(functions.stats_order_by_plays !== false && functions.stats_order_by_duration !== false) { text += ''; } if(functions.stats_order_by_plays == false) { text += top_list(results.user.user_music.data.tracks_duration, functions.get_user_music_stats_top_track_plural, "track", false, 'user_music_data_tracks'); } else { text += top_list(results.user.user_music.data.tracks_plays, functions.get_user_music_stats_top_track_plural, "track", false, 'user_music_data_tracks'); } text += "
"; text += "
"; if(functions.stats_order_by_plays !== false && functions.stats_order_by_duration !== false) { text += ''; } if(functions.stats_order_by_plays == false) { text += top_list(results.user.user_music.data.albums_duration, functions.get_user_music_stats_top_album_plural, "album", false, 'user_music_data_albums'); } else { text += top_list(results.user.user_music.data.albums_plays, functions.get_user_music_stats_top_album_plural, "album", false, 'user_music_data_albums'); } text += "
"; text += "
"; if(functions.stats_order_by_plays !== false && functions.stats_order_by_duration !== false) { text += ''; } if(functions.stats_order_by_plays == false) { text += top_list(results.user.user_music.data.artists_duration, functions.get_user_music_stats_top_artist_plural, "artist", false, 'user_music_data_artists'); } else { text += top_list(results.user.user_music.data.artists_plays, functions.get_user_music_stats_top_artist_plural, "artist", false, 'user_music_data_artists'); } text += "
"; text += "
"; text += "
"; text += "
"; if(!results.user.user_music.data.user_album_oldest.error) { text += "
"; text += oldest_album(results.user.user_music.data.user_album_oldest, functions); text += "
"; } text += "
"; text += you_spent(results.user.user_music.data.track_duration, 'music', functions); text += "
"; text += "
"; text += "
"; text += "
"; } else if(results.user.user_music.data.track_plays == 1) { text += "
"; text += "
"; text += "

" + functions.get_user_music_stats_title + "

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

" + functions.get_user_music_stats_subtitle_one + "

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

" + functions.get_user_music_stats_subsubtitle_one + "

"; text += "
"; text += "
"; text += "
"; text += top_list(results.user.user_music.data.tracks_duration, functions.get_user_music_stats_top_track, true, false); text += "
"; text += "
"; text += "
"; } else { text += "
"; text += "
"; text += "
"; text += "
"; text += "

" + functions.get_user_music_stats_title + "

"; text += "

" + functions.get_user_music_stats_subtitle_none + "

"; text += "

" + functions.get_user_music_stats_subsubtitle_none + "

"; text += ''; text += "
"; text += "
"; text += "
"; text += "
"; } document.getElementById("search_results").innerHTML += text; } function oldest_movie(array, functions_data) { var html = ""; html += "
"; html += "
"; html += functions_data.get_user_movie_stats_oldest_title.replaceAll('{movie_title}', '' + array.title + " (" + array.year + ")"); html += '
'; html += '
'; if(array.year < 1950) { html += functions_data.get_user_movie_stats_oldest_subtitle_pre_1950; } else if(array.year < 1975) { html += functions_data.get_user_movie_stats_oldest_subtitle_pre_1975; } else if(array.year < 2000) { html += functions_data.get_user_movie_stats_oldest_subtitle_pre_2000; } else { html += functions_data.get_user_movie_stats_oldest_subtitle; } html += '
'; html += "
"; html += "
"; return html; } function oldest_album(album, functions_data) { var html = ""; html += "
"; html += "
"; html += functions_data.get_user_music_stats_oldest_album_title.replaceAll('{album_title}', '' + album.parent_title + " (" + album.year + ")").replaceAll('{album_artist}', album.grandparent_title); html += "

"; html += functions_data.get_user_music_stats_oldest_album_subtitle; html += '
'; html += "
"; html += "
"; return html; } function completion_movie(user_movie_finishing_percent, single, functions_data) { var html = ""; html += "
"; html += "
"; var str = JSON.stringify(user_movie_finishing_percent); if(str.includes('.')) { var percent = str.split('.'); percent = percent[0] + '.' + percent[1].slice(0, 2); } else { var percent = str; } if(!single) { html += "" + functions_data.get_user_movie_stats_movie_completion_title_plural.replaceAll('{movie_finish_percent}', percent) + ""; } else { html += "" + functions_data.get_user_movie_stats_movie_completion_title.replaceAll('{movie_finish_percent}', percent) + ""; } if(user_movie_finishing_percent >= 90.0) { html += ''; } else { html += '

'; } html += functions_data.get_user_movie_stats_movie_completion_subtitle; html += "
"; html += "
"; return html; } function paused_movie(array, single, functions_data) { var html = ""; html += "
"; if(array.paused_counter > 0) { var pause_time = seconds_to_time(array.paused_counter, false); if(!single) { html += "
"; html += functions_data.get_user_movie_stats_pause_title.replaceAll('{movie_title}', '' + array.title + '' + ' (' + array.year + ')'); html += "
"; html += "
"; html += functions_data.get_user_movie_stats_pause_subtitle.replaceAll('{pause_duration}', pause_time); html += "
"; } else { html += "
"; html += functions_data.get_user_movie_stats_pause_title_one; html += "
"; html += "
"; html += functions_data.get_user_movie_stats_pause_subtitle_one.replaceAll('{pause_duration}', pause_time); html += "
"; } } else { html += "
"; html += '' + functions_data.get_user_movie_stats_pause_title_none + ''; html += '
'; html += "
"; html += functions_data.get_user_movie_stats_pause_subtitle_none; html += "
"; } html += "
"; return html; } function load_showbuddy(buddy_object, top_show, functions_data) { var html = ""; html += "
"; html += "
"; if(!buddy_object.error) { if(!buddy_object.found) { html += functions_data.get_user_show_stats_buddy_title_none.replaceAll('{top_show_title}', '' + top_show.title + ''); html += '

'; html += functions_data.get_user_show_stats_buddy_subtitle_none; } else { html += functions_data.get_user_show_stats_buddy_title.replaceAll('{top_show_title}', '' + top_show.title + '').replaceAll('{buddy_username}', buddy_object.friendly_name); var combined = results.user.user_shows.data.show_buddy.duration + parseInt(results.user.user_shows.data.shows_duration[0].duration); var combined_2 = seconds_to_time(combined); html += ''; html += functions_data.get_user_show_stats_buddy_subtitle.replaceAll('{buddy_duration_sum}', combined_2).replaceAll('{top_show_title}', top_show.title); } } html += "
"; html += "
"; return html; } function load_longest_episode(array, functions_data) { var html = ""; html += "
"; html += "
"; html += functions_data.get_user_show_stats_most_played_title.replaceAll('{show_episode}', '' + array.title + '').replaceAll('{show_title}', array.grandparent_title); html += '

'; html += functions_data.get_user_show_stats_most_played_subtitle.replaceAll('{episode_play_sum}', play_plays(array.plays)).replaceAll('{episode_duration_sum}', seconds_to_time(array.duration, false)); html += "
"; html += "
"; return html; } function you_spent(time, category, functions_data) { var html = ""; var time_str = seconds_to_time(time, false); if(category === 'movies') { html += "
"; html += "
"; html += functions_data.get_user_movie_stats_spent_title.replaceAll('{movie_sum_duration}', time_str); html += '
'; html += "
"; html += "
"; } else if(category === 'shows') { html += "
"; html += functions_data.get_user_show_stats_spent_title.replaceAll('{show_sum_duration}', time_str); html += '
'; html += "
"; } else if(category === 'music') { html += "
"; html += "
"; html += functions_data.get_user_music_stats_spent_title.replaceAll('{music_sum_duration}', time_str); if(time > 3600) { var time_min = Math.floor(time / 60); var time_str = time_min + ' ' + functions.wrapperr_minute_plural; html += '

'; html += functions_data.get_user_music_stats_spent_subtitle.replaceAll('{music_sum_minutes}', number_with_spaces(time_str)); } html += '
'; html += "
"; html += "
"; } else { html += "
"; html += "Unknown category."; html += "
"; } return html; } function top_list(array, title, music, year, div_id) { var html = ""; html += "
"; html += "
"; html += "
" + title + "
"; html += "
"; for(i = 0; (i < array.length && i < 10); i++) { html += "
"; html += "
"; html += i+1 + ". "; html += "
"; html += "
"; if(music === "track" || music === "album") { html+= array[i].grandparent_title + "
"; } html += ""; if(music === "album") { html += array[i].parent_title; } else if(music === "artist") { html += array[i].grandparent_title; } else { html += array[i].title; } html += ""; var movie_hour = seconds_to_time(array[i].duration, true); if(typeof(array[i].year) !== "undefined" && year) { html += " (" + array[i].year + ")"; } html += "
" + movie_hour + "
" + play_plays(array[i].plays); html += "
"; html += "
"; } html += "
"; html += "
"; html += "
"; return html; } function top_list_names(array, title, div_id) { var html = ""; html += "
"; html += "
"; html += "
" + title + "
"; html += "
"; for(i = 0; i < 10 && i < array.length; i++) { if(i == 0) { html += "
"; } else if(i == 1) { html += "
"; } else if(i == 2) { html += "
"; } else { html += "
"; } html += "
"; html += i+1 + ". "; html += "
"; if(array[i].user == results.user.name) { html += "
"; html += array[i].user; html += "
"; }else { html += "
"; html += array[i].user; html += "
"; } html += "
"; } html += "
"; html += "
"; html += "
"; return html; } // Toggle names list to plays or duration function top_list_names_sort_by(array, title, div_id, button_id, functions_data) { document.getElementById(div_id).outerHTML = top_list_names(array, title, div_id); var button_text = document.getElementById(button_id + '_text'); if(button_text.innerHTML.includes(functions_data.wrapperr_sort_plays)) { button_text.innerHTML = button_text.innerHTML = functions_data.wrapperr_sort_duration; } else { button_text.innerHTML = button_text.innerHTML = functions_data.wrapperr_sort_plays; } var button = document.getElementById(button_id); if(button.getAttribute('onclick').includes('_duration')) { button.setAttribute( "onclick", button.getAttribute('onclick').replaceAll('_duration', '_plays')); } else { button.setAttribute( "onclick", button.getAttribute('onclick').replaceAll('_plays', '_duration')); } } //TOP USERS function load_users() { var text = ""; text += "
"; text += "

" + functions.get_year_stats_title + "

"; text += "

" + functions.get_year_stats_subtitle + "

"; text += "

" + functions.get_year_stats_subsubtitle + "

"; text += "
"; if(functions.get_year_stats_leaderboard) { text += "
"; if(functions.stats_order_by_plays !== false && functions.stats_order_by_duration !== false) { text += ''; } if(functions.stats_order_by_plays == false) { text += top_list_names(results.year_stats.year_users.data.users_duration, functions.get_year_stats_leaderboard_title, 'year_stats_year_users'); } else { text += top_list_names(results.year_stats.year_users.data.users_plays, functions.get_year_stats_leaderboard_title, 'year_stats_year_users'); } text += "
"; var time_movies = seconds_to_time(results.year_stats.year_movies.data.movie_duration, false); var time_shows = seconds_to_time(results.year_stats.year_shows.data.show_duration, false); var time_artists = seconds_to_time(results.year_stats.year_music.data.music_duration, false); var function_sum = 0; var time = 0; text += "
"; text += "
"; text += "
"; if(functions.get_year_stats_movies && results.year_stats.year_movies.data.movie_plays > 0) { text += functions.get_year_stats_movies_duration_title.replaceAll('{movie_duration_sum}', '' + time_movies + ''); text += "

"; function_sum += 1; time += results.year_stats.year_movies.data.movie_duration; } if(functions.get_year_stats_shows && results.year_stats.year_shows.data.show_plays > 0) { text += functions.get_year_stats_shows_duration_title.replaceAll('{show_duration_sum}', '' + time_shows + ''); text += "

"; function_sum += 1; time += results.year_stats.year_shows.data.show_duration; } if(functions.get_year_stats_music && results.year_stats.year_music.data.music_plays > 0) { text += functions.get_year_stats_music_duration_title.replaceAll('{music_duration_sum}', '' + time_artists + ''); text += "

"; function_sum += 1; time += results.year_stats.year_music.data.music_duration; } if(function_sum > 1) { var time_all = seconds_to_time(Math.floor(time), false); text += functions.get_year_stats_duration_sum_title.replaceAll('{all_duration_sum}', '' + time_all + ''); } text += ''; text += "
"; text += "
"; text += "
"; } text += "
"; text += "
"; if(functions.get_year_stats_movies && results.year_stats.year_movies.data.movie_plays > 0) { text += "
"; if(functions.stats_order_by_plays !== false && functions.stats_order_by_duration !== false) { text += ''; } if(functions.stats_order_by_plays == false) { text += top_list(results.year_stats.year_movies.data.movies_duration, functions.get_year_stats_movies_title, false, true, 'year_stats_year_movies'); } else { text += top_list(results.year_stats.year_movies.data.movies_plays, functions.get_year_stats_movies_title, false, true, 'year_stats_year_movies'); } text += "
"; } if(functions.get_year_stats_shows && results.year_stats.year_shows.data.show_plays > 0) { text += "
"; if(functions.stats_order_by_plays !== false && functions.stats_order_by_duration !== false) { text += ''; } if(functions.stats_order_by_plays == false) { text += top_list(results.year_stats.year_shows.data.shows_duration, functions.get_year_stats_shows_title, false, false, 'year_stats_year_shows'); } else { text += top_list(results.year_stats.year_shows.data.shows_plays, functions.get_year_stats_shows_title, false, false, 'year_stats_year_shows'); } text += "
"; } if(functions.get_year_stats_music && results.year_stats.year_music.data.music_plays > 0) { text += "
"; if(functions.stats_order_by_plays !== false && functions.stats_order_by_duration !== false) { text += ''; } if(functions.stats_order_by_plays == false) { text += top_list(results.year_stats.year_music.data.artists_duration, functions.get_year_stats_music_title, "artist", false, 'year_stats_year_music'); } else { text += top_list(results.year_stats.year_music.data.artists_plays, functions.get_year_stats_music_title, "artist", false, 'year_stats_year_music'); } text += "
"; } text += "
"; text += "
"; document.getElementById("search_results").innerHTML += text; } //Outro function load_outro() { var text = ""; text += "
"; text += "
"; text += "
"; text += ''; text += "
"; text += "
"; text += "

" + functions.stats_outro_title + "

"; text += "

" + functions.stats_outro_subtitle + "

"; text += "
"; text += "
"; text += "
"; text += "
"; if(!link_mode && functions.create_share_links) { text += "
"; text += ""; text += ""; text += "
"; } var url_home = window.location.href.split('?')[0]; text += "
"; text += `"; text += "
"; text += "
"; text += "
"; text += "
"; document.getElementById("search_results").innerHTML += text; } function create_wrapped_link() { document.getElementById("share_wrapped_button").disabled = true; document.getElementById("share_wrapped_button").style.opacity = '0.5'; wrapped_form = { "cookie" : get_cookie('wrapperr-user'), "data" : results, "functions" : functions }; var wrapped_data = JSON.stringify(wrapped_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) { alert("API response can't be parsed."); console.log('Error: ' + error); console.log(this.responseText); document.getElementById("share_wrapped_button").disabled = false; document.getElementById("share_wrapped_button").style.opacity = '1'; } if(result.error) { alert(result.message); document.getElementById("share_wrapped_button").disabled = false; document.getElementById("share_wrapped_button").style.opacity = '1'; } else { document.getElementById('share_wrapped_results_url').innerHTML = '' + window.location.href.split('?')[0] + result.url + ''; document.getElementById('share_wrapped_results_div').style.display = 'inline-block'; document.getElementById("share_wrapped_button").disabled = false; document.getElementById("share_wrapped_button").style.opacity = '1'; } } }; xhttp.withCredentials = true; xhttp.open("post", "api/create_link.php"); xhttp.send(wrapped_data); } //Converting seconds to time in string var seconds_in_day = 86400; var seconds_in_hour = 3600; var seconds_in_minute = 60; function seconds_to_time(seconds, comma) { if(seconds >= seconds_in_day) { var time = seconds_to_days(seconds, comma, functions); } else if(seconds >= seconds_in_hour) { var time = seconds_to_hours(seconds, comma, functions); } else if(seconds >= seconds_in_minute) { var time = seconds_to_minutes(seconds, comma, functions); } else { var time = seconds_to_seconds(seconds, functions); } return time; } // Change background color for each category $(window).scroll(function() { if(loaded) { // Select the window, body and elements containing stats var $window = $(window), $body = $('body'), $panel = $('.boks'); // Change 33% earlier than scroll position so colour is there when you arrive var scroll = $window.scrollTop() + ($window.height() / 3); $panel.each(function () { var $this = $(this); // If position is within range of this panel. // So position of (position of top of div <= scroll position) && (position of bottom of div > scroll position). // Remember we set the scroll to 33% earlier in scroll var. if ($this.position().top <= scroll && $this.position().top + $this.height() > scroll) { // Remove all classes on body with color- $body.removeClass(function (index, css) { return (css.match (/(^|\s)color-\S+/g) || []).join(' '); }); // Add class of currently active div $body.addClass('color-' + $(this).data('color')); } }); } }).scroll();