2023-02-17 06:47:28 -05:00
// Get the clear storage button element
const clearStorageBtn = document . getElementById ( 'clear-storage-btn' ) ;
// Add a click event listener to the clear storage button
clearStorageBtn . addEventListener ( 'click' , ( ) => {
// Remove the cookies
function removeCookies ( ) {
// Set the expiration date to a date in the past
const expirationDate = new Date ( 0 ) . toUTCString ( ) ;
// Set the ext_id cookie to expire
document . cookie = ` ext_id=; expires= ${ expirationDate } ` ;
// Set the luid cookie to expire
document . cookie = ` luid=; expires= ${ expirationDate } ` ;
// Set the aime_card_id cookie to expire
document . cookie = ` aime_card_id=; expires= ${ expirationDate } ` ;
}
// Example usage
removeCookies ( ) ;
console . log ( 'Local storage cleared.' ) ;
window . location = "/" ;
} ) ;
// Get the cookie string
const cookieString = document . cookie ;
// Parse the cookie string and extract the values
const cookies = cookieString . split ( ';' ) ;
2023-02-18 05:19:30 -05:00
let ext _id , luid , aime _card _id ;
2023-02-17 06:47:28 -05:00
for ( let i = 0 ; i < cookies . length ; i ++ ) {
const cookie = cookies [ i ] . trim ( ) ;
const cookieParts = cookie . split ( '=' ) ;
if ( cookieParts [ 0 ] === 'ext_id' ) {
ext _id = cookieParts [ 1 ] ;
}
if ( cookieParts [ 0 ] === 'luid' ) {
luid = cookieParts [ 1 ] ;
}
2023-02-18 05:19:30 -05:00
if ( cookieParts [ 0 ] === 'aime_card_id' ) {
aime _card _id = cookieParts [ 1 ] ;
}
2023-02-17 06:47:28 -05:00
}
// Send the user to the sign in page if they aren't already signed in to the website.
if ( ext _id && luid ) {
console . log ( ` ext_id: ${ ext _id } , luid: ${ luid } ` ) ;
} else {
console . log ( 'User Data Not Detected! Please Sign In.' ) ;
window . location = "/" ;
}
const userdata = JSON . parse ( document . currentScript . getAttribute ( 'data-userdata' ) ) ;
2023-02-18 05:19:30 -05:00
//=====================================================================
// Now Exiting: Cookie Data ///////////////// Now Entering: User Data
//=====================================================================
// general functions
function padNumber ( num , size ) {
let s = num + "" ;
while ( s . length < size ) {
s = "0" + s ;
}
return s ;
}
2023-02-18 18:15:19 -05:00
async function getSongInformation ( musicData , id ) {
2023-02-18 05:19:30 -05:00
const songMatch = musicData [ id ] ;
if ( ! songMatch ) {
2023-02-18 08:33:40 -05:00
return null ;
2023-02-18 05:19:30 -05:00
}
return songMatch ;
2023-02-18 08:33:40 -05:00
}
2023-02-18 05:19:30 -05:00
// Ban Check lmao
if ( userdata . ban _state !== 0 ) {
//nice
const parent = document . getElementById ( "User" ) ;
const wrapperDiv = document . createElement ( "div" ) ;
wrapperDiv . id = 'wrapper' ;
2023-02-18 18:15:19 -05:00
const scoreDiv = document . createElement ( "div" ) ;
scoreDiv . classList . add ( 'error' )
scoreDiv . innerHTML = ` <h3 style='
2023-02-18 05:19:30 -05:00
word - wrap : break - word ;
2023-02-18 18:15:19 -05:00
max - width : 800 px ; '>Heya! It looks like you' ve been banned from playing on this profile , but don 't worry - you can still enjoy the game in guest mode and view this profile. However, your account won' t be able to play on it anymore . If you have any questions about your ban , please contact your Network Administrator . < /h3>`; / / or set the HTML content with scoreDiv . innerHTML = " < p > This is some HTML content < / p > ;
2023-02-18 05:19:30 -05:00
parent . insertBefore ( wrapperDiv , parent . firstChild ) ;
2023-02-18 18:15:19 -05:00
wrapperDiv . appendChild ( scoreDiv ) ;
2023-02-18 05:19:30 -05:00
}
2023-02-17 06:47:28 -05:00
// Check if the user image element exists
2023-02-18 05:19:30 -05:00
if ( userdata . icon _id === 10 ) {
2023-02-17 06:47:28 -05:00
const userImage = document . getElementById ( 'user-image' ) ;
userImage . src = "images/" + ext _id + '-up.jpg' ;
} else if ( document . currentScript . getAttribute ( 'data-userdata' ) ) {
const userImage = document . getElementById ( 'user-image' ) ;
const UI _Icon = userdata . icon _id ;
// Pad the number because game weird
// Set the user image source
userImage . src = "assets/icon/UI_Icon_" + padNumber ( Number ( UI _Icon ) , 6 ) + '.png' ;
}
// title getting
const request = new XMLHttpRequest ( ) ;
request . open ( 'GET' , '/assets/metadata/titleMetadata.json' , true ) ;
2023-02-18 05:19:30 -05:00
request . onload = function ( ) {
if ( this . status >= 200 && this . status < 400 ) {
const data = JSON . parse ( this . response ) ;
const userTitle = document . getElementById ( 'user-title-text' ) ;
var userTitleText = ""
for ( title of data ) {
if ( userdata . title _id === title . titleId ) {
userTitleText = title . name
break
}
continue
2023-02-17 06:47:28 -05:00
}
2023-02-18 05:19:30 -05:00
userTitle . textContent = userTitleText
} else {
// handle the error
2023-02-17 06:47:28 -05:00
}
} ;
2023-02-18 05:19:30 -05:00
request . onerror = function ( ) {
// handle the error
2023-02-17 06:47:28 -05:00
} ;
request . send ( ) ;
2023-02-18 05:19:30 -05:00
// User Play Log
2023-02-18 08:33:40 -05:00
let scoreIncrement = 0 ;
let errorIncrement = 0 ;
let displayedScoreCount = 20 ;
async function userPlayLogFormatter ( div , loadMoreButton ) {
2023-02-18 05:19:30 -05:00
const UserPlayLogData = await UserPlayLog ( aime _card _id ) ;
2023-02-18 18:15:19 -05:00
console . log ( UserPlayLogData )
2023-02-18 08:33:40 -05:00
let scoresWrapperDiv = document . getElementById ( "scoreWrapper" ) ;
// If the scores wrapper div doesn't exist, create it.
if ( scoresWrapperDiv === null ) {
scoresWrapperDiv = document . createElement ( 'div' ) ;
2023-02-18 05:19:30 -05:00
scoresWrapperDiv . id = "scoreWrapper" ;
2023-02-18 08:33:40 -05:00
div . appendChild ( scoresWrapperDiv ) ;
}
2023-02-18 05:19:30 -05:00
2023-02-18 18:15:19 -05:00
const startIndex = scoresWrapperDiv . children . length ;
if ( startIndex > 0 ) {
// If the scores wrapper div already has children, don't do anything.
return ;
}
2023-02-18 08:33:40 -05:00
// Get the user's play log data and music IDs.
const musicIds = UserPlayLogData . map ( score => score . music _id ) ;
const musicData = await musicMetadata ( ) ;
2023-02-18 18:15:19 -05:00
2023-02-18 08:33:40 -05:00
let errorIncrement = 0 ;
let scoreIncrement = 0 ;
2023-02-18 18:15:19 -05:00
for ( let i = UserPlayLogData . length - 1 ; i >= 0 ; i -- ) {
const scoreDiv = document . createElement ( 'div' ) ; // Create a Div
2023-02-18 08:33:40 -05:00
let score = JSON . parse ( JSON . stringify ( UserPlayLogData [ i ] ) ) ; // get score data
let song = await getSongInformation ( musicData , score . music _id ) // get song data
2023-02-18 18:15:19 -05:00
let diffucultyData = song . difficultys . Notes [ score . level ] // get difficulty information
2023-02-18 08:33:40 -05:00
if ( ! song || ! song . name ) { // if a song can't be found, skip it and increment the error counter by 1.
console . log ( song )
console . log ( score . music _id )
console . log ( "Song or title is undefined" ) ;
errorIncrement ++
continue ;
2023-02-18 05:19:30 -05:00
}
2023-02-18 18:15:19 -05:00
scoreDiv . innerHTML = `
< div class = "score-title" >
2023-02-18 08:33:40 -05:00
< h4 > $ { song . name . str || "" } || < / h 4 >
2023-02-18 18:15:19 -05:00
< / d i v >
2023-02-18 08:33:40 -05:00
` ;
2023-02-18 18:15:19 -05:00
/* Score Jacket Image */
const scoreJacketDiv = document . createElement ( 'div' ) ;
2023-02-18 08:33:40 -05:00
let jacket = document . createElement ( 'img' ) ;
jacket . addEventListener ( "error" , function ( ) {
this . src = "assets/icon/UI_Icon_000000.png" ;
} ) ;
2023-02-18 18:15:19 -05:00
scoreJacketDiv . classList . add ( 'score-jacket' ) ;
2023-02-18 08:33:40 -05:00
jacket . classList . add ( 'score-jacket' ) ;
jacket . src = "assets/jacket/UI_Jacket_" + padNumber ( Number ( score . music _id ) , 6 ) + '.png' ;
2023-02-18 18:15:19 -05:00
scoreJacketDiv . append ( jacket )
scoreDiv . append ( scoreJacketDiv )
/* Achivement Box */
const scoreAchivementDiv = document . createElement ( 'div' ) ;
scoreAchivementDiv . classList . add ( 'score-achivement' ) ;
scoreAchivementDiv . innerHTML = ` <h5>ACHIVEMENT</h5> ` ;
let achivementPercentage = document . createElement ( 'h5' ) ;
let achivementNumber = padNumber ( Number ( score . achievement ) , 7 )
achivementPercentage . textContent = ` ${ achivementNumber / 10000 } % ` ;
scoreAchivementDiv . append ( achivementPercentage )
scoreDiv . append ( scoreAchivementDiv )
/* Score Grade */
let scoreGrades = [ "D" , "C" , "B" , "BB" , "BBB" , "A" , "AA" , "AAA" , "S" , "S+" , "SS" , "SS+" , "SSS" , "SSS+" ]
const scoreGradeDiv = document . createElement ( 'div' ) ;
scoreGradeDiv . classList . add ( 'score-grade' ) ;
let scoreGrade = document . createElement ( 'h4' ) ;
scoreGrade . textContent = ` ${ scoreGrades [ score . score _rank ] } ` ;
scoreGradeDiv . append ( scoreGrade ) ;
scoreDiv . append ( scoreGradeDiv ) ;
/* DX Score, Full Combo, Full Sync, and Multi-Placement */
const scoreInfoDiv = document . createElement ( 'div' ) ;
scoreInfoDiv . classList . add ( 'score-info' ) ;
const scoreInfoGridDiv = document . createElement ( 'div' ) ;
scoreInfoDiv . classList . add ( 'score-info-grid' ) ;
// please i dont want to make a fucking nested grid
/* DX Score */
const scoreDXScoreDiv = document . createElement ( 'div' ) ;
scoreDXScoreDiv . classList . add ( 'DX-Score' ) ;
scoreDXScoreDiv . innerHTML = ` <h4>DX Score: ${ score . deluxscore } / ${ diffucultyData . maxNotes * 3 } </h4> ` ;
scoreInfoGridDiv . append ( scoreDXScoreDiv ) ;
scoreInfoDiv . append ( scoreInfoGridDiv ) ;
scoreDiv . append ( scoreInfoDiv ) ;
scoreDiv . setAttribute ( "class" , "score-grid" ) ;
2023-02-18 08:33:40 -05:00
scoreIncrement ++
2023-02-18 18:15:19 -05:00
scoresWrapperDiv . appendChild ( scoreDiv ) ;
2023-02-18 08:33:40 -05:00
}
2023-02-18 18:15:19 -05:00
2023-02-18 08:33:40 -05:00
// Edit the Score Info Header with the relevant information.
const header = document . querySelector ( '#score-info-header' ) ;
2023-02-18 18:15:19 -05:00
header . textContent = ` Showing ${ startIndex + scoreIncrement - errorIncrement } out of ${ scoreIncrement } scores. ` ;
2023-02-18 08:33:40 -05:00
if ( errorIncrement > 0 ) {
header . insertAdjacentHTML ( 'afterend' , ` <p> ${ errorIncrement } Songs Failed to load properly, most likely due to missing information.</p> ` ) ;
}
// If there are no more scores to load, hide the "Load More" button.
if ( startIndex + scoreIncrement >= UserPlayLogData . length ) {
loadMoreButton . style . display = "none" ;
2023-02-18 05:19:30 -05:00
}
}
2023-02-18 08:33:40 -05:00
2023-02-18 18:15:19 -05:00
2023-02-18 05:19:30 -05:00
//=====================================================================
// Now Exiting: User Data ////////////// Now Entering: Nested Div Hell
//=====================================================================
const showContent = ( contentNumber ) => {
// Select the content div with the data-content attribute equal to the contentNumber
const contentDiv = document . querySelector ( ` [data-content="content- ${ contentNumber } "] ` ) ;
// Hide all content divs except the selected one
const contentDivs = document . querySelectorAll ( '[data-content]' ) ;
contentDivs . forEach ( ( div ) => {
if ( div === contentDiv ) {
if ( contentNumber === 2 ) { // If the ContentNumber is set to the PlayLog, Go to the userPlayLogFormatter Function
userPlayLogFormatter ( div )
}
div . classList . remove ( 'hidden' ) ;
} else {
div . classList . add ( 'hidden' ) ;
}
} ) ;
} ;
//=====================================================================
// Now Exiting: Nested Div Hell ///////////// Now Entering: Fetch Land
//=====================================================================
function UserPlayLog ( aime _card _id ) {
const input = aime _card _id ;
const url = "/api/getUserScores/" ;
// Return the fetch promise so that it can be handled within userPlayLogFormatter
return fetch ( url , {
method : "POST" ,
headers : {
"Content-Type" : "application/json"
} ,
body : JSON . stringify ( {
input : aime _card _id
} )
} )
. then ( response => response . json ( ) )
. then ( data => data . data )
. catch ( error => console . error ( error ) ) ;
}
async function musicMetadata ( ) {
const url = "/assets/metadata/musicMetadata.json" ;
2023-02-18 08:33:40 -05:00
2023-02-18 05:19:30 -05:00
try {
2023-02-18 08:33:40 -05:00
const response = await fetch ( url , {
method : "GET" ,
headers : {
"Content-Type" : "application/json" ,
} ,
} ) ;
const data = await response . json ( ) ;
const mapping = { } ;
data . forEach ( ( song ) => {
mapping [ song . name . id ] = song ;
} ) ;
return mapping ;
2023-02-18 05:19:30 -05:00
} catch ( error ) {
2023-02-18 08:33:40 -05:00
console . error ( error ) ;
2023-02-18 05:19:30 -05:00
}
2023-02-18 08:33:40 -05:00
}