2021-03-08 18:45:06 +00:00
function get _stats ( ) {
var results ;
var functions ;
var loading _icon = document . getElementById ( "loading_icon" ) ;
2020-12-19 16:10:59 +00:00
2021-03-08 18:45:06 +00:00
var p _identity = document . getElementById ( "p_identity" ) . value ;
2020-12-19 16:10:59 +00:00
2021-03-08 18:45:06 +00:00
stats _form = {
2021-10-07 16:44:27 +00:00
"p_identity" : p _identity . trim ( ) ,
"caching" : "False"
2021-03-08 18:45:06 +00:00
} ;
2020-12-19 16:10:59 +00:00
2021-03-08 18:45:06 +00:00
var stats _data = JSON . stringify ( stats _form ) ;
2020-12-19 16:10:59 +00:00
2021-03-08 18:45:06 +00:00
var xhttp = new XMLHttpRequest ( ) ;
xhttp . onreadystatechange = function ( ) {
if ( this . readyState == 4 && this . status == 200 ) {
2021-10-07 16:44:27 +00:00
try {
var result = JSON . parse ( this . responseText ) ;
if ( result . error ) {
loading _icon . style . display = "none" ;
search _button ( "SEARCH" ) ;
document . getElementById ( 'results_error' ) . innerHTML = '<p style="color:inherit; text-shadow: none;">' + result . message + '</p>' ;
} else {
load _page ( this . responseText ) ;
}
} catch ( error ) {
document . getElementById ( 'results_error' ) . innerHTML = '<p style="color:inherit; text-shadow: none;">' + "API response can't be parsed." + '</p>' ;
console . log ( 'Error: ' + error ) ;
console . log ( this . responseText ) ;
loading _icon . style . display = "none" ;
}
2021-03-08 18:45:06 +00:00
}
} ;
xhttp . withCredentials = true ;
xhttp . open ( "post" , "api/get_stats.php" ) ;
xhttp . send ( stats _data ) ;
2020-12-19 16:10:59 +00:00
2021-03-08 18:45:06 +00:00
loading _icon . style . display = "inline" ;
}
2020-12-19 16:10:59 +00:00
2020-12-22 16:27:30 +00:00
function load _page ( data ) {
results = JSON . parse ( data ) ;
2020-12-19 16:10:59 +00:00
2021-03-08 18:45:06 +00:00
if ( results . error ) {
2020-12-19 16:10:59 +00:00
$ ( '#results_error' ) . html ( results . message ) ;
2020-12-22 16:27:30 +00:00
loading _icon . style . display = "none" ;
search _button ( "SEARCH" ) ;
2021-03-13 22:40:46 +00:00
return
2020-12-19 16:10:59 +00:00
}
var search _box = document . getElementById ( "search_input" ) ;
2021-03-08 18:45:06 +00:00
var login _content = document . getElementById ( "login_content" ) ;
2021-03-12 22:45:44 +00:00
var footer = document . getElementById ( "footer" ) ;
2020-12-19 16:10:59 +00:00
search _box . style . display = "none" ;
2021-03-08 18:45:06 +00:00
login _content . style . display = "none" ;
2021-03-12 22:45:44 +00:00
footer . style . display = "none" ;
2021-03-08 18:45:06 +00:00
load _introduction ( ) ;
2020-12-19 16:10:59 +00:00
2021-03-08 18:45:06 +00:00
if ( ! results . user . user _movies . error && functions . get _user _movie _stats ) {
load _movies ( ) ;
}
2021-10-01 23:21:18 +00:00
2021-03-08 18:45:06 +00:00
if ( ! results . user . user _shows . error && functions . get _user _show _stats ) {
load _shows ( ) ;
}
2021-10-01 23:21:18 +00:00
if ( ! results . user . user _music . error && functions . get _user _music _stats ) {
load _music ( ) ;
}
2021-03-08 18:45:06 +00:00
2021-10-01 23:21:18 +00:00
if ( ! results . year _stats . error && ( functions . get _year _stats _movies || functions . get _year _stats _shows || functions . get _year _stats _music ) ) {
2021-03-08 18:45:06 +00:00
load _users ( ) ;
}
2020-12-19 16:10:59 +00:00
2021-03-08 18:45:06 +00:00
load _outro ( ) ;
}
//INTRODUCTION
function load _introduction ( ) {
var text = "" ;
text += "<div class='boks' style='width: 100%; padding-bottom: 15em; padding-top: 15em; height:auto; background-color:#D2A3A4;'>" ;
2020-12-19 16:10:59 +00:00
2020-12-23 13:17:10 +00:00
text += "<div class='boks3'>" ;
2021-03-08 18:45:06 +00:00
2020-12-23 13:17:10 +00:00
text += "<div class='boks2'>" ;
2021-03-08 18:45:06 +00:00
text += '<img src="assets/img/finished-illustration.svg" style="width:100%; ">' ;
text += "</div>" ;
2020-12-19 16:10:59 +00:00
2021-03-08 18:45:06 +00:00
text += "<div class='boks2'>" ;
text += "<br>" ;
text += "<h1 style='font-size:3em; display: block;'>Hey there, " + results . user . name + "!</h1>" ;
text += "<br><br><br><br>" ;
text += "<h2>New year, new page of statistics...</h2>" ;
text += "</div>" ;
text += "</div>" ;
text += "</div>" ;
document . getElementById ( "search_results" ) . innerHTML += text ;
}
//MOVIES
function load _movies ( ) {
var text = "" ;
if ( results . user . user _movies . data . movies . length > 1 ) {
text += "<div class='boks' style='height: auto !important; width: 100%; padding-bottom: 25em; padding-top: 25em; height:10em; background-color:#B9A3D2;'>" ;
text += "<div class='boks3'>" ;
2021-08-11 16:07:05 +00:00
text += "<h1>Movies!</h1>" ;
2021-03-08 18:45:06 +00:00
text += "<br><br><br>" ;
text += "<h2>You watched " + results . user . user _movies . data . movies . length + " movies. That's a lot of movies!</h2><p>(or not, I am pre-programmed to say that)</p>"
text += "<br><br>" ;
text += "</div>" ;
text += "<div class='boks3'>" ;
2021-03-13 22:40:46 +00:00
2021-03-08 18:45:06 +00:00
text += "<div class='boks2'>" ;
2021-10-01 23:21:18 +00:00
text += top _list ( results . user . user _movies . data . movies , "Your top movies" , false , true ) ;
2020-12-23 13:17:10 +00:00
text += "</div>" ;
2021-03-09 23:41:48 +00:00
text += "<div class='boks2' style='padding: 0;'>" ;
text += "<div class='boks2'>" ;
2021-03-13 22:40:46 +00:00
text += completion _movie ( results . user . user _movies . data . user _movie _finishing _percent , false ) ;
2020-12-23 13:17:10 +00:00
text += "</div>" ;
2021-03-09 23:41:48 +00:00
text += "<div class='boks2'>" ;
2021-03-13 22:40:46 +00:00
text += paused _movie ( results . user . user _movies . data . user _movie _most _paused , false ) ;
2020-12-23 13:17:10 +00:00
text += "</div>" ;
2021-03-09 23:41:48 +00:00
text += "<div class='boks2'>" ;
2021-03-13 22:40:46 +00:00
text += oldest _movie ( results . user . user _movies . data . user _movie _oldest ) ;
2020-12-23 13:17:10 +00:00
text += "</div>" ;
2021-03-09 23:41:48 +00:00
var sum = 0 ;
for ( i = 0 ; ( i < results . user . user _movies . data . movies . length ) ; i ++ ) {
sum += results . user . user _movies . data . movies [ i ] . duration ;
}
2021-03-13 22:40:46 +00:00
2021-03-09 23:41:48 +00:00
text += "<div class='boks2'>" ;
2021-10-05 13:34:30 +00:00
text += you _spent ( sum , 'movies' , 'watching' ) ;
2021-03-09 23:41:48 +00:00
text += "</div>" ;
2020-12-23 13:17:10 +00:00
text += "</div>" ;
2021-03-08 18:45:06 +00:00
text += "</div>" ;
2020-12-23 13:17:10 +00:00
text += "</div>" ;
2020-12-19 16:10:59 +00:00
2021-03-08 18:45:06 +00:00
} else if ( results . user . user _movies . data . movies . length == 1 ) {
2020-12-23 13:17:10 +00:00
2021-03-08 18:45:06 +00:00
text += "<div class='boks' style='height: auto !important; width: 100%; padding-bottom: 25em; padding-top: 25em; height:10em; background-color:#B9A3D2;'>" ;
2020-12-23 13:17:10 +00:00
2021-03-08 18:45:06 +00:00
text += "<div class='boks3'>" ;
2021-08-11 16:07:05 +00:00
text += "<h1>Movies!</h1>" ;
2021-03-08 18:45:06 +00:00
text += "<br><br><br>" ;
text += "<h2>You watched " + results . user . user _movies . data . movies . length + " movie. You know what you like!</h2><p>(at least you tried it out)</p>" ;
text += "<br><br>" ;
text += "</div>" ;
text += "<div class='boks3'>" ;
2021-03-13 22:40:46 +00:00
2021-03-08 18:45:06 +00:00
text += "<div class='boks2'>" ;
2021-10-01 23:21:18 +00:00
text += top _list ( results . user . user _movies . data . movies , "Your movie" , false , true ) ;
2021-03-08 18:45:06 +00:00
text += "</div>" ;
2021-03-09 23:41:48 +00:00
text += "<div class='boks2' style='padding: 0;'>" ;
text += "<div class='boks2'>" ;
2021-03-13 22:40:46 +00:00
text += completion _movie ( results . user . user _movies . data . user _movie _finishing _percent , true ) ;
2021-03-08 18:45:06 +00:00
text += "</div>" ;
2021-03-09 23:41:48 +00:00
text += "<div class='boks2'>" ;
2021-03-13 22:40:46 +00:00
text += paused _movie ( results . user . user _movies . data . user _movie _most _paused , true ) ;
2020-12-23 13:17:10 +00:00
text += "</div>" ;
2021-03-09 23:41:48 +00:00
2020-12-23 13:17:10 +00:00
text += "</div>" ;
2021-03-08 18:45:06 +00:00
text += "</div>" ;
text += "</div>" ;
} else {
text += "<div class='boks' style='height: auto !important; width: 100%; padding-bottom: 25em; padding-top: 25em; height:10em; background-color:#B9A3D2;'>" ;
text += "<div class='boks3'>" ;
2021-10-07 16:44:27 +00:00
text += "<div class='boks2'>" ;
text += "<div class='status'>" ;
text += "<h1>Movies!</h1>" ;
text += "<br><br><br>" ;
text += "<h2>You watched " + results . user . user _movies . data . movies . length + " movies. That's impressive in itself!</h2><p>(might wanna try it)</p>"
text += '<img src="assets/img/bored.svg" style="margin: auto; display: block; width: 15em;">' ;
text += "</div>" ;
text += "</div>" ;
2021-03-08 18:45:06 +00:00
text += "</div>" ;
2020-12-23 13:17:10 +00:00
text += "</div>" ;
2021-03-08 18:45:06 +00:00
}
document . getElementById ( "search_results" ) . innerHTML += text ;
}
//SHOWS
function load _shows ( ) {
var text = "" ;
if ( results . user . user _shows . data . shows . length > 1 ) {
text += "<div class='boks' style='height: auto !important; width: 100%; padding-bottom: 25em; padding-top: 25em; height:10em; background-color:#BBD2A3;'>" ;
2021-03-09 23:41:48 +00:00
text += "<div class='boks3'>" ;
2021-08-11 16:07:05 +00:00
text += "<h1>Shows!</h1>" ;
2021-03-09 23:41:48 +00:00
text += "<br><br><br><h2>You watched " + results . user . user _shows . data . shows . length + " different shows.</h2><p>(No, watching The Office twice in a year doesn't count as two shows)</p>"
text += "</div>" ;
2020-12-23 13:17:10 +00:00
2021-03-08 18:45:06 +00:00
text += "<div class='boks3'>" ;
2021-03-13 22:40:46 +00:00
2020-12-23 13:17:10 +00:00
text += "<div class='boks2'>" ;
2021-10-01 23:21:18 +00:00
text += top _list ( results . user . user _shows . data . shows , "Your top shows" , false , true ) ;
2020-12-23 13:17:10 +00:00
text += "</div>" ;
2021-03-09 23:41:48 +00:00
text += "<div class='boks2' style='padding: 0;'>" ;
2021-03-08 18:45:06 +00:00
2021-03-09 23:41:48 +00:00
if ( results . user . user _shows . data . shows . length > 0 && ! results . user . user _shows . data . show _buddy . error && functions . get _user _show _buddy ) {
text += "<div class='boks2'>" ;
text += load _showbuddy ( ) ;
text += "</div>" ;
}
2021-10-07 16:44:27 +00:00
if ( results . user . user _shows . data . episode _duration _longest . plays != 0 && results . user . user _shows . data . episode _duration _longest . duration != 0 ) {
text += "<div class='boks2'>" ;
text += load _longest _episode ( results . user . user _shows . data . episode _duration _longest ) ;
text += "</div>" ;
}
2021-03-09 23:41:48 +00:00
var sum = 0 ;
for ( i = 0 ; ( i < results . user . user _shows . data . shows . length ) ; i ++ ) {
sum += results . user . user _shows . data . shows [ i ] . duration ;
}
2021-03-13 22:40:46 +00:00
2021-03-09 23:41:48 +00:00
text += "<div class='boks2'>" ;
2021-10-05 13:34:30 +00:00
text += you _spent ( sum , 'shows' , 'watching' ) ;
2020-12-23 13:17:10 +00:00
text += "</div>" ;
2021-03-09 23:41:48 +00:00
2020-12-23 13:17:10 +00:00
text += "</div>" ;
2021-03-08 18:45:06 +00:00
2020-12-23 13:17:10 +00:00
text += "</div>" ;
2021-03-08 18:45:06 +00:00
text += "</div>" ;
} else if ( results . user . user _shows . data . shows . length == 1 ) {
text += "<div class='boks' style='height: auto !important; width: 100%; padding-bottom: 25em; padding-top: 25em; height:10em; background-color:#BBD2A3;'>" ;
2021-03-09 23:41:48 +00:00
text += "<div class='boks3'>" ;
2021-08-11 16:07:05 +00:00
text += "<h1>Shows!</h1>" ;
2021-03-09 23:41:48 +00:00
text += "<br><br><br><h2>You watched " + results . user . user _shows . data . shows . length + " show.</h2><p>(Better not be that same one again...)</p>"
text += "</div>" ;
2021-03-08 18:45:06 +00:00
text += "<div class='boks3'>" ;
2021-03-13 22:40:46 +00:00
2021-03-08 18:45:06 +00:00
text += "<div class='boks2'>" ;
2021-10-01 23:21:18 +00:00
text += top _list ( results . user . user _shows . data . shows , "Your show" , false , true ) ;
2021-03-08 18:45:06 +00:00
text += "</div>" ;
2020-12-22 16:27:30 +00:00
2021-03-09 15:15:32 +00:00
if ( results . user . user _shows . data . shows . length > 0 && ! results . user . user _shows . data . show _buddy . error && functions . get _user _show _buddy ) {
2021-03-08 18:45:06 +00:00
text += "<div class='boks2'>" ;
2021-03-13 22:40:46 +00:00
text += load _showbuddy ( ) ;
2021-03-08 18:45:06 +00:00
text += "</div>" ;
}
2021-10-07 16:44:27 +00:00
if ( results . user . user _shows . data . episode _duration _longest . plays != 0 && results . user . user _shows . data . episode _duration _longest . duration != 0 ) {
text += "<div class='boks2'>" ;
text += load _longest _episode ( results . user . user _shows . data . episode _duration _longest ) ;
text += "</div>" ;
}
2021-03-08 18:45:06 +00:00
text += "</div>" ;
2020-12-22 16:27:30 +00:00
text += "</div>" ;
2021-03-08 18:45:06 +00:00
} else {
2020-12-19 16:10:59 +00:00
2021-03-08 18:45:06 +00:00
text += "<div class='boks' style='height: auto !important; width: 100%; padding-bottom: 25em; padding-top: 25em; height:10em; background-color:#B9A3D2;'>" ;
text += "<div class='boks3'>" ;
2021-10-07 16:44:27 +00:00
text += "<div class='boks2'>" ;
text += "<div class='status'>" ;
text += "<h1>Shows!</h1>" ;
text += "<br><br><br>" ;
text += "<h2>You watched " + results . user . user _shows . data . shows . length + " shows. I get it, it's not for everyone!</h2><p>(might wanna try it)</p>"
text += '<img src="assets/img/bored.svg" style="margin: auto; display: block; width: 15em;">' ;
text += "</div>" ;
text += "</div>" ;
2021-03-08 18:45:06 +00:00
text += "</div>" ;
text += "</div>" ;
}
document . getElementById ( "search_results" ) . innerHTML += text ;
}
2021-10-01 23:21:18 +00:00
//MUSIC
function load _music ( ) {
var text = "" ;
var albums = [ ] ;
var artists = [ ] ;
2021-10-07 16:44:27 +00:00
var tracks = results . user . user _music . data . music ;
2021-10-01 23:21:18 +00:00
for ( var i = 0 ; i < results . user . user _music . data . music . length ; i ++ ) {
var found = false ;
for ( var j = 0 ; j < albums . length ; j ++ ) {
if ( albums [ j ] . title == results . user . user _music . data . music [ i ] . parent _title && albums [ j ] . grandparent _title == results . user . user _music . data . music [ i ] . grandparent _title ) {
albums [ j ] [ "plays" ] = albums [ j ] . plays + 1 ;
albums [ j ] [ "duration" ] = results . user . user _music . data . music [ i ] . duration + albums [ j ] . duration ;
found = true ;
break ;
}
}
if ( ! found && results . user . user _music . data . music [ i ] . parent _title != "" && results . user . user _music . data . music [ i ] . grandparent _title != "" ) {
2021-10-07 16:44:27 +00:00
albums . push ( { "title" : results . user . user _music . data . music [ i ] . parent _title , "parent_rating_key" : results . user . user _music . data . music [ i ] . parent _rating _key , "grandparent_title" : results . user . user _music . data . music [ i ] . grandparent _title , "plays" : 1 , "duration" : results . user . user _music . data . music [ i ] . duration , "year" : results . user . user _music . data . music [ i ] . year } ) ;
2021-10-01 23:21:18 +00:00
}
}
albums . sort ( function ( a , b ) {
return parseFloat ( b . duration ) - parseFloat ( a . duration ) ;
} ) ;
for ( var i = 0 ; i < results . user . user _music . data . music . length ; i ++ ) {
var found = false ;
for ( var j = 0 ; j < artists . length ; j ++ ) {
if ( artists [ j ] . title == results . user . user _music . data . music [ i ] . grandparent _title ) {
artists [ j ] [ "plays" ] = artists [ j ] . plays + 1 ;
artists [ j ] [ "duration" ] = results . user . user _music . data . music [ i ] . duration + artists [ j ] . duration ;
found = true ;
break ;
}
}
if ( ! found && results . user . user _music . data . music [ i ] . grandparent _title != "" ) {
artists . push ( { "title" : results . user . user _music . data . music [ i ] . grandparent _title , "grandparent_rating_key" : results . user . user _music . data . music [ i ] . grandparent _rating _key , "plays" : 1 , "duration" : results . user . user _music . data . music [ i ] . duration } ) ;
}
}
artists . sort ( function ( a , b ) {
return parseFloat ( b . duration ) - parseFloat ( a . duration ) ;
} ) ;
if ( results . user . user _music . data . music . length > 1 ) {
text += "<div class='boks' style='height: auto !important; width: 100%; padding-bottom: 25em; padding-top: 25em; height:10em; background-color:#CFA38C;'>" ;
text += "<div class='boks3'>" ;
text += "<h1>Music!</h1>" ;
text += "<br><br><br><h2>You listened to " + results . user . user _music . data . music . length + ' different tracks.</h2><p>(If you can call your taste "music"...)</p>'
text += "</div>" ;
text += "<div class='boks3'>" ;
text += "<div class='boks2'>" ;
text += top _list ( results . user . user _music . data . music , "Your top tracks" , true , false ) ;
text += "</div>" ;
text += "<div class='boks2'>" ;
text += top _list ( albums , "Your top albums" , true , false ) ;
text += "</div>" ;
text += "<div class='boks2'>" ;
text += top _list ( artists , "Your top artists" , false , false ) ;
text += "</div>" ;
2021-10-07 16:44:27 +00:00
text += "<div class='boks2' style='padding: 0;'>" ;
albums . sort ( function ( a , b ) {
return parseFloat ( a . year ) - parseFloat ( b . year ) ;
} ) ;
text += "<div class='boks2'>" ;
text += oldest _album ( albums ) ;
text += "</div>" ;
var sum = 0 ;
for ( i = 0 ; ( i < results . user . user _music . data . music . length ) ; i ++ ) {
sum += results . user . user _music . data . music [ i ] . duration ;
}
text += "<div class='boks2'>" ;
text += you _spent ( sum , 'music' , 'listening' ) ;
text += "</div>" ;
text += "</div>" ;
2021-10-05 13:34:30 +00:00
2021-10-01 23:21:18 +00:00
text += "</div>" ;
text += "</div>" ;
2021-10-07 16:44:27 +00:00
} else if ( results . user . user _music . data . music . length == 1 ) {
2021-10-05 13:34:30 +00:00
text += "<div class='boks' style='height: auto !important; width: 100%; padding-bottom: 25em; padding-top: 25em; height:10em; background-color:#CFA38C;'>" ;
text += "<div class='boks3'>" ;
text += "<h1>Music!</h1>" ;
text += "<br><br><br><h2>You listened to " + results . user . user _music . data . music . length + " track.</h2><p>(Whatever floats your boat...)</p>"
text += "</div>" ;
text += "<div class='boks3'>" ;
text += "<div class='boks2'>" ;
text += top _list ( results . user . user _music . data . music , "Your track" , true , false ) ;
text += "</div>" ;
text += "</div>" ;
text += "</div>" ;
} else {
text += "<div class='boks' style='height: auto !important; width: 100%; padding-bottom: 25em; padding-top: 25em; height:10em; background-color:#CFA38C;'>" ;
text += "<div class='boks3'>" ;
2021-10-07 16:44:27 +00:00
text += "<div class='boks2'>" ;
text += "<div class='status'>" ;
text += "<h1>Music!</h1>" ;
text += "<br><br><br>" ;
text += "<h2>You listened to " + results . user . user _music . data . music . length + " tracks. No speakers, huh?</h2><p>(might wanna try it)</p>"
text += '<img src="assets/img/bored.svg" style="margin: auto; display: block; width: 15em;">' ;
text += "</div>" ;
text += "</div>" ;
2021-10-05 13:34:30 +00:00
text += "</div>" ;
text += "</div>" ;
}
2021-10-01 23:21:18 +00:00
document . getElementById ( "search_results" ) . innerHTML += text ;
}
2021-03-13 22:40:46 +00:00
function oldest _movie ( array ) {
var html = "" ;
html += "<div class='status' id='list3' style='padding:1em;min-width:15em;'>" ;
html += "<div class='stats'>" ;
html += "The oldest movie you watched was <br><b>" + array . title + " (" + array . year + ")</b><br>" ;
if ( array . year < 1950 ) {
html += "<br>I didn't even know they made movies back then." ;
html += '<br><br><img src="assets/img/old-man.svg" style="margin: auto; display: block; width: 15em;">' ;
} else if ( array . year < 1975 ) {
html += "<br>Did it even have color?" ;
html += '<br><br><img src="assets/img/old-man.svg" style="margin: auto; display: block; width: 15em;">' ;
} else if ( array . year < 2000 ) {
html += "<br>Was it a 4K, UHD, 3D, Dolby Atmos remaster?" ;
2021-10-05 13:34:30 +00:00
html += '<br><br><img src="assets/img/old-man.svg" style="margin: auto; display: block; width: 15em;">' ;
2021-03-13 22:40:46 +00:00
} else {
html += "<br>Enjoying the classics, huh?" ;
2021-10-05 13:34:30 +00:00
html += '<br><br><img src="assets/img/old-man.svg" style="margin: auto; display: block; width: 15em;">' ;
2021-03-13 22:40:46 +00:00
}
html += "</div>" ;
html += "</div>" ;
return html ;
}
2021-10-07 16:44:27 +00:00
function oldest _album ( array ) {
var html = "" ;
html += "<div class='status' id='list3' style='padding:1em;min-width:15em;'>" ;
html += "<div class='stats'>" ;
html += "The oldest album you listened to was <br><b>" + array [ 0 ] . title + " (" + array [ 0 ] . year + ")</b> by " + array [ 0 ] . grandparent _title + "<br>" ;
html += "<br>Maybe get the vinyl release?" ;
html += '<br><br><img src="assets/img/old-man.svg" style="margin: auto; display: block; width: 15em;">' ;
html += "</div>" ;
html += "</div>" ;
return html ;
}
2021-03-13 22:40:46 +00:00
function completion _movie ( user _movie _finishing _percent , single ) {
var html = "" ;
html += "<div class='status' id='list3' style='padding:1em;min-width:15em;'>" ;
html += "<div class='stats'>" ;
var str = JSON . stringify ( user _movie _finishing _percent ) ;
var percent = str . split ( '.' ) ;
if ( ! single ) {
html += "<b>Your average movie finishing percentage was " + percent [ 0 ] + "%</b>" ;
} else {
html += "<b>Your saw " + percent [ 0 ] + "%</b>" ;
}
if ( percent [ 0 ] > 89 ) {
html += '<br><br><img src="assets/img/champion.svg" style="margin: auto; display: block; width: 15em;">' ;
}
html += "<br><br>You're not watching the credits like a nerd, are you?" ;
html += "</div>" ;
html += "</div>" ;
return html ;
}
function paused _movie ( array , single ) {
var html = "" ;
html += "<div class='status' id='list3' style='padding:1em;min-width:15em;'>" ;
if ( array . paused _counter > 0 ) {
var pause _time = seconds _to _time ( array . paused _counter , false ) ;
if ( ! single ) {
html += "<div class='stats'>" ;
html += "Your longest movie pause was watching <br><b>" + array . title + " (" + array . year + ")</b>" ;
html += "<br><br>It was paused for " + pause _time + "..." ;
html += "</div>" ;
} else {
html += "<div class='stats'>" ;
html += "One movie, but you still paused it<br>" ;
html += "<br><br>It was paused for " + pause _time + "..." ;
html += "</div>" ;
}
} else {
html += "<div class='stats'>" ;
html += "<b>Bladder of steel</b>" ;
html += '<br><br><img src="assets/img/awards.svg" style="margin: auto; display: block; width: 15em;">' ;
html += "<br>You never paused a single movie." ;
html += "</div>" ;
}
html += "</div>" ;
return html ;
}
2021-10-07 16:44:27 +00:00
2021-03-08 18:45:06 +00:00
function load _showbuddy ( ) {
var html = "" ;
2021-03-13 22:40:46 +00:00
2021-03-08 18:45:06 +00:00
html += "<div class='status' id='list3' style='padding:1em;min-width:15em;'>" ;
html += "<div class='stats'>" ;
2021-10-05 13:34:30 +00:00
html += "<b>Your top show was " + results . user . user _shows . data . shows [ 0 ] . title + "</b><br>" ;
2021-03-08 18:45:06 +00:00
if ( ! results . user . user _shows . data . show _buddy . error ) {
2021-10-07 16:44:27 +00:00
if ( ! results . user . user _shows . data . show _buddy . found ) {
2021-03-08 18:45:06 +00:00
html += '<br><img src="assets/img/quest.svg" style="margin: auto; display: block; width: 15em;">' ;
2021-10-05 13:34:30 +00:00
html += "<br>That means you dared to explore where no one else would, because you are the only viewer of that show" ;
2021-03-08 18:45:06 +00:00
} else {
html += "And you're not alone! Your " + results . user . user _shows . data . shows [ 0 ] . title + "-buddy is " ;
2021-10-07 16:44:27 +00:00
html += "<b>" + results . user . user _shows . data . show _buddy . friendly _name + "!</b><br><br>" ;
var combined = results . user . user _shows . data . show _buddy . duration + parseInt ( results . user . user _shows . data . shows [ 0 ] . duration ) ;
2021-03-13 22:40:46 +00:00
var combined _2 = seconds _to _time ( combined ) ;
2021-03-08 18:45:06 +00:00
html += '<img src="assets/img/social-event.svg" style="margin: auto; display: block; width: 15em;">' ;
2021-03-13 22:40:46 +00:00
html += "<br>Your combined efforts resulted in <b>" + combined _2 + "</b> of " + results . user . user _shows . data . shows [ 0 ] . title + "!</b>" ;
2021-03-08 18:45:06 +00:00
}
}
html += "</div>" ;
html += "</div>" ;
2021-03-13 22:40:46 +00:00
return html ;
}
2021-10-07 16:44:27 +00:00
function load _longest _episode ( array ) {
var html = "" ;
html += "<div class='status' id='list3' style='padding:1em;min-width:15em;'>" ;
html += "<div class='stats'>" ;
html += "Your really liked the episode <b>" + array . title + "</b> from " + array . grandparent _title + "<br>" ;
html += "<br>It recieved " + play _plays ( array . plays ) + " and was endured for " + seconds _to _time ( array . duration , false ) + "." ;
html += "</div>" ;
html += "</div>" ;
return html ;
}
2021-10-05 13:34:30 +00:00
function you _spent ( time , category , verb ) {
2021-03-13 22:40:46 +00:00
var html = "" ;
var time = seconds _to _time ( time , false ) ;
html += "<div class='status' id='list3' style='padding:1em;min-width:15em;'>" ;
html += "<div class='stats'>" ;
html += "You spent <b>" + time + "</b>" ;
2021-10-05 13:34:30 +00:00
html += " " + verb + " " ;
html += category ;
if ( category == 'music' ) {
html += '<br><img src="assets/img/music.svg" style="margin: auto; display: block; width: 15em;">' ;
} else {
html += '<br><img src="assets/img/watching-tv.svg" style="margin: auto; display: block; width: 15em;">' ;
}
2021-03-13 22:40:46 +00:00
html += "</div>" ;
html += "</div>" ;
return html ;
}
2021-10-01 23:21:18 +00:00
function top _list ( array , title , music , year ) {
2021-03-13 22:40:46 +00:00
var html = "" ;
2021-10-01 23:21:18 +00:00
2021-03-13 22:40:46 +00:00
html += "<div class='status' id='list3'>" ;
html += "<div class='stats'>" ;
html += "<div class='status-title'>" + title + "</div>" ;
html += "<div class='stats-list'>" ;
for ( i = 0 ; ( i < array . length && i < 10 ) ; i ++ ) {
html += "<div class='item'>" ;
html += "<div class='number'>" ;
html += i + 1 + ". " ;
html += "</div>" ;
2021-10-01 23:21:18 +00:00
html += "<div class='movie_name'>" ;
if ( music ) {
html += array [ i ] . grandparent _title + "<br>" ;
}
html += "<b>" ;
html += array [ i ] . title ;
2021-03-13 22:40:46 +00:00
html += "</b>" ;
var movie _hour = seconds _to _time ( array [ i ] . duration , true ) ;
2021-10-01 23:21:18 +00:00
if ( typeof ( array [ i ] . year ) != "undefined" && year ) {
2021-03-13 22:40:46 +00:00
html += " (" + array [ i ] . year + ")" ;
}
html += "<br>" + movie _hour + "<br>" + play _plays ( array [ i ] . plays ) ;
html += "</div>" ;
html += "</div>" ;
}
html += "</div>" ;
html += "</div>" ;
html += "</div>" ;
return html ;
}
function top _list _names ( array , title ) {
var html = "" ;
html += "<div class='status' id='list3'>" ;
html += "<div class='stats'>" ;
html += "<div class='status-title'>" + title + "</div>" ;
html += "<div class='stats-list'>" ;
for ( i = 0 ; i < 10 && i < array . length ; i ++ ) {
if ( i == 0 ) {
html += "<div class='item gold'>" ;
} else if ( i == 1 ) {
html += "<div class='item silver'>" ;
} else if ( i == 2 ) {
html += "<div class='item bronze'>" ;
} else {
html += "<div class='item'>" ;
}
html += "<div class='number'>" ;
html += i + 1 + ". " ;
html += "</div>" ;
if ( array [ i ] . user == results . user . name ) {
html += "<div class='name you'>" ;
html += array [ i ] . user ;
html += "</div>" ;
} else {
html += "<div class='name'>" ;
html += array [ i ] . user ;
html += "</div>" ;
}
html += "</div>" ;
}
html += "</div>" ;
html += "</div>" ;
html += "</div>" ;
2021-03-08 18:45:06 +00:00
return html ;
}
//TOP USERS
function load _users ( ) {
var text = "" ;
text += "<div class='boks' style='height: auto !important; width: 100%; padding-bottom: 25em; padding-top: 25em; height:10em; background-color: #a2d1d0;'>" ;
2021-08-11 16:07:05 +00:00
text += "<h1>Server-wide statistics!</h1>" ;
2021-03-08 18:45:06 +00:00
text += "<br><br><br><br><h2>It's okay to feel shame if you are on the list.</h2><p>(or missing from it...)</p>"
2020-12-23 13:17:10 +00:00
text += "<br><br>" ;
text += "<div class='boks3'>" ;
2021-10-01 23:21:18 +00:00
if ( functions . get _year _stats _leaderboard ) {
2020-12-23 13:17:10 +00:00
2021-10-01 23:21:18 +00:00
text += "<div class='boks2'>" ;
2021-10-05 12:34:00 +00:00
text += top _list _names ( results . year _stats . year _users . data , 'Top users' ) ;
2021-10-01 23:21:18 +00:00
text += "</div>" ;
2020-12-23 13:17:10 +00:00
2021-10-01 23:21:18 +00:00
var sum _movies = 0 ;
var sum _shows = 0 ;
var sum _artists = 0 ;
2021-03-13 22:40:46 +00:00
2021-10-07 16:44:27 +00:00
if ( functions . get _year _stats _movies && results . year _stats . year _movies . data . length > 0 ) {
2021-10-05 12:34:00 +00:00
for ( i = 0 ; ( i < results . year _stats . year _movies . data . length ) ; i ++ ) {
sum _movies += results . year _stats . year _movies . data [ i ] . duration ;
2021-10-01 23:21:18 +00:00
}
}
2021-03-13 22:40:46 +00:00
2021-10-07 16:44:27 +00:00
if ( functions . get _year _stats _shows && results . year _stats . year _shows . data . length > 0 ) {
2021-10-05 12:34:00 +00:00
for ( i = 0 ; ( i < results . year _stats . year _shows . data . length ) ; i ++ ) {
sum _shows += results . year _stats . year _shows . data [ i ] . duration ;
2021-10-01 23:21:18 +00:00
}
}
2021-10-07 16:44:27 +00:00
if ( functions . get _year _stats _music && results . year _stats . year _music . data . length > 0 ) {
2021-10-05 12:34:00 +00:00
for ( i = 0 ; ( i < results . year _stats . year _music . data . length ) ; i ++ ) {
sum _artists += results . year _stats . year _music . data [ i ] . duration ;
2021-10-01 23:21:18 +00:00
}
}
var time _movies = seconds _to _time ( sum _movies , false ) ;
var time _shows = seconds _to _time ( sum _shows , false ) ;
var time _artists = seconds _to _time ( sum _artists , false ) ;
var time _all = seconds _to _time ( Math . floor ( sum _movies + sum _shows + sum _artists ) , false ) ;
2021-10-07 16:44:27 +00:00
var function _sum = 0 ;
2021-10-01 23:21:18 +00:00
text += "<div class='boks2'>" ;
text += "<div class='status' id='list3' style='padding:1em;min-width:15em;'>" ;
text += "<div class='stats'>" ;
2021-10-07 16:44:27 +00:00
if ( functions . get _year _stats _movies && results . year _stats . year _movies . data . length > 0 ) {
2021-10-01 23:21:18 +00:00
text += "All the different users combined spent <b>" + time _movies + "</b>" ;
text += " watching movies." ;
text += "<br><br>" ;
2021-10-07 16:44:27 +00:00
function _sum += 1 ;
2021-10-01 23:21:18 +00:00
}
2021-10-07 16:44:27 +00:00
if ( functions . get _year _stats _shows && results . year _stats . year _shows . data . length > 0 ) {
2021-10-01 23:21:18 +00:00
text += "All the different users combined spent <b>" + time _shows + "</b>" ;
text += " watching shows." ;
text += "<br><br>" ;
2021-10-07 16:44:27 +00:00
function _sum += 1 ;
2021-10-01 23:21:18 +00:00
}
2021-10-07 16:44:27 +00:00
if ( functions . get _year _stats _music && results . year _stats . year _music . data . length > 0 ) {
2021-10-01 23:21:18 +00:00
text += "All the different users combined spent <b>" + time _artists + "</b>" ;
text += " listening to artists." ;
text += "<br><br>" ;
2021-10-07 16:44:27 +00:00
function _sum += 1 ;
2021-10-01 23:21:18 +00:00
}
2021-10-07 16:44:27 +00:00
if ( function _sum > 1 ) {
2021-10-01 23:21:18 +00:00
text += "That is <b>" + time _all + "</b><br>of content!" ;
}
text += '<img src="assets/img/home.svg" style="margin: auto; display: block; width: 15em;">' ;
text += "</div>" ;
2020-12-23 13:17:10 +00:00
text += "</div>" ;
text += "</div>" ;
2021-10-01 23:21:18 +00:00
}
2020-12-19 16:10:59 +00:00
text += "</div>" ;
2020-12-23 13:17:10 +00:00
text += "<div class='boks3'>" ;
2020-12-19 16:10:59 +00:00
2021-10-07 16:44:27 +00:00
if ( functions . get _year _stats _movies && results . year _stats . year _movies . data . length > 0 ) {
2021-10-01 23:21:18 +00:00
text += "<div class='boks2'>" ;
2021-10-05 12:34:00 +00:00
text += top _list ( results . year _stats . year _movies . data , "Top movies" , false , true ) ;
2021-10-01 23:21:18 +00:00
text += "</div>" ;
}
2020-12-23 13:17:10 +00:00
2021-10-07 16:44:27 +00:00
if ( functions . get _year _stats _shows && results . year _stats . year _shows . data . length > 0 ) {
2021-10-01 23:21:18 +00:00
text += "<div class='boks2'>" ;
2021-10-05 12:34:00 +00:00
text += top _list ( results . year _stats . year _shows . data , "Top shows" , false , false ) ;
2021-10-01 23:21:18 +00:00
text += "</div>" ;
}
2021-10-07 16:44:27 +00:00
if ( functions . get _year _stats _music && results . year _stats . year _music . data . length > 0 ) {
2021-10-01 23:21:18 +00:00
var artists = [ ] ;
2021-10-05 12:34:00 +00:00
for ( var i = 0 ; i < results . year _stats . year _music . data . length ; i ++ ) {
2021-10-01 23:21:18 +00:00
var found = false ;
for ( var j = 0 ; j < artists . length ; j ++ ) {
2021-10-05 12:34:00 +00:00
if ( artists [ j ] . title == results . year _stats . year _music . data [ i ] . grandparent _title ) {
2021-10-01 23:21:18 +00:00
artists [ j ] [ "plays" ] = artists [ j ] . plays + 1 ;
2021-10-05 12:34:00 +00:00
artists [ j ] [ "duration" ] = results . year _stats . year _music . data [ i ] . duration + artists [ j ] . duration ;
2021-10-01 23:21:18 +00:00
found = true ;
break ;
}
}
2021-10-05 12:34:00 +00:00
if ( ! found && results . year _stats . year _music . data [ i ] . grandparent _title != "" ) {
artists . push ( { "title" : results . year _stats . year _music . data [ i ] . grandparent _title , "grandparent_rating_key" : results . year _stats . year _music . data [ i ] . grandparent _rating _key , "plays" : 1 , "duration" : results . year _stats . year _music . data [ i ] . duration } ) ;
2021-10-01 23:21:18 +00:00
}
}
artists . sort ( function ( a , b ) {
return parseFloat ( b . duration ) - parseFloat ( a . duration ) ;
} ) ;
text += "<div class='boks2'>" ;
text += top _list ( artists , "Top artists" , false , false ) ;
text += "</div>" ;
}
2020-12-23 13:17:10 +00:00
text += "</div>" ;
2020-12-19 16:10:59 +00:00
text += "</div>" ;
2021-03-08 18:45:06 +00:00
document . getElementById ( "search_results" ) . innerHTML += text ;
}
2020-12-19 16:10:59 +00:00
2021-03-08 18:45:06 +00:00
//Outro
function load _outro ( ) {
var text = "" ;
2020-12-19 16:10:59 +00:00
2021-03-08 18:45:06 +00:00
text += "<div class='boks' style='height: auto !important; width: 100%; padding-bottom: 15em; padding-top: 15em; height:10em; background-color:#39393A;'>" ;
text += "<div class='boks3'>" ;
text += "<div class='boks2'>" ;
text += '<img src="assets/img/new-years.svg" style="width:100%; ">' ;
text += "</div>" ;
text += "<div class='boks2' style='margin-top:5em;'>" ;
text += "<h1>Hope you are staying safe!</h1><br><br><h4>Goodybye.</h4>" ;
text += "</div>" ;
text += "</div>" ;
text += "</div>" ;
2020-12-19 16:10:59 +00:00
2021-03-08 18:45:06 +00:00
document . getElementById ( "search_results" ) . innerHTML += text ;
2021-03-13 22:40:46 +00:00
}
function play _plays ( plays ) {
plays = parseInt ( plays ) ;
if ( plays == 1 ) {
var play _string = plays + ' play' ;
} else {
var play _string = plays + ' plays' ;
}
return play _string ;
}
//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 ) ;
} else if ( seconds >= seconds _in _hour ) {
var time = seconds _to _hours ( seconds , comma ) ;
} else if ( seconds >= seconds _in _minute ) {
var time = seconds _to _minutes ( seconds , comma ) ;
} else {
var time = seconds _to _seconds ( seconds ) ;
}
return time ;
}
function seconds _to _days ( seconds , comma ) {
var day = Math . floor ( seconds / seconds _in _day ) ;
var rest = Math . floor ( seconds % seconds _in _day ) ;
var hour = Math . floor ( rest / seconds _in _hour ) ;
rest = Math . floor ( rest % seconds _in _hour ) ;
var minute = Math . floor ( rest / seconds _in _minute ) ;
rest = Math . floor ( rest % seconds _in _minute ) ;
var day _string = '' ;
var hour _string = '' ;
var minute _string = '' ;
if ( day < 2 ) {
day _string += day + ' day' ;
} else {
day _string += day + ' days' ;
}
if ( hour < 2 ) {
hour _string += hour + ' hour' ;
} else {
hour _string += hour + ' hours' ;
}
if ( minute < 2 ) {
minute _string += minute + ' minute' ;
} else {
minute _string += minute + ' minutes' ;
}
if ( ! hour == 0 ) {
if ( ! minute == 0 ) {
if ( comma ) {
return day _string + ', ' + hour _string + ', ' + minute _string ;
} else {
return day _string + ', ' + hour _string + ' and ' + minute _string ;
}
} else {
if ( comma ) {
return day _string + ', ' + hour _string ;
} else {
return day _string + ' and ' + hour _string ;
}
}
} else {
return day _string ;
}
}
function seconds _to _hours ( seconds , comma ) {
var hour = Math . floor ( seconds / seconds _in _hour ) ;
var rest = Math . floor ( seconds % seconds _in _hour ) ;
var minute = Math . floor ( rest / seconds _in _minute ) ;
rest = Math . floor ( rest % seconds _in _minute ) ;
var hour _string = '' ;
var minute _string = '' ;
if ( hour < 2 ) {
hour _string += hour + ' hour' ;
} else {
hour _string += hour + ' hours' ;
}
if ( minute < 2 ) {
minute _string += minute + ' minute' ;
} else {
minute _string += minute + ' minutes' ;
}
if ( ! minute == 0 ) {
if ( comma ) {
return hour _string + ', ' + minute _string ;
} else {
return hour _string + ' and ' + minute _string ;
}
} else {
return hour _string ;
}
}
function seconds _to _minutes ( seconds , comma ) {
seconds = parseInt ( seconds ) ;
var minute = Math . floor ( seconds / seconds _in _minute ) ;
var rest = Math . floor ( seconds % seconds _in _minute ) ;
var minute _string = '' ;
var second _string = '' ;
if ( minute < 2 ) {
minute _string += minute + ' minute' ;
} else {
minute _string += minute + ' minutes' ;
}
if ( seconds < 2 ) {
second _string += rest + ' second' ;
} else {
second _string += rest + ' seconds' ;
}
if ( ! seconds == 0 ) {
if ( comma ) {
return minute _string + ', ' + second _string ;
} else {
return minute _string + ' and ' + second _string ;
}
} else {
return minute _string ;
}
}
function seconds _to _seconds ( seconds ) {
var second _string = '' ;
if ( seconds == 1 ) {
second _string += seconds + ' second' ;
} else {
second _string += seconds + ' seconds' ;
}
return second _string ;
2020-12-22 16:27:30 +00:00
}