cant you just use a php widget and do this
PHP Code:
if ($vbulletin->userinfo['userid'] > 0) {
$username = $vbulletin->userinfo['username'];
echo 'Welcome ' . $username . '!';
} else {
echo 'Welcome Guest!';
}
P.S. I doubt the code above works, its a proof of concept.
Try this if you want to stick to JS
HTML Code:
var username =$vbulletin->bbuserinfo['username'];
not sure if single quotes are needed in JS.