";
}
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.buddy_found) {
html += functions_data.get_user_show_stats_buddy_title_none.replaceAll('{top_show_title}', '' + top_show.grandparent_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.grandparent_title + '').replaceAll('{buddy_username}', buddy_object.buddy_name);
var combined = parseInt(top_show.duration) + parseInt(buddy_object.buddy_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.grandparent_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);
html += '
';
html += functions_data.get_user_music_stats_spent_subtitle.replaceAll('{music_sum_minutes}', number_with_spaces(time_min));
}
html += ' ';
html += "
";
html += "
";
} else {
html += "
";
html += "Unknown category.";
html += "
";
}
return html;
}
function top_list(array, title, music, show, 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 + " ";
} else if(show) {
html+= "" + array[i].grandparent_title + "";
}
if(!show) {
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_duration !== 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_duration !== false) {
text += top_list(results.year_stats.year_movies.data.movies_duration, functions.get_year_stats_movies_title, false, 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, false, true, 'year_stats_year_movies');
}
text += "
";
if(functions.stats_order_by_plays !== false && functions.stats_order_by_duration !== false) {
text += '';
}
if(functions.stats_order_by_duration !== false) {
text += top_list(results.year_stats.year_music.data.artists_duration, functions.get_year_stats_music_title, "artist", false, 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, 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 && functions.plex_auth) {
text += "
";
text += "";
text += "
";
text += "
";
text += "
Shareable link (valid for 7 days):
";
text += "
";
text += "
";
text += "
";
text += "";
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 = {
"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] + '?hash=' + result.data;
document.getElementById('share_wrapped_results_title_div').style.display = 'block';
document.getElementById('share_wrapped_results_div').style.display = 'flex';
document.getElementById("share_wrapped_button").disabled = true;
document.getElementById("share_wrapped_button").style.opacity = '0.5';
}
}
};
xhttp.withCredentials = true;
xhttp.open("post", "api/create/share-link");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", "Bearer " + cookie);
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;
}
function copy_link_user() {
/* Get the text field */
var copyText = document.getElementById("share_wrapped_results_url").innerHTML
/* Copy the text inside the text field */
navigator.clipboard.writeText(copyText)
alert("URL copied to clipboard.")
}
function delete_new_link_user() {
if(!confirm('Are you sure you want to delete this link?')) {
return;
}
cookie_form = {};
var cookie_data = JSON.stringify(cookie_form);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
try {
var result= JSON.parse(this.responseText);
} catch(error) {
console.log('Failed to parse Wrapperr response. Response: ' + this.responseText)
}
if(!result.error) {
document.getElementById('share_wrapped_results_url').innerHTML = "";
document.getElementById('share_wrapped_results_title_div').style.display = 'none';
document.getElementById('share_wrapped_results_div').style.display = 'none';
document.getElementById("share_wrapped_button").disabled = false;
document.getElementById("share_wrapped_button").style.opacity = '1';
} else {
console.log(result.message);
}
}
};
xhttp.withCredentials = true;
xhttp.open("post", "api/delete/user-share-link");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", "Bearer " + cookie);
xhttp.send(cookie_data);
return;
}
// 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();