Files
Groove_Coaster_2_Server/new_server_7003/web/user.html
UnitedAirforce 10bbd03bb6 v3 push
2025-11-26 13:49:27 +08:00

79 lines
2.7 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>User Information</title>
<!-- Include Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
background-color: #000000;
}
#welcome-title {
color: #ffffff;
font-family: Arial, sans-serif;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container mt-5">
<div class="text-center">
<!-- Title -->
<h1 id="welcome-title">Hello, {username}</h1>
<!-- Export Data Button -->
<button id="export-button" class="btn btn-primary mt-3">Export Data</button>
</div>
</div>
<script>
// Function to get a cookie value by name
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
}
// Fetch user data from the API
async function fetchUserData() {
const token = getCookie("token"); // Read the token from the cookie
if (!token) {
console.error("Token not found in cookies.");
return;
}
try {
// Query the API
const response = await fetch("/usercenter/api", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
token: token,
action: "basic"
})
});
if (!response.ok) {
console.error("Failed to fetch user data:", response.statusText);
return;
}
// Parse the response data
const response_data = await response.json();
const username = response_data.data.username || "User";
// Update the username in the title
document.getElementById("welcome-title").textContent = `Hello, ${username}`;
} catch (error) {
console.error("Error fetching user data:", error);
}
}
// Call the function to fetch user data when the page loads
document.addEventListener("DOMContentLoaded", fetchUserData);
</script>
</body>
</html>