function topFunction() { document.body.scrollTop = 0; // For Safari document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera } function login_menu() { topFunction(); var html = '

Admin Login

'; html += '
' html += '
'; html += ''; html += ''; html += '
'; html += '
'; html += ''; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; document.getElementById("setup").innerHTML = html; } function log_in() { // Disable button document.getElementById("log_in_button").disabled = true; document.getElementById("log_in_button").style.opacity = '0.5'; // Get variables password = document.getElementById('password').value; username = document.getElementById('username').value; admin_login_form = {"admin_password" : password, "admin_username" : username}; var admin_login_data = JSON.stringify(admin_login_form); var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4) { try { var result= JSON.parse(this.responseText); } catch(error) { console.log('Failed to parse API response. Response: ' + this.responseText) document.getElementById("log_in_button").disabled = false; document.getElementById("log_in_button").style.opacity = '1'; document.getElementById('password').value = ''; return; } if(result.error) { document.getElementById("password_login_form_error").innerHTML = result.message; document.getElementById("log_in_button").disabled = false; document.getElementById("log_in_button").style.opacity = '1'; document.getElementById('password').value = ''; } else { set_cookie("wrapperr-admin", result.data, 3); location.reload(); } } }; xhttp.withCredentials = true; xhttp.open("post", api_url + "login/admin"); xhttp.send(admin_login_data); return; } function set_password_form() { topFunction(); var html = '

Create admin

'; html += '
' html += '
'; html += ''; html += ''; html += '
'; html += '
'; html += ''; html += ''; html += '
'; html += '
'; html += ''; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; document.getElementById("setup").innerHTML = html; } function set_password() { // Disable button document.getElementById("create_admin_button").disabled = true; document.getElementById("create_admin_button").style.opacity = '0.5'; // Check password match if(document.getElementById('password').value != document.getElementById('password_2').value) { alert("The passwords must match."); document.getElementById('password').value = ""; document.getElementById('password_2').value = ""; document.getElementById('password').focus(); document.getElementById("create_admin_button").disabled = false; document.getElementById("create_admin_button").style.opacity = '1'; return false; } else { password = document.getElementById('password').value; username = document.getElementById('username').value; } admin_create_form = {"admin_password" : password, "admin_username" : username}; var admin_create_data = JSON.stringify(admin_create_form); var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4) { try { var result= JSON.parse(this.responseText); } catch(error) { console.log('Failed to parse API response. Response: ' + this.responseText) document.getElementById("create_admin_button").disabled = false; document.getElementById("create_admin_button").style.opacity = '1'; return; } if(result.error) { document.getElementById("password_form_error").innerHTML = result.message; document.getElementById("create_admin_button").disabled = false; document.getElementById("create_admin_button").style.opacity = '1'; } else { location.reload(); } } }; xhttp.withCredentials = true; xhttp.open("post", api_url + "create/admin"); xhttp.send(admin_create_data); return; } function update_password_form() { topFunction(); var html = '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
' html += '
'; html += ''; html += ''; html += '
'; html += '
'; html += ''; html += ''; html += '
'; html += '
'; html += ''; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; document.getElementById("setup").innerHTML = html; } function update_password() { // Disable button document.getElementById("update_admin_button").disabled = true; document.getElementById("update_admin_button").style.opacity = '0.5'; // Check password match if(document.getElementById('password').value != document.getElementById('password_2').value) { alert("The passwords must match."); document.getElementById('password').value = ""; document.getElementById('password_2').value = ""; document.getElementById('password').focus(); document.getElementById("update_admin_button").disabled = false; document.getElementById("update_admin_button").style.opacity = '1'; return false; } else { password = document.getElementById('password').value; username = document.getElementById('username').value; } admin_create_form = {"admin_password" : password, "admin_username" : username}; var admin_create_data = JSON.stringify(admin_create_form); var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4) { try { var result= JSON.parse(this.responseText); } catch(error) { document.getElementById("password_form_error").innerHTML = 'Failed to parse API response.'; console.log('Failed to parse API response. Response: ' + this.responseText) document.getElementById("update_admin_button").disabled = false; document.getElementById("update_admin_button").style.opacity = '1'; return; } if(result.error) { document.getElementById("password_form_error").innerHTML = result.message; document.getElementById("update_admin_button").disabled = false; document.getElementById("update_admin_button").style.opacity = '1'; } else { set_cookie("wrapperr-admin", "", 1); location.reload(); } } }; xhttp.withCredentials = true; xhttp.open("post", api_url + "update/admin"); xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.setRequestHeader("Authorization", "Bearer " + cookie); xhttp.send(admin_create_data); return; } function get_admin_state() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4) { try { var result= JSON.parse(this.responseText); } catch(error) { console.log('Failed to parse API response. Response: ' + this.responseText) return; } if(result.error) { console.log(result.message); } else if(!result.configured) { first_time = true; set_password_form(); } else { login_menu(); } } else if(this.readyState == 4 && this.status !== 200) { var html = '

' + this.status + ' Error

'; html += '

The API did not respond correctly.

'; document.getElementById("setup").innerHTML = html; } }; xhttp.withCredentials = true; xhttp.open("post", api_url + "get_admin_state.php"); xhttp.send(); return; } function sign_out() { set_cookie("wrapperr-admin", "", 1); location.reload(); } function admin_menu() { var html = '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; document.getElementById("setup").innerHTML = html; if(timezone === '') { document.getElementById("set_wrapperr_settings").style.border = '0.15em dashed var(--red)'; document.getElementById("caching_menu").disabled = true; document.getElementById("caching_menu").style.opacity = '0.5'; } if(wrapped_start === '' || wrapped_end === '') { document.getElementById("set_wrapperr_customization").style.border = '0.15em dashed var(--red)'; document.getElementById("caching_menu").disabled = true; document.getElementById("caching_menu").style.opacity = '0.5'; } if(tautulli[0].tautulli_ip === '' || tautulli[0].tautulli_apikey === '' || tautulli[0].tautulli_length === '' || tautulli[0].tautulli_port == 0 || tautulli[0].tautulli_length == 0) { document.getElementById("set_tautulli_settings").style.border = '0.15em dashed var(--red)'; document.getElementById("caching_menu").disabled = true; document.getElementById("caching_menu").style.opacity = '0.5'; } if(!use_logs) { document.getElementById("log_menu").disabled = true; document.getElementById("log_menu").style.opacity = '0.5'; } } function set_tautulli_settings() { topFunction(); var html = '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
' for(var i = 0; i < tautulli.length; i++) { if(tautulli.length > 1) { html += '
'; html += ''; html += '
'; } html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += 'Use Tautulli grouping:'; html += 'Test Tautulli connection'; html += '
'; html += '
'; html += '
'; html += '
'; } html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
!
If you changed any server names you must clear the cache for Wrapperr to function.
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; document.getElementById("setup").innerHTML = html; } function additional_tautulli_server() { tautulli_apikey = "" tautulli_ip = "" tautulli_port = "" tautulli_length = 5000 tautulli_root = "" tautulli_libraries = "" tautulli_grouping = true tautulli_https = false tautulli_name = "" tautulli_object = { "tautulli_apikey" : tautulli_apikey, "tautulli_ip" : tautulli_ip, "tautulli_port" : tautulli_port, "tautulli_length" : tautulli_length, "tautulli_root" : tautulli_root, "tautulli_libraries" : tautulli_libraries, "tautulli_grouping" : tautulli_grouping, "tautulli_https" : tautulli_https, "tautulli_name" : "" }; tautulli.push(tautulli_object); set_tautulli_settings(); return; } function remove_tautulli_server(index) { if(tautulli.length < 2) { return } tautullinew = [] for(var i = 0; i < tautulli.length; i++) { if(i !== index) { tautullinew.push(tautulli[i]) } } tautulli = tautullinew set_tautulli_settings(); return; } function set_tautulli_settings_call() { document.getElementById("set_tautulli_form_button").disabled = true; document.getElementById("set_tautulli_form_button").style.opacity = '0.5'; var tautulli_settings_array = [] for(var i = 0; i < 100; i++) { try { tautulli_apikey = document.getElementById('tautulli_apikey_' + i).value; } catch { break; } tautulli_apikey = document.getElementById('tautulli_apikey_' + i).value; tautulli_ip = document.getElementById('tautulli_ip_' + i).value; tautulli_port = parseInt(document.getElementById('tautulli_port_' + i).value); tautulli_length = parseInt(document.getElementById('tautulli_length_' + i).value); tautulli_root = document.getElementById('tautulli_root_' + i).value; tautulli_libraries = document.getElementById('tautulli_libraries_' + i).value; tautulli_grouping = document.getElementById('tautulli_grouping_' + i).checked; tautulli_https = document.getElementById('tautulli_https_' + i).checked; tautulli_name = document.getElementById('tautulli_name_' + i).value; if(tautulli_apikey === '') { document.getElementById("set_tautulli_form_button").disabled = false; document.getElementById("set_tautulli_form_button").style.opacity = '1'; alert('API key is required for Tautulli to function.'); document.getElementById('tautulli_apikey_' + i).focus(); return; } if(tautulli_apikey === '') { document.getElementById("set_tautulli_form_button").disabled = false; document.getElementById("set_tautulli_form_button").style.opacity = '1'; alert('Server name is required for Tautulli to function.'); document.getElementById('tautulli_name_' + i).focus(); return; } if(tautulli_ip === '') { document.getElementById("set_tautulli_form_button").disabled = false; document.getElementById("set_tautulli_form_button").style.opacity = '1'; alert('Tautulli IP is required for Tautulli to function.'); document.getElementById('tautulli_ip_' + i).focus(); return; } if(tautulli_length == 0) { document.getElementById("set_tautulli_form_button").disabled = false; document.getElementById("set_tautulli_form_button").style.opacity = '1'; alert('Tautulli item length is required for Tautulli to function.'); document.getElementById('tautulli_length_' + i).focus(); return; } if(tautulli_port == 0) { document.getElementById("set_tautulli_form_button").disabled = false; document.getElementById("set_tautulli_form_button").style.opacity = '1'; alert('Tautulli port is required for Tautulli to function. Use 80 for HTTP, 443 for HTTPS.'); document.getElementById('tautulli_port_' + i).focus(); return; } tautulli_object = { "tautulli_apikey" : tautulli_apikey, "tautulli_ip" : tautulli_ip, "tautulli_port" : tautulli_port, "tautulli_length" : tautulli_length, "tautulli_root" : tautulli_root, "tautulli_libraries" : tautulli_libraries, "tautulli_grouping" : tautulli_grouping, "tautulli_https" : tautulli_https, "tautulli_name" : tautulli_name }; tautulli_settings_array.push(tautulli_object) } if(tautulli_settings_array.length < 1) { alert("Failed to save Tautulli settings.") document.getElementById("set_tautulli_form_button").disabled = false; document.getElementById("set_tautulli_form_button").style.opacity = '1'; return } var name_array = [] for(var i = 0; i < tautulli_settings_array.length; i++) { var found_name = false for(var j = 0; j < name_array.length; j++) { if(tautulli_settings_array[i].tautulli_name == name_array[j]) { found_name = true } } if(found_name) { alert("Tautulli server names must be unique.") document.getElementById("set_tautulli_form_button").disabled = false; document.getElementById("set_tautulli_form_button").style.opacity = '1'; return } else { name_array.push(tautulli_settings_array[i].tautulli_name) } } clear_cache = document.getElementById('clear_cache').checked; tautulli_settings_form = { "clear_cache" : clear_cache, "data_type" : "tautulli_config", "tautulli_config" : tautulli_settings_array, "wrapperr_data" : {}, "wrapperr_customize" : {} }; var tautulli_settings_data = JSON.stringify(tautulli_settings_form); console.log(tautulli_settings_data) //return; var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4) { try { var result= JSON.parse(this.responseText); } catch(error) { alert('Failed to parse API response.'); console.log('Failed to parse API response. Response: ' + this.responseText) document.getElementById("set_tautulli_form_button").disabled = false; document.getElementById("set_tautulli_form_button").style.opacity = '1'; return; } if(result.error) { alert(result.message); document.getElementById("set_tautulli_form_button").disabled = false; document.getElementById("set_tautulli_form_button").style.opacity = '1'; } else { get_config(get_cookie('wrapperr-admin')); } } }; xhttp.withCredentials = true; xhttp.open("post", api_url + "set/config"); xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.setRequestHeader("Authorization", "Bearer " + cookie); xhttp.send(tautulli_settings_data); return; } function set_wrapperr_settings() { topFunction(); var html = '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
' var wrapped_start_obj = new Date(wrapped_start); var temp_date = wrapped_start_obj.toLocaleString("sv-SE", { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit" }).replace(" ", "T"); html += '
'; html += '
!
The more unique days in the wrapped period, the more Tautulli API calls. It is recommended to enable "Cache results for later use" to prevent long load times.
'; html += '
'; html += '
'; html += '
'; var wrapped_end_obj = new Date(wrapped_end); var temp_date = wrapped_end_obj.toLocaleString("sv-SE", { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit" }).replace(" ", "T"); html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '' html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
!
Many of the settings here need a clean cache to be applied.
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; // Place content from config document.getElementById("setup").innerHTML = html; document.getElementById("wrapperr_front_page_title").value = wrapperr_front_page_title; document.getElementById("wrapperr_front_page_subtitle").value = wrapperr_front_page_subtitle; document.getElementById("stats_intro_title").value = stats_intro_title; document.getElementById("stats_intro_subtitle").value = stats_intro_subtitle; document.getElementById("stats_outro_title").value = stats_outro_title; document.getElementById("stats_outro_subtitle").value = stats_outro_subtitle; document.getElementById("stats_top_list_length").value = stats_top_list_length; document.getElementById("get_user_movie_stats_title").value = get_user_movie_stats_title; document.getElementById("get_user_movie_stats_subtitle").value = get_user_movie_stats_subtitle; document.getElementById("get_user_movie_stats_subsubtitle").value = get_user_movie_stats_subsubtitle; document.getElementById("get_user_movie_stats_subtitle_one").value = get_user_movie_stats_subtitle_one; document.getElementById("get_user_movie_stats_subsubtitle_one").value = get_user_movie_stats_subsubtitle_one; document.getElementById("get_user_movie_stats_subtitle_none").value = get_user_movie_stats_subtitle_none; document.getElementById("get_user_movie_stats_subsubtitle_none").value = get_user_movie_stats_subsubtitle_none; document.getElementById("get_user_movie_stats_movie_completion_title").value = get_user_movie_stats_movie_completion_title; document.getElementById("get_user_movie_stats_movie_completion_title_plural").value = get_user_movie_stats_movie_completion_title_plural; document.getElementById("get_user_movie_stats_movie_completion_subtitle").value = get_user_movie_stats_movie_completion_subtitle; document.getElementById("get_user_movie_stats_pause_title").value = get_user_movie_stats_pause_title; document.getElementById("get_user_movie_stats_pause_subtitle").value = get_user_movie_stats_pause_subtitle; document.getElementById("get_user_movie_stats_pause_title_one").value = get_user_movie_stats_pause_title_one; document.getElementById("get_user_movie_stats_pause_subtitle_one").value = get_user_movie_stats_pause_subtitle_one; document.getElementById("get_user_movie_stats_pause_title_none").value = get_user_movie_stats_pause_title_none; document.getElementById("get_user_movie_stats_pause_subtitle_none").value = get_user_movie_stats_pause_subtitle_none; document.getElementById("get_user_movie_stats_oldest_title").value = get_user_movie_stats_oldest_title; document.getElementById("get_user_movie_stats_oldest_subtitle").value = get_user_movie_stats_oldest_subtitle; document.getElementById("get_user_movie_stats_oldest_subtitle_pre_1950").value = get_user_movie_stats_oldest_subtitle_pre_1950; document.getElementById("get_user_movie_stats_oldest_subtitle_pre_1975").value = get_user_movie_stats_oldest_subtitle_pre_1975; document.getElementById("get_user_movie_stats_oldest_subtitle_pre_2000").value = get_user_movie_stats_oldest_subtitle_pre_2000; document.getElementById("get_user_movie_stats_spent_title").value = get_user_movie_stats_spent_title; document.getElementById("get_user_show_stats_title").value = get_user_show_stats_title; document.getElementById("get_user_show_stats_subtitle").value = get_user_show_stats_subtitle; document.getElementById("get_user_show_stats_subsubtitle").value = get_user_show_stats_subsubtitle; document.getElementById("get_user_show_stats_subtitle_one").value = get_user_show_stats_subtitle_one; document.getElementById("get_user_show_stats_subsubtitle_one").value = get_user_show_stats_subsubtitle_one; document.getElementById("get_user_show_stats_subtitle_none").value = get_user_show_stats_subtitle_none; document.getElementById("get_user_show_stats_subsubtitle_none").value = get_user_show_stats_subsubtitle_none; document.getElementById("get_user_show_stats_most_played_title").value = get_user_show_stats_most_played_title; document.getElementById("get_user_show_stats_most_played_subtitle").value = get_user_show_stats_most_played_subtitle; document.getElementById("get_user_show_stats_buddy_title").value = get_user_show_stats_buddy_title; document.getElementById("get_user_show_stats_buddy_subtitle").value = get_user_show_stats_buddy_subtitle; document.getElementById("get_user_show_stats_buddy_title_none").value = get_user_show_stats_buddy_title_none; document.getElementById("get_user_show_stats_buddy_subtitle_none").value = get_user_show_stats_buddy_subtitle_none; document.getElementById("get_user_show_stats_spent_title").value = get_user_show_stats_spent_title; document.getElementById("get_user_music_stats_title").value = get_user_music_stats_title; document.getElementById("get_user_music_stats_subtitle").value = get_user_music_stats_subtitle; document.getElementById("get_user_music_stats_subsubtitle").value = get_user_music_stats_subsubtitle; document.getElementById("get_user_music_stats_subtitle_one").value = get_user_music_stats_subtitle_one; document.getElementById("get_user_music_stats_subsubtitle_one").value = get_user_music_stats_subsubtitle_one; document.getElementById("get_user_music_stats_subtitle_none").value = get_user_music_stats_subtitle_none; document.getElementById("get_user_music_stats_subsubtitle_none").value = get_user_music_stats_subsubtitle_none; document.getElementById("get_user_music_stats_spent_title").value = get_user_music_stats_spent_title; document.getElementById("get_user_music_stats_spent_subtitle").value = get_user_music_stats_spent_subtitle; document.getElementById("get_user_music_stats_oldest_album_title").value = get_user_music_stats_oldest_album_title; document.getElementById("get_user_music_stats_oldest_album_subtitle").value = get_user_music_stats_oldest_album_subtitle; document.getElementById("get_year_stats_title").value = get_year_stats_title; document.getElementById("get_year_stats_subtitle").value = get_year_stats_subtitle; document.getElementById("get_year_stats_subsubtitle").value = get_year_stats_subsubtitle; document.getElementById("get_year_stats_movies_duration_title").value = get_year_stats_movies_duration_title; document.getElementById("get_year_stats_shows_duration_title").value = get_year_stats_shows_duration_title; document.getElementById("get_year_stats_music_duration_title").value = get_year_stats_music_duration_title; document.getElementById("get_year_stats_duration_sum_title").value = get_year_stats_duration_sum_title; } function toggle_hidden_form(div_id) { var div = document.getElementById(div_id); if(div.className === "form_shown") { div.classList.remove('form_shown'); div.classList.add('form_hidden'); } else { div.classList.remove('form_hidden'); div.classList.add('form_shown'); } } function set_wrapperr_customization_call() { document.getElementById("set_wrapperr_customization_form_button").disabled = true; document.getElementById("set_wrapperr_customization_form_button").style.opacity = '0.5'; wrapperr_front_page_title = document.getElementById('wrapperr_front_page_title').value; wrapperr_front_page_subtitle = document.getElementById('wrapperr_front_page_subtitle').value; stats_intro_title = document.getElementById('stats_intro_title').value; stats_intro_subtitle = document.getElementById('stats_intro_subtitle').value; stats_outro_title = document.getElementById('stats_outro_title').value; stats_outro_subtitle = document.getElementById('stats_outro_subtitle').value; stats_order_by_plays = document.getElementById('stats_order_by_plays').checked; stats_order_by_duration = document.getElementById('stats_order_by_duration').checked; stats_top_list_length = parseInt(document.getElementById("stats_top_list_length").value); get_user_movie_stats = document.getElementById('get_user_movie_stats').checked; get_user_movie_stats_title = document.getElementById('get_user_movie_stats_title').value; get_user_movie_stats_subtitle = document.getElementById('get_user_movie_stats_subtitle').value; get_user_movie_stats_subsubtitle = document.getElementById('get_user_movie_stats_subsubtitle').value; get_user_movie_stats_subtitle_one = document.getElementById('get_user_movie_stats_subtitle_one').value; get_user_movie_stats_subsubtitle_one = document.getElementById('get_user_movie_stats_subsubtitle_one').value; get_user_movie_stats_subtitle_none = document.getElementById('get_user_movie_stats_subtitle_none').value; get_user_movie_stats_subsubtitle_none = document.getElementById('get_user_movie_stats_subsubtitle_none').value; get_user_movie_stats_top_movie = document.getElementById('get_user_movie_stats_top_movie').value; get_user_movie_stats_top_movie_plural = document.getElementById('get_user_movie_stats_top_movie_plural').value; get_user_movie_stats_movie_completion_title = document.getElementById('get_user_movie_stats_movie_completion_title').value; get_user_movie_stats_movie_completion_title_plural = document.getElementById('get_user_movie_stats_movie_completion_title_plural').value; get_user_movie_stats_movie_completion_subtitle = document.getElementById('get_user_movie_stats_movie_completion_subtitle').value; get_user_movie_stats_pause_title = document.getElementById('get_user_movie_stats_pause_title').value; get_user_movie_stats_pause_subtitle = document.getElementById('get_user_movie_stats_pause_subtitle').value; get_user_movie_stats_pause_title_one = document.getElementById('get_user_movie_stats_pause_title_one').value; get_user_movie_stats_pause_subtitle_one = document.getElementById('get_user_movie_stats_pause_subtitle_one').value; get_user_movie_stats_pause_title_none = document.getElementById('get_user_movie_stats_pause_title_none').value; get_user_movie_stats_pause_subtitle_none = document.getElementById('get_user_movie_stats_pause_subtitle_none').value; get_user_movie_stats_oldest_title = document.getElementById('get_user_movie_stats_oldest_title').value; get_user_movie_stats_oldest_subtitle = document.getElementById('get_user_movie_stats_oldest_subtitle').value; get_user_movie_stats_oldest_subtitle_pre_1950 = document.getElementById('get_user_movie_stats_oldest_subtitle_pre_1950').value; get_user_movie_stats_oldest_subtitle_pre_1975 = document.getElementById('get_user_movie_stats_oldest_subtitle_pre_1975').value; get_user_movie_stats_oldest_subtitle_pre_2000 = document.getElementById('get_user_movie_stats_oldest_subtitle_pre_2000').value; get_user_movie_stats_spent_title = document.getElementById('get_user_movie_stats_spent_title').value; get_user_show_stats = document.getElementById('get_user_show_stats').checked; get_user_show_stats_buddy = document.getElementById('get_user_show_stats_buddy').checked; get_user_show_stats_title = document.getElementById('get_user_show_stats_title').value; get_user_show_stats_subtitle = document.getElementById('get_user_show_stats_subtitle').value; get_user_show_stats_subsubtitle = document.getElementById('get_user_show_stats_subsubtitle').value; get_user_show_stats_subtitle_one = document.getElementById('get_user_show_stats_subtitle_one').value; get_user_show_stats_subsubtitle_one = document.getElementById('get_user_show_stats_subsubtitle_one').value; get_user_show_stats_subtitle_none = document.getElementById('get_user_show_stats_subtitle_none').value; get_user_show_stats_subsubtitle_none = document.getElementById('get_user_show_stats_subsubtitle_none').value; get_user_show_stats_top_show = document.getElementById('get_user_show_stats_top_show').value; get_user_show_stats_top_show_plural = document.getElementById('get_user_show_stats_top_show_plural').value; get_user_show_stats_most_played_title = document.getElementById('get_user_show_stats_most_played_title').value; get_user_show_stats_most_played_subtitle = document.getElementById('get_user_show_stats_most_played_subtitle').value; get_user_show_stats_buddy_title = document.getElementById('get_user_show_stats_buddy_title').value; get_user_show_stats_buddy_subtitle = document.getElementById('get_user_show_stats_buddy_subtitle').value; get_user_show_stats_buddy_title_none = document.getElementById('get_user_show_stats_buddy_title_none').value; get_user_show_stats_buddy_subtitle_none = document.getElementById('get_user_show_stats_buddy_subtitle_none').value; get_user_show_stats_spent_title = document.getElementById('get_user_show_stats_spent_title').value; get_user_music_stats = document.getElementById('get_user_music_stats').checked; get_user_music_stats_title = document.getElementById('get_user_music_stats_title').value; get_user_music_stats_subtitle = document.getElementById('get_user_music_stats_subtitle').value; get_user_music_stats_subsubtitle = document.getElementById('get_user_music_stats_subsubtitle').value; get_user_music_stats_subtitle_one = document.getElementById('get_user_music_stats_subtitle_one').value; get_user_music_stats_subsubtitle_one = document.getElementById('get_user_music_stats_subsubtitle_one').value; get_user_music_stats_subtitle_none = document.getElementById('get_user_music_stats_subtitle_none').value; get_user_music_stats_subsubtitle_none = document.getElementById('get_user_music_stats_subsubtitle_none').value; get_user_music_stats_top_track = document.getElementById('get_user_music_stats_top_track').value; get_user_music_stats_top_track_plural = document.getElementById('get_user_music_stats_top_track_plural').value; get_user_music_stats_top_album_plural = document.getElementById('get_user_music_stats_top_album_plural').value; get_user_music_stats_top_artist_plural = document.getElementById('get_user_music_stats_top_artist_plural').value; get_user_music_stats_spent_title = document.getElementById('get_user_music_stats_spent_title').value; get_user_music_stats_spent_subtitle = document.getElementById('get_user_music_stats_spent_subtitle').value; get_user_music_stats_oldest_album_title = document.getElementById('get_user_music_stats_oldest_album_title').value; get_user_music_stats_oldest_album_subtitle = document.getElementById('get_user_music_stats_oldest_album_subtitle').value; get_year_stats_title = document.getElementById('get_year_stats_title').value; get_year_stats_subtitle = document.getElementById('get_year_stats_subtitle').value; get_year_stats_subsubtitle = document.getElementById('get_year_stats_subsubtitle').value; get_year_stats_movies = document.getElementById('get_year_stats_movies').checked; get_year_stats_movies_title = document.getElementById('get_year_stats_movies_title').value; get_year_stats_movies_duration_title = document.getElementById('get_year_stats_movies_duration_title').value; get_year_stats_shows = document.getElementById('get_year_stats_shows').checked; get_year_stats_shows_title = document.getElementById('get_year_stats_shows_title').value; get_year_stats_shows_duration_title = document.getElementById('get_year_stats_shows_duration_title').value; get_year_stats_music = document.getElementById('get_year_stats_music').checked; get_year_stats_music_title = document.getElementById('get_year_stats_music_title').value; get_year_stats_music_duration_title = document.getElementById('get_year_stats_music_duration_title').value; get_year_stats_leaderboard = document.getElementById('get_year_stats_leaderboard').checked; get_year_stats_leaderboard_numbers = document.getElementById('get_year_stats_leaderboard_numbers').checked; get_year_stats_leaderboard_title = document.getElementById('get_year_stats_leaderboard_title').value; get_year_stats_duration_sum_title = document.getElementById('get_year_stats_duration_sum_title').value; clear_cache = document.getElementById('clear_cache').checked; wrapperr_and = document.getElementById("wrapperr_and").value; wrapperr_play = document.getElementById("wrapperr_play").value; wrapperr_play_plural = document.getElementById("wrapperr_play_plural").value; wrapperr_day = document.getElementById("wrapperr_day").value; wrapperr_day_plural = document.getElementById("wrapperr_day_plural").value; wrapperr_hour = document.getElementById("wrapperr_hour").value; wrapperr_hour_plural = document.getElementById("wrapperr_hour_plural").value; wrapperr_minute = document.getElementById("wrapperr_minute").value; wrapperr_minute_plural = document.getElementById("wrapperr_minute_plural").value; wrapperr_second = document.getElementById("wrapperr_second").value; wrapperr_second_plural = document.getElementById("wrapperr_second_plural").value; wrapperr_sort_plays = document.getElementById("wrapperr_sort_plays").value; wrapperr_sort_duration = document.getElementById("wrapperr_sort_duration").value; wrapperr_customization_form = { "clear_cache" : clear_cache, "data_type" : "wrapperr_customize", "tautulli_config" : [], "wrapperr_data" : {}, "wrapperr_customize" : { "wrapperr_front_page_title" : wrapperr_front_page_title, "wrapperr_front_page_subtitle" : wrapperr_front_page_subtitle, "stats_intro_title" : stats_intro_title, "stats_intro_subtitle" : stats_intro_subtitle, "stats_outro_title" : stats_outro_title, "stats_outro_subtitle" : stats_outro_subtitle, "stats_order_by_plays" : stats_order_by_plays, "stats_order_by_duration" : stats_order_by_duration, "stats_top_list_length" : stats_top_list_length, "get_user_movie_stats" : get_user_movie_stats, "get_user_movie_stats_title" : get_user_movie_stats_title, "get_user_movie_stats_subtitle" : get_user_movie_stats_subtitle, "get_user_movie_stats_subsubtitle" : get_user_movie_stats_subsubtitle, "get_user_movie_stats_subtitle_one" : get_user_movie_stats_subtitle_one, "get_user_movie_stats_subsubtitle_one" : get_user_movie_stats_subsubtitle_one, "get_user_movie_stats_subtitle_none" : get_user_movie_stats_subtitle_none, "get_user_movie_stats_subsubtitle_none" : get_user_movie_stats_subsubtitle_none, "get_user_movie_stats_top_movie" : get_user_movie_stats_top_movie, "get_user_movie_stats_top_movie_plural" : get_user_movie_stats_top_movie_plural, "get_user_movie_stats_movie_completion_title" : get_user_movie_stats_movie_completion_title, "get_user_movie_stats_movie_completion_title_plural" : get_user_movie_stats_movie_completion_title_plural, "get_user_movie_stats_movie_completion_subtitle" : get_user_movie_stats_movie_completion_subtitle, "get_user_movie_stats_pause_title" : get_user_movie_stats_pause_title, "get_user_movie_stats_pause_subtitle" : get_user_movie_stats_pause_subtitle, "get_user_movie_stats_pause_title_one" : get_user_movie_stats_pause_title_one, "get_user_movie_stats_pause_subtitle_one" : get_user_movie_stats_pause_subtitle_one, "get_user_movie_stats_pause_title_none" : get_user_movie_stats_pause_title_none, "get_user_movie_stats_pause_subtitle_none" : get_user_movie_stats_pause_subtitle_none, "get_user_movie_stats_oldest_title" : get_user_movie_stats_oldest_title, "get_user_movie_stats_oldest_subtitle" : get_user_movie_stats_oldest_subtitle, "get_user_movie_stats_oldest_subtitle_pre_1950" : get_user_movie_stats_oldest_subtitle_pre_1950, "get_user_movie_stats_oldest_subtitle_pre_1975" : get_user_movie_stats_oldest_subtitle_pre_1975, "get_user_movie_stats_oldest_subtitle_pre_2000" : get_user_movie_stats_oldest_subtitle_pre_2000, "get_user_movie_stats_spent_title" : get_user_movie_stats_spent_title, "get_user_show_stats" : get_user_show_stats, "get_user_show_stats_buddy" : get_user_show_stats_buddy, "get_user_show_stats_title" : get_user_show_stats_title, "get_user_show_stats_subtitle" : get_user_show_stats_subtitle, "get_user_show_stats_subsubtitle" : get_user_show_stats_subsubtitle, "get_user_show_stats_subtitle_one" : get_user_show_stats_subtitle_one, "get_user_show_stats_subsubtitle_one" : get_user_show_stats_subsubtitle_one, "get_user_show_stats_subtitle_none" : get_user_show_stats_subtitle_none, "get_user_show_stats_subsubtitle_none" : get_user_show_stats_subsubtitle_none, "get_user_show_stats_top_show" : get_user_show_stats_top_show, "get_user_show_stats_top_show_plural" : get_user_show_stats_top_show_plural, "get_user_show_stats_spent_title" : get_user_show_stats_spent_title, "get_user_show_stats_most_played_title" : get_user_show_stats_most_played_title, "get_user_show_stats_most_played_subtitle" : get_user_show_stats_most_played_subtitle, "get_user_show_stats_buddy_title" : get_user_show_stats_buddy_title, "get_user_show_stats_buddy_subtitle" : get_user_show_stats_buddy_subtitle, "get_user_show_stats_buddy_title_none" : get_user_show_stats_buddy_title_none, "get_user_show_stats_buddy_subtitle_none" : get_user_show_stats_buddy_subtitle_none, "get_user_music_stats" : get_user_music_stats, "get_user_music_stats_title" : get_user_music_stats_title, "get_user_music_stats_subtitle" : get_user_music_stats_subtitle, "get_user_music_stats_subsubtitle" : get_user_music_stats_subsubtitle, "get_user_music_stats_subtitle_one" : get_user_music_stats_subtitle_one, "get_user_music_stats_subsubtitle_one" : get_user_music_stats_subsubtitle_one, "get_user_music_stats_subtitle_none" : get_user_music_stats_subtitle_none, "get_user_music_stats_subsubtitle_none" : get_user_music_stats_subsubtitle_none, "get_user_music_stats_top_track" : get_user_music_stats_top_track, "get_user_music_stats_top_track_plural" : get_user_music_stats_top_track_plural, "get_user_music_stats_top_album_plural" : get_user_music_stats_top_album_plural, "get_user_music_stats_top_artist_plural" : get_user_music_stats_top_artist_plural, "get_user_music_stats_spent_title" : get_user_music_stats_spent_title, "get_user_music_stats_spent_subtitle" : get_user_music_stats_spent_subtitle, "get_user_music_stats_oldest_album_title" : get_user_music_stats_oldest_album_title, "get_user_music_stats_oldest_album_subtitle" : get_user_music_stats_oldest_album_subtitle, "get_year_stats_title" : get_year_stats_title, "get_year_stats_subtitle" : get_year_stats_subtitle, "get_year_stats_subsubtitle" : get_year_stats_subsubtitle, "get_year_stats_movies" : get_year_stats_movies, "get_year_stats_movies_title" : get_year_stats_movies_title, "get_year_stats_movies_duration_title" : get_year_stats_movies_duration_title, "get_year_stats_shows" : get_year_stats_shows, "get_year_stats_shows_title" : get_year_stats_shows_title, "get_year_stats_shows_duration_title" : get_year_stats_shows_duration_title, "get_year_stats_music" : get_year_stats_music, "get_year_stats_music_title" : get_year_stats_music_title, "get_year_stats_music_duration_title" : get_year_stats_music_duration_title, "get_year_stats_leaderboard" : get_year_stats_leaderboard, "get_year_stats_leaderboard_numbers" : get_year_stats_leaderboard_numbers, "get_year_stats_leaderboard_title" : get_year_stats_leaderboard_title, "get_year_stats_duration_sum_title" : get_year_stats_duration_sum_title, "wrapperr_and" : wrapperr_and, "wrapperr_play" : wrapperr_play, "wrapperr_play_plural" : wrapperr_play_plural, "wrapperr_day" : wrapperr_day, "wrapperr_day_plural" : wrapperr_day_plural, "wrapperr_hour" : wrapperr_hour, "wrapperr_hour_plural" : wrapperr_hour_plural, "wrapperr_minute" : wrapperr_minute, "wrapperr_minute_plural" : wrapperr_minute_plural, "wrapperr_second" : wrapperr_second, "wrapperr_second_plural" : wrapperr_second_plural, "wrapperr_sort_plays" : wrapperr_sort_plays, "wrapperr_sort_duration" : wrapperr_sort_duration } }; var wrapperr_customization_data = JSON.stringify(wrapperr_customization_form); // Debug line // console.log(wrapperr_customization_data); var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4) { try { var result= JSON.parse(this.responseText); } catch(error) { alert('Failed to parse API response.'); console.log('Failed to parse API response. Response: ' + this.responseText); document.getElementById("set_wrapperr_customization_form_button").disabled = false; document.getElementById("set_wrapperr_customization_form_button").style.opacity = '1'; return; } if(result.error) { alert(result.message); document.getElementById("set_wrapperr_customization_form_button").disabled = false; document.getElementById("set_wrapperr_customization_form_button").style.opacity = '1'; } else { get_config(get_cookie('wrapperr-admin')); } } }; xhttp.withCredentials = true; xhttp.open("post", api_url + "set/config"); xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.setRequestHeader("Authorization", "Bearer " + cookie); xhttp.send(wrapperr_customization_data); return; } function caching_menu() { var html = '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; var min_day_length = 1; if(tautulli.length > 1) { min_day_length = tautulli.length + 1 } html += `

Caching Tautulli data for later use to prevent long load times.

When you configured a wrapped period, you set the number of days to process. Each unique day in that period is a new API request to Tautulli, which holds the data which needs processing.

Wrapperr can cache data from Tautulli to decrease load times, but it needs to be loaded once. If the time frame is long this can take several minutes. Instead of loading your own stats, you can perform caching here. Afterward, everything is cached and saved. Only additional/new data is downloaded on future Wrapperr usage.

The loop used on this page ensures the cache is saved after a certain amount of days are downloaded. If the value below is set to 50, it will save the cache for every 50 days downloaded.

`; document.getElementById("setup").innerHTML = html; } function add_to_cache_log(log_message, state, color) { var today = new Date(); var time = pad_number(today.getHours(), 2) + ":" + pad_number(today.getMinutes(), 2) + ":" + pad_number(today.getSeconds(), 2); if(state) { style = 'color:' + color + ';'; } else { style = ''; } var tablerow = ` ` + time + ` ` + log_message + ` `; document.getElementById('cache_results_body').innerHTML += tablerow } function cache_initiate() { var days = parseInt(document.getElementById('days').value); var html = `

Caching log:

Time Message
`; document.getElementById('cache').innerHTML = html; add_to_cache_log('Creating new cache request. Maximum ' + days + ' days.') get_stats(days); } function cache_log(days, result, complete) { if(result) { add_to_cache_log('Completed caching with a maximum of ' + days + ' days.', false, ''); } else { add_to_cache_log('Error caching ' + days + ' days. Stopping.', true, 'var(--red)'); document.getElementById('loading_icon').style.display = "none"; document.getElementById("cache_button").disabled = false; document.getElementById("cache_button").style.opacity = '1'; } if(complete) { add_to_cache_log('Finished caching request.', true, 'var(--green)'); document.getElementById('loading_icon').style.display = "none"; document.getElementById("cache_button").disabled = false; document.getElementById("cache_button").style.opacity = '1'; } else { add_to_cache_log('Requesting new cache from Wrapperr. Maximum ' + days + ' days.', false, ''); } var cache_results = document.getElementById("cache_results"); cache_results.scrollTop = cache_results.scrollHeight; } function get_stats(days) { document.getElementById("cache_button").disabled = true; document.getElementById("cache_button").style.opacity = '0.5'; stats_form = { "caching" : true, "cache_limit" : days }; var stats_data = JSON.stringify(stats_form); var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4) { try { var result= JSON.parse(this.responseText); } catch(error) { if(this.responseText.includes('Maximum execution time of')) { cache_log(days, false, true); document.getElementById("cache_button").disabled = false; document.getElementById("cache_button").style.opacity = '1'; alert('PHP runtime was exceeded and stopped execution. Lower days cached to prevent this.'); console.log('Failed to parse API response. Error: ' + this.responseText); } else { cache_log(days, false, true); alert('Failed to parse API response.'); console.log('Failed to parse API response. Error: ' + this.responseText); document.getElementById("cache_button").disabled = false; document.getElementById("cache_button").style.opacity = '1'; } return; } if(result.error) { alert(result.message); cache_log(days, false, true); } else { if(!result.data) { cache_log(days, true, result.data); get_stats(days); } else { cache_log(days, true, result.data); } } } }; xhttp.withCredentials = true; xhttp.open("post", api_url + "get/statistics", ); xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.setRequestHeader("Authorization", "Bearer " + cookie); xhttp.send(stats_data); return; } function log_menu() { var html = '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += `

Wrapperr log file

Date Time Message
`; document.getElementById("setup").innerHTML = html; get_log(); } function get_log() { document.getElementById("log_button").disabled = true; document.getElementById("log_button").style.opacity = '0.5'; log_data_form = {}; var log_data_data = JSON.stringify(log_form); var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4) { try { var result= JSON.parse(this.responseText); } catch(error) { alert('Failed to parse API response.'); console.log('Failed to parse API response. Error: ' + this.responseText); document.getElementById("log_button").disabled = false; document.getElementById("log_button").style.opacity = '1'; return; } if(result.error) { document.getElementById("log_button").disabled = false; document.getElementById("log_button").style.opacity = '1'; alert(result.message); } else { document.getElementById("log_button").disabled = false; document.getElementById("log_button").style.opacity = '1'; log_form(result.data, result.limit); } } }; xhttp.withCredentials = true; xhttp.open("post", api_url + "get/log", ); xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.setRequestHeader("Authorization", "Bearer " + cookie); xhttp.send(log_data_data); return; } function log_form(log_lines_array, limit) { var log_table = ` Date Time Message `; for(index = 0; index < log_lines_array.length; index++) { var tablerow = ` ` + log_lines_array[index].date + ` ` + log_lines_array[index].time + ` ` + log_lines_array[index].message + ` `; log_table += tablerow } document.getElementById('log_results_body').innerHTML = log_table document.getElementById('log_result_text').innerHTML = 'Retrieved last ' + limit + ' lines.'; var log_results = document.getElementById("log_results"); log_results.scrollTop = log_results.scrollHeight; } function test_tautulli_connection(tautulli_id) { document.getElementById("test_connection_" + tautulli_id).disabled = true; document.getElementById("test_connection_" + tautulli_id).style.opacity = '0.5'; var button = document.getElementById('test_connection_' + tautulli_id); button.style.backgroundColor = 'lightgrey'; https_temp = document.getElementById('tautulli_https_' + tautulli_id).checked; ip_temp = document.getElementById('tautulli_ip_' + tautulli_id).value; root_temp = document.getElementById('tautulli_root_' + tautulli_id).value; port_temp = parseInt(document.getElementById('tautulli_port_' + tautulli_id).value); api_temp = document.getElementById('tautulli_apikey_' + tautulli_id).value; config_form = {"tautulli_https" : https_temp, "tautulli_apikey" : api_temp, "tautulli_port" : port_temp, "tautulli_root" : root_temp, "tautulli_ip" : ip_temp}; var config_data = JSON.stringify(config_form); var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4) { try { var result= JSON.parse(this.responseText); } catch(error) { console.log('Failed to parse API response. Response: ' + this.responseText) alert('Failed to parse API response.'); button.style.backgroundColor = 'var(--red)'; document.getElementById("test_connection_" + tautulli_id).disabled = false; document.getElementById("test_connection_" + tautulli_id).style.opacity = '1'; return; } if(result.error) { button.style.backgroundColor = 'var(--red)'; document.getElementById("test_connection_" + tautulli_id).disabled = false; document.getElementById("test_connection_" + tautulli_id).style.opacity = '1'; alert(result.message); return } if(result.data) { button.style.backgroundColor = 'var(--green)'; document.getElementById("test_connection_" + tautulli_id).disabled = false; document.getElementById("test_connection_" + tautulli_id).style.opacity = '1'; } else { button.style.backgroundColor = 'var(--red)'; document.getElementById("test_connection_" + tautulli_id).disabled = false; document.getElementById("test_connection_" + tautulli_id).style.opacity = '1'; } } }; xhttp.withCredentials = true; xhttp.open("post", api_url + 'get/tautulli-connection'); xhttp.send(config_data); } function get_wrapper_version() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4) { try { var result= JSON.parse(this.responseText); } catch(error) { console.log('Failed to parse Wrapperr version. Response: ' + this.responseText) alert("Failed to parse API response"); return; } if(!result.error) { document.getElementById('github_link').innerHTML = 'GitHub (' + result.wrapperr_version + ')'; if(result.application_name && result.application_name !== '') { document.getElementById('application_name').innerHTML = result.application_name + ' Setup'; document.title = result.application_name; } if(result.wrapperr_root != "") { api_url = window.location.origin + "/" + result.wrapperr_root + "/api/"; console.log("URL: " + api_url) } get_admin_state(); } } else if(this.readyState == 4 && this.status !== 200) { var html = '

' + this.status + ' Error

'; html += '

The API did not respond correctly.

'; document.getElementById("setup").innerHTML = html; } }; xhttp.withCredentials = true; // Get the root without "/admin" root = window.location.pathname.replace('/admin', '') // Maybe add trailing slash depending on the end of "window.location.origin" var trailingslash = "" if(window.location.origin.charAt(window.location.origin.length-1) != "/") { trailingslash = "/" } // Reach the API to get URL base xhttp.open("post", window.location.origin + "/" + root + trailingslash + "api/get/wrapperr-version"); xhttp.send(); return; } // Get admin configuration state function get_admin_state() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4) { try { var result= JSON.parse(this.responseText); } catch(error) { console.log('Failed to parse API response. Response: ' + this.responseText) return; } if(result.error) { console.log(result.message); } else if(!result.data) { first_time = true; set_password_form(); } else { cookie = get_cookie('wrapperr-admin'); if(cookie) { validate_cookie_admin(cookie); } else { login_menu(); } } } }; xhttp.withCredentials = true; xhttp.open("post", api_url + "get/admin-state"); xhttp.send(); return; } // Validate admin login function validate_cookie_admin(cookie) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4) { try { var result= JSON.parse(this.responseText); } catch(error) { console.log('Failed to parse API response. Response: ' + this.responseText) } if(result.error) { set_cookie("wrapperr-admin", "", 1); login_menu(); document.getElementById("password_login_form_error").innerHTML = result.message; } else { get_config(get_cookie('wrapperr-admin')); } } }; xhttp.withCredentials = true; xhttp.open("post", api_url + "validate/admin"); xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.setRequestHeader("Authorization", "Bearer " + cookie); xhttp.send(); return; } // Get config for admin to configure function get_config(cookie) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4) { try { var result = JSON.parse(this.responseText); } catch { alert("Failed to parse API response."); return; } if(result.error) { alert(result.message); location.reload(); } else { tautulli = result.data.tautulli_config; timezone = result.data.timezone; create_share_links = result.data.create_share_links; plex_auth = result.data.plex_auth; use_cache = result.data.use_cache; use_logs = result.data.use_logs; clientID = result.data.clientID; wrapperr_root = result.data.wrapperr_root; application_name_str = result.data.application_name; application_url_str = result.data.application_url; winter_theme = result.data.winter_theme; wrapped_start = new Date(0); wrapped_start.setUTCSeconds(result.data.wrapped_start); wrapped_end = new Date(0); wrapped_end.setUTCSeconds(result.data.wrapped_end); stats_order_by_plays = result.data.wrapperr_customize.stats_order_by_plays; stats_order_by_duration = result.data.wrapperr_customize.stats_order_by_duration; wrapperr_front_page_title = result.data.wrapperr_customize.wrapperr_front_page_title; wrapperr_front_page_subtitle = result.data.wrapperr_customize.wrapperr_front_page_subtitle; stats_intro_title = result.data.wrapperr_customize.stats_intro_title; stats_intro_subtitle = result.data.wrapperr_customize.stats_intro_subtitle; stats_outro_title = result.data.wrapperr_customize.stats_outro_title; stats_outro_subtitle = result.data.wrapperr_customize.stats_outro_subtitle; stats_top_list_length = result.data.wrapperr_customize.stats_top_list_length; get_user_movie_stats = result.data.wrapperr_customize.get_user_movie_stats; get_user_movie_stats_title = result.data.wrapperr_customize.get_user_movie_stats_title; get_user_movie_stats_subtitle = result.data.wrapperr_customize.get_user_movie_stats_subtitle; get_user_movie_stats_subsubtitle = result.data.wrapperr_customize.get_user_movie_stats_subsubtitle; get_user_movie_stats_subtitle_one = result.data.wrapperr_customize.get_user_movie_stats_subtitle_one; get_user_movie_stats_subsubtitle_one = result.data.wrapperr_customize.get_user_movie_stats_subsubtitle_one; get_user_movie_stats_subtitle_none = result.data.wrapperr_customize.get_user_movie_stats_subtitle_none; get_user_movie_stats_subsubtitle_none = result.data.wrapperr_customize.get_user_movie_stats_subsubtitle_none; get_user_movie_stats_top_movie = result.data.wrapperr_customize.get_user_movie_stats_top_movie; get_user_movie_stats_top_movie_plural = result.data.wrapperr_customize.get_user_movie_stats_top_movie_plural; get_user_movie_stats_movie_completion_title = result.data.wrapperr_customize.get_user_movie_stats_movie_completion_title; get_user_movie_stats_movie_completion_title_plural = result.data.wrapperr_customize.get_user_movie_stats_movie_completion_title_plural; get_user_movie_stats_movie_completion_subtitle = result.data.wrapperr_customize.get_user_movie_stats_movie_completion_subtitle; get_user_movie_stats_pause_title = result.data.wrapperr_customize.get_user_movie_stats_pause_title; get_user_movie_stats_pause_subtitle = result.data.wrapperr_customize.get_user_movie_stats_pause_subtitle; get_user_movie_stats_pause_title_one = result.data.wrapperr_customize.get_user_movie_stats_pause_title_one; get_user_movie_stats_pause_subtitle_one = result.data.wrapperr_customize.get_user_movie_stats_pause_subtitle_one; get_user_movie_stats_pause_title_none = result.data.wrapperr_customize.get_user_movie_stats_pause_title_none; get_user_movie_stats_pause_subtitle_none = result.data.wrapperr_customize.get_user_movie_stats_pause_subtitle_none; get_user_movie_stats_oldest_title = result.data.wrapperr_customize.get_user_movie_stats_oldest_title; get_user_movie_stats_oldest_subtitle = result.data.wrapperr_customize.get_user_movie_stats_oldest_subtitle; get_user_movie_stats_oldest_subtitle_pre_1950 = result.data.wrapperr_customize.get_user_movie_stats_oldest_subtitle_pre_1950; get_user_movie_stats_oldest_subtitle_pre_1975 = result.data.wrapperr_customize.get_user_movie_stats_oldest_subtitle_pre_1975; get_user_movie_stats_oldest_subtitle_pre_2000 = result.data.wrapperr_customize.get_user_movie_stats_oldest_subtitle_pre_2000; get_user_movie_stats_spent_title = result.data.wrapperr_customize.get_user_movie_stats_spent_title; get_user_show_stats = result.data.wrapperr_customize.get_user_show_stats; get_user_show_stats_buddy = result.data.wrapperr_customize.get_user_show_stats_buddy; get_user_show_stats_title = result.data.wrapperr_customize.get_user_show_stats_title; get_user_show_stats_subtitle = result.data.wrapperr_customize.get_user_show_stats_subtitle; get_user_show_stats_subsubtitle = result.data.wrapperr_customize.get_user_show_stats_subsubtitle; get_user_show_stats_subtitle_one = result.data.wrapperr_customize.get_user_show_stats_subtitle_one; get_user_show_stats_subsubtitle_one = result.data.wrapperr_customize.get_user_show_stats_subsubtitle_one; get_user_show_stats_subtitle_none = result.data.wrapperr_customize.get_user_show_stats_subtitle_none; get_user_show_stats_subsubtitle_none = result.data.wrapperr_customize.get_user_show_stats_subsubtitle_none; get_user_show_stats_top_show = result.data.wrapperr_customize.get_user_show_stats_top_show; get_user_show_stats_top_show_plural = result.data.wrapperr_customize.get_user_show_stats_top_show_plural; get_user_show_stats_spent_title = result.data.wrapperr_customize.get_user_show_stats_spent_title; get_user_show_stats_most_played_title = result.data.wrapperr_customize.get_user_show_stats_most_played_title; get_user_show_stats_most_played_subtitle = result.data.wrapperr_customize.get_user_show_stats_most_played_subtitle; get_user_show_stats_buddy_title = result.data.wrapperr_customize.get_user_show_stats_buddy_title; get_user_show_stats_buddy_subtitle = result.data.wrapperr_customize.get_user_show_stats_buddy_subtitle; get_user_show_stats_buddy_title_none = result.data.wrapperr_customize.get_user_show_stats_buddy_title_none; get_user_show_stats_buddy_subtitle_none = result.data.wrapperr_customize.get_user_show_stats_buddy_subtitle_none; get_user_music_stats = result.data.wrapperr_customize.get_user_music_stats; get_user_music_stats_title = result.data.wrapperr_customize.get_user_music_stats_title; get_user_music_stats_subtitle = result.data.wrapperr_customize.get_user_music_stats_subtitle; get_user_music_stats_subsubtitle = result.data.wrapperr_customize.get_user_music_stats_subsubtitle; get_user_music_stats_subtitle_one = result.data.wrapperr_customize.get_user_music_stats_subtitle_one; get_user_music_stats_subsubtitle_one = result.data.wrapperr_customize.get_user_music_stats_subsubtitle_one; get_user_music_stats_subtitle_none = result.data.wrapperr_customize.get_user_music_stats_subtitle_none; get_user_music_stats_subsubtitle_none = result.data.wrapperr_customize.get_user_music_stats_subsubtitle_none; get_user_music_stats_top_track = result.data.wrapperr_customize.get_user_music_stats_top_track; get_user_music_stats_top_track_plural = result.data.wrapperr_customize.get_user_music_stats_top_track_plural; get_user_music_stats_top_album_plural = result.data.wrapperr_customize.get_user_music_stats_top_album_plural; get_user_music_stats_top_artist_plural = result.data.wrapperr_customize.get_user_music_stats_top_artist_plural; get_user_music_stats_spent_title = result.data.wrapperr_customize.get_user_music_stats_spent_title; get_user_music_stats_spent_subtitle = result.data.wrapperr_customize.get_user_music_stats_spent_subtitle; get_user_music_stats_oldest_album_title = result.data.wrapperr_customize.get_user_music_stats_oldest_album_title; get_user_music_stats_oldest_album_subtitle = result.data.wrapperr_customize.get_user_music_stats_oldest_album_subtitle; get_year_stats_title = result.data.wrapperr_customize.get_year_stats_title; get_year_stats_subtitle = result.data.wrapperr_customize.get_year_stats_subtitle; get_year_stats_subsubtitle = result.data.wrapperr_customize.get_year_stats_subsubtitle; get_year_stats_movies = result.data.wrapperr_customize.get_year_stats_movies; get_year_stats_movies_title = result.data.wrapperr_customize.get_year_stats_movies_title; get_year_stats_movies_duration_title = result.data.wrapperr_customize.get_year_stats_movies_duration_title; get_year_stats_shows = result.data.wrapperr_customize.get_year_stats_shows; get_year_stats_shows_title = result.data.wrapperr_customize.get_year_stats_shows_title; get_year_stats_shows_duration_title = result.data.wrapperr_customize.get_year_stats_shows_duration_title; get_year_stats_music = result.data.wrapperr_customize.get_year_stats_music; get_year_stats_music_title = result.data.wrapperr_customize.get_year_stats_music_title; get_year_stats_music_duration_title = result.data.wrapperr_customize.get_year_stats_music_duration_title; get_year_stats_leaderboard = result.data.wrapperr_customize.get_year_stats_leaderboard; get_year_stats_leaderboard_numbers = result.data.wrapperr_customize.get_year_stats_leaderboard_numbers; get_year_stats_leaderboard_title = result.data.wrapperr_customize.get_year_stats_leaderboard_title; get_year_stats_duration_sum_title = result.data.wrapperr_customize.get_year_stats_duration_sum_title; wrapperr_and = result.data.wrapperr_customize.wrapperr_and; wrapperr_play = result.data.wrapperr_customize.wrapperr_play; wrapperr_play_plural = result.data.wrapperr_customize.wrapperr_play_plural; wrapperr_day = result.data.wrapperr_customize.wrapperr_day; wrapperr_day_plural = result.data.wrapperr_customize.wrapperr_day_plural; wrapperr_hour = result.data.wrapperr_customize.wrapperr_hour; wrapperr_hour_plural = result.data.wrapperr_customize.wrapperr_hour_plural; wrapperr_minute = result.data.wrapperr_customize.wrapperr_minute; wrapperr_minute_plural = result.data.wrapperr_customize.wrapperr_minute_plural; wrapperr_second = result.data.wrapperr_customize.wrapperr_second; wrapperr_second_plural = result.data.wrapperr_customize.wrapperr_second_plural; wrapperr_sort_plays = result.data.wrapperr_customize.wrapperr_sort_plays; wrapperr_sort_duration = result.data.wrapperr_customize.wrapperr_sort_duration; username = result.username; admin_menu(); } } }; xhttp.withCredentials = true; xhttp.open("post", api_url + "get/config"); xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.setRequestHeader("Authorization", "Bearer " + cookie); xhttp.send(); }