function time_days(seconds_input) {
var seconds = Number(seconds_input);
var days = seconds * 1.15741E-5;
var hours = String(days).split(".");
var hours_str = "0." + hours[1];
var hours_int = Number(hours_str) * 24.0;
var minutes = String(hours_int).split(".");
var minutes_str = "0." + minutes[1];
var minutes_int = Number(minutes_str) * 60.0;
var days_form = String(days).split(".");
var hours_form = String(hours_int).split(".");
var minutes_form = String(minutes_int).split(".");
var final = [Number(days_form[0]), Number(hours_form[0]), Number(minutes_form[0])];
return final;
}
function time_hours(seconds_input) {
var seconds = Number(seconds_input);
var hours_int = Number(seconds) * 0.0002777778;
var minutes = String(hours_int).split(".");
var minutes_str = "0." + minutes[1];
var minutes_int = Number(minutes_str) * 60.0;
var hours_form = String(hours_int).split(".");
var minutes_form = String(minutes_int).split(".");
var final = [Number(hours_form[0]), Number(minutes_form[0])];
return final;
}
function makeRequest (method, url, data) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open(method, url);
xhr.onload = function () {
if (this.status >= 200 && this.status < 300) {
resolve(xhr.response);
} else {
reject({
status: this.status,
statusText: xhr.statusText
});
}
};
xhr.onerror = function () {
reject({
status: this.status,
statusText: xhr.statusText
});
};
if(method=="POST" && data){
xhr.send(data);
}else{
xhr.send();
}
});
}
function topFunction() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}
function login_menu() {
topFunction();
var html = '
';
document.getElementById("setup").innerHTML = html;
}
function set_password(back) {
topFunction();
var html = '';
document.getElementById("setup").innerHTML = html;
}
function set_tautulli(back) {
topFunction();
if(!back) {
if(document.getElementById('password').value == document.getElementById('password_2').value) {
password = document.getElementById('password').value;
} else {
alert("The passwords must match.");
return false;
}
}
var html = '';
html += '';
html += '
';
html += '';
document.getElementById("setup").innerHTML = html;
}
function set_tautulli_details(back) {
topFunction();
if(!back) {
tautulli_apikey = document.getElementById('tautulli_apikey').value;
tautulli_ip = document.getElementById('tautulli_ip').value;
tautulli_port = document.getElementById('tautulli_port').value;
tautulli_length = document.getElementById('tautulli_length').value;
tautulli_root = document.getElementById('tautulli_root').value;
ssl = document.getElementById('ssl').checked;
library_id_movies = document.getElementById('library_id_movies').value;
library_id_shows = document.getElementById('library_id_shows').value;
}
var html = '';
html += '';
html += '
';
html += '';
document.getElementById("setup").innerHTML = html;
}
function test_tautulli_connection() {
var button = document.getElementById('test_connection');
button.style.backgroundColor = 'lightgrey';
ssl_temp = document.getElementById('ssl').checked;
ip_temp = document.getElementById('tautulli_ip').value;
root_temp = document.getElementById('tautulli_root').value;
port_temp = document.getElementById('tautulli_port').value;
api_temp = document.getElementById('tautulli_apikey').value;
if(ssl_temp) {
var prefix = 'https://';
} else {
var prefix = 'http://';
}
if(root_temp == "") {
var suffix = '';
} else {
var suffix = '/' + root_temp + '/';
}
if(port_temp == "") {
url = prefix + ip_temp + suffix + '/api/v2';
} else {
url = prefix + ip_temp + ':' + port_temp + suffix + '/api/v2';
}
config_form = {"url" : url, "ssl" : ssl_temp, "apikey" : api_temp};
var config_data = JSON.stringify(config_form);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var result = JSON.parse(this.responseText);
if(!result.error) {
button.style.backgroundColor = '#79A04F';
} else {
button.style.backgroundColor = '#F1909C';
}
}
};
xhttp.withCredentials = true;
xhttp.open("post", 'api/get_connection.php');
xhttp.send(config_data);
}
function set_tautulli_last(back) {
if(!back) {
wrapped_start = new Date(document.getElementById('wrapped_start').value);
wrapped_end = new Date(document.getElementById('wrapped_end').value);
if(wrapped_end < wrapped_start) {
alert("The wrapped end period must be later than the wrapped start period.");
return;
}
get_user_movie_stats = document.getElementById('get_user_movie_stats').checked;
get_user_show_stats = document.getElementById('get_user_show_stats').checked;
get_user_show_buddy = document.getElementById('get_user_show_buddy').checked;
get_year_stats = document.getElementById('get_year_stats').checked;
use_cache = document.getElementById('use_cache').checked;
cache_age_limit = document.getElementById('cache_age_limit').value;
set_config();
}
}