2026-03-18 21:13:52 +01:00
window . loadHeader ( function ( headerContainer ) {
const friendButton = headerContainer . querySelector ( '.menu-item.friend' ) ;
if ( friendButton ) {
friendButton . classList . add ( 'active' ) ;
}
2026-02-21 06:16:14 +01:00
2026-03-18 21:13:52 +01:00
const logoutForm = document . getElementById ( "logout-form" ) ;
if ( logoutForm ) {
logoutForm . action = "/api/v1/spfn/logout" ;
const originInput = document . getElementById ( "logout_frontend_origin" ) ;
if ( originInput ) originInput . value = window . location . origin ;
logoutForm . addEventListener ( 'submit' , ( ) => {
sessionStorage . removeItem ( 'user_cache' ) ;
} ) ;
}
2026-03-22 23:35:09 +01:00
const twitterBtn = document . getElementById ( 'twitter-link-btn' ) ;
const twitterLabel = document . getElementById ( 'twitter-label-img' ) ;
const handleTwitterAction = ( ) => {
const isLinked = twitterBtn . dataset . linked === "true" ;
if ( isLinked ) {
if ( ! confirm ( "Unlink Twitter account?" ) ) return ;
fetch ( "/api/v1/me/twitter/unlink" , { method : "POST" , credentials : 'include' } )
. then ( ( ) => window . location . reload ( ) ) ;
} else {
twitterBtn . style . opacity = "0.5" ;
twitterBtn . style . pointerEvents = "none" ;
fetch ( "/api/v1/me/twitter/link" , { credentials : 'include' } )
. then ( res => res . status === 401 ? ( window . location . href = "/sign_in/" ) : res . json ( ) )
. then ( data => data ? . url ? ( window . location . href = data . url ) : window . location . reload ( ) )
. catch ( ( ) => window . location . reload ( ) ) ;
}
} ;
if ( twitterBtn ) {
twitterBtn . addEventListener ( 'click' , handleTwitterAction ) ;
}
2026-03-18 21:13:52 +01:00
const extractMiiName = ( miiDataB64 ) => {
try {
const binaryString = atob ( miiDataB64 . replace ( /-/g , '+' ) . replace ( /_/g , '/' ) ) ;
const data = new Uint8Array ( binaryString . length ) ;
for ( let i = 0 ; i < binaryString . length ; i ++ ) {
data [ i ] = binaryString . charCodeAt ( i ) ;
}
const size = data . length ;
let offset = - 1 ;
let isBE = false ;
if ( [ 92 , 96 , 104 , 106 , 108 , 336 , 72 ] . includes ( size ) ) offset = 0x1A ;
else if ( [ 74 , 76 ] . includes ( size ) ) { offset = 0x02 ; isBE = true ; }
else if ( size === 88 ) offset = 0x10 ;
else if ( [ 48 , 68 ] . includes ( size ) ) offset = 0x1C ;
if ( offset === - 1 ) return null ;
const decoder = new TextDecoder ( isBE ? 'utf-16be' : 'utf-16le' ) ;
let end = offset ;
while ( end < offset + 20 && end + 1 < data . length && ( data [ end ] !== 0 || data [ end + 1 ] !== 0 ) ) {
end += 2 ;
2026-02-21 06:16:14 +01:00
}
2026-03-18 21:13:52 +01:00
return decoder . decode ( data . slice ( offset , end ) ) ;
} catch ( e ) {
return null ;
}
} ;
2026-02-21 06:16:14 +01:00
2026-03-22 23:35:09 +01:00
const updateTwitterUI = ( ) => {
if ( ! twitterBtn || ! twitterLabel ) return ;
//this is so shitty but it works so i dont care
fetch ( "/api/v1/me/twitter/status" , { credentials : 'include' } )
. then ( res => res . ok ? res . json ( ) : null )
. then ( data => {
if ( data && data . is _linked ) {
twitterBtn . dataset . linked = "true" ;
twitterLabel . src = "/assets/en/svg/text/menu/tx_twitter_Cancel-34186e4e830964405f2528210d7278206d255bf40b69559babc36a7a041e0394.svg" ;
twitterLabel . alt = "Unlink Twitter" ;
twitterLabel . style . scale = "1.6" ;
twitterLabel . style . marginLeft = "30px" ;
twitterLabel . style . translate = "-10px -2px" ;
} else {
twitterBtn . dataset . linked = "false" ;
twitterLabel . src = "/assets/en/svg/text/menu/tx_twitter-47ce083cc4514ab6aeb75b7dd9f71ce89ddc54a18d930d90cf4df62047413831.svg" ;
twitterLabel . alt = "Link Twitter" ;
twitterLabel . style . height = "" ;
twitterLabel . style . transform = "" ;
}
} )
. catch ( ( ) => {
twitterBtn . dataset . linked = "false" ;
} ) ;
} ;
2026-03-18 21:13:52 +01:00
const renderData = ( data ) => {
if ( typeof data === 'string' ) {
try { data = JSON . parse ( data ) ; } catch ( e ) { }
}
const nameEl = document . getElementById ( 'mii-name' ) ;
const imgEl = document . getElementById ( 'mii-img' ) ;
const miiBlob = ( data . mii && data . mii . data ) || data . mii _data ;
2026-02-21 06:16:14 +01:00
2026-03-18 21:13:52 +01:00
if ( nameEl ) {
const parsedName = miiBlob ? extractMiiName ( miiBlob ) : null ;
nameEl . textContent = parsedName || ( data . mii && data . mii . name ) || data . nickname || data . username || "User" ;
}
2026-02-21 06:16:14 +01:00
2026-03-18 21:13:52 +01:00
if ( imgEl && miiBlob ) {
2026-07-18 04:11:47 +02:00
imgEl . src = ` https://mii-renderer.bloxerhd.co.uk/miis/image.png?data= ${ encodeURIComponent ( miiBlob ) } &type=face&width=270 ` ;
2026-03-18 21:13:52 +01:00
imgEl . style . display = 'block' ;
2026-02-21 06:16:14 +01:00
}
2026-03-22 23:35:09 +01:00
updateTwitterUI ( ) ;
2026-03-18 21:13:52 +01:00
} ;
2026-02-11 04:48:16 +01:00
2026-03-18 21:13:52 +01:00
const cached = sessionStorage . getItem ( 'user_cache' ) ;
if ( cached ) renderData ( JSON . parse ( cached ) ) ;
fetch ( "/api/v1/me" , { credentials : 'include' } )
2026-03-22 23:35:09 +01:00
. then ( res => res . redirected ? ( window . location . href = res . url ) : ( res . ok ? res . json ( ) : Promise . reject ( res ) ) )
2026-03-18 21:13:52 +01:00
. then ( data => {
2026-03-21 03:42:36 +01:00
if ( ! data ) return ;
2026-03-18 21:13:52 +01:00
sessionStorage . setItem ( 'user_cache' , JSON . stringify ( data ) ) ;
renderData ( data ) ;
} )
. catch ( ( ) => {
if ( ! cached ) {
const nameEl = document . getElementById ( 'mii-name' ) ;
if ( nameEl ) nameEl . textContent = "Guest" ;
}
} ) ;
const loadingOverlay = document . getElementById ( "loading-overlay" ) ;
if ( loadingOverlay ) loadingOverlay . style . display = "none" ;
2026-02-07 00:51:33 +01:00
} ) ;
2026-02-04 05:56:59 +01:00
function friendsbox ( ) {
const infoBox = document . createElement ( 'div' ) ;
infoBox . className = 'splat-info-box' ;
2026-03-18 21:13:52 +01:00
infoBox . innerHTML = ` <p>In Splatoon, you can join online matches that your friends are participating in. Here will show your friends that are online. Register your friends on Wii U and play Splatoon!</p> ` ;
2026-02-04 05:56:59 +01:00
const contentArea = document . querySelector ( '.content' ) ;
2026-03-18 21:13:52 +01:00
if ( contentArea ) contentArea . appendChild ( infoBox ) ;
2026-02-04 05:56:59 +01:00
}
friendsbox ( ) ;