名前の色

This commit is contained in:
2025-12-07 21:48:42 +09:00
parent 1ee2760c8e
commit f6389eedc9
2 changed files with 21 additions and 3 deletions

View File

@@ -139,7 +139,25 @@ function assert_unless_success(Result $assertion, Throwable|string|null $descrip
if (AUTH_ENABLED) { if (AUTH_ENABLED) {
function getcookie(string $name): string|null { function getcookie(string $name): string|null {
if (!$_COOKIE[$name]) return null; return $_COOKIE[$name] ?? null;
return $_COOKIE[$name]; }
function namecolor(\stdClass $userData): string {
$ban = "#888888";
$male = "#97ACEF";
$female = "#F185C9";
$ungender = "#7C60B0";
$gender = 'color: '.($userData->gender === 0 ? $male : ($userData->gender === 1 ? $female : $ungender)).';';
$style = $userData->namecolor ?: ($userData->role >= 0 ? $gender : $ban);
$showname = $userData->displayname ?? $userData->username;
$color = "<span style=\"{$style}\">{$showname}</span>";
if ($userData->role === 1) $color .= "<span style=\"font-size: x-small; background: #10c074; border: 1px solid #fcfcfc; border-radius: 10px; padding: 0 0.5em;\">✓</span>";
$suffix = $userData->gender === 0 ? 'くん' : ($userData->gender === 1 ? 'ちゃん' : 'さん');
return $color.$suffix;
} }
} }

View File

@@ -59,7 +59,7 @@
{@ if (AUTH_ENABLED) @} {@ if (AUTH_ENABLED) @}
<div> <div>
{@ if (isset($user) && isset($user->id) && $user->id > 0) @} {@ if (isset($user) && isset($user->id) && $user->id > 0) @}
お帰りなしゃ~い、{{ $user->displayname ?? $user->username }}さん (<a href="/logout">ログアウト</a>) お帰りなしゃ~い、{{{ namecolor($user) }}} (<a href="/logout">ログアウト</a>)
{@ else @} {@ else @}
<a href="/login">ログイン</a> <a href="/login">ログイン</a>
{@ if (AUTH_REGISTER_ENABLED) @} {@ if (AUTH_REGISTER_ENABLED) @}