1
0
mirror of https://dev.s-ul.net/Galexion/MaiMaiDXNet.git synced 2024-11-24 08:50:10 +01:00
MaiMaiDXNet/views/user.ejs
2023-02-17 01:23:14 -05:00

102 lines
4.7 KiB
Plaintext

<% var rootPath='../' ; %>
<%- include(rootPath + 'templates/header.ejs' ); %>
<% function normalizeText(text) { return text .normalize('NFD') .replace(/[\u0300-\u036f]/g, '' )
.replace(/[\uFF01-\uFF5E]/g, function(ch) { return String.fromCharCode(ch.charCodeAt(0) - 0xFEE0); }); } %>
<link href="/stylesheets/user.css" rel="stylesheet" type="text/css">
<div id="User">
<h1>Yo! Welcome Back <%= normalizeText(userdata.user_name) %>!</h1>
<button id="clear-storage-btn">Sign Out</button>
<script>
const extId = localStorage.getItem('ext_id');
const luid = localStorage.getItem('luid');
const clearStorageBtn = document.getElementById('clear-storage-btn');
clearStorageBtn.addEventListener('click', () => {
// Remove the cookies
function removeCookies() {
// Set the expiration date to a date in the past
const expirationDate = new Date(0).toUTCString();
// Set the ext_id cookie to expire
document.cookie = `ext_id=; expires=${expirationDate}`;
// Set the luid cookie to expire
document.cookie = `luid=; expires=${expirationDate}`;
// Set the aime_card_id cookie to expire
document.cookie = `aime_card_id=; expires=${expirationDate}`;
}
// Example usage
removeCookies();
console.log('Local storage cleared.');
window.location = "/";
});
// Get the cookie string
const cookieString = document.cookie;
// Parse the cookie string and extract the values
const cookies = cookieString.split(';');
let ext_id2, luid2;
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
const cookieParts = cookie.split('=');
if (cookieParts[0] === 'ext_id') {
ext_id2 = cookieParts[1];
}
if (cookieParts[0] === 'luid') {
luid2 = cookieParts[1];
}
}
// Use the values as needed
if (ext_id2 && luid2) {
console.log(`ext_id: ${ext_id2}, luid: ${luid2}`);
} else {
console.log('User Data Not Detected! Please Sign In.');
window.location = "/";
}
</script>
<% if(userdata.icon_id===10) { %>
<img id="user-image" src="" alt="User Image">
<script>
const userImage = document.getElementById('user-image');
userImage.src = "images/" + ext_id2 + '-up.jpg';
</script>
<% } else {%>
<img id="user-image" src="" alt="User Image">
<script data-userdata="<%=JSON.stringify(userdata)%>">
const userdata = JSON.parse(document.currentScript.getAttribute('data-userdata'));
const userImage = document.getElementById('user-image');
const UI_Icon = userdata.icon_id
function padNumber(num, size) {
var s = num + "";
while (s.length < size) s = "0" + s;
return s;
}
// Usage:
userImage.src = "assets/icon/UI_Icon_" + padNumber(Number(UI_Icon),6) + '.png';
</script>
<%}%>
<details>
<summary>Developer Only Information</summary>
For Development purposes only, send statistics found in this menu when encontering UI
Errors.
<details>
<summary>Raw User Details</summary>
<pre><code><%=JSON.stringify(userdata, null, 2)%></code></pre>
</details>
</details>
</div>