2018-11-15 22:53:52 +00:00
interface CurrentUserInfo {
user_id : number ;
username : string ;
user_background_settings : number ;
user_colour : number ;
}
let userInfo : CurrentUserInfo ;
function getRawCurrentUserInfo ( ) : CurrentUserInfo
{
const userInfoElement : HTMLDivElement = document . getElementById ( 'js-user-info' ) as HTMLDivElement ;
if ( ! userInfoElement )
return null ;
return JSON . parse ( userInfoElement . textContent ) as CurrentUserInfo ;
}
function refreshCurrentUserInfo ( ) : void
{
userInfo = getRawCurrentUserInfo ( ) ;
}
function getCurrentUser ( attribute : string = null )
{
if ( attribute ) {
if ( ! userInfo ) {
return '' ;
}
return userInfo [ attribute ] || '' ;
}
return userInfo || null ;
}
function userInit ( ) : void
{
refreshCurrentUserInfo ( ) ;
2018-12-11 00:35:33 +00:00
console . log ( ` You are ${ getCurrentUser ( 'username' ) } with user id ${ getCurrentUser ( 'user_id' ) } and colour ${ colourGetCSS ( getCurrentUser ( 'user_colour' ) ) } . ` ) ;
2018-11-15 22:53:52 +00:00
}