mirror of
https://github.com/Grasscutters/GrassClipper.git
synced 2024-08-14 13:11:48 +08:00
clean alert functions
This commit is contained in:
parent
bf06b92fde
commit
71c3cc7837
@ -1,42 +1,16 @@
|
|||||||
let alertTimeout, alertCooldown = 3000
|
let alertTimeout, alertCooldown = 3000
|
||||||
|
|
||||||
async function displayLoginAlert(message, type, cooldown = null) {
|
async function displayLoginAlert(message, type, cooldown = null) {
|
||||||
const elm = document.getElementById('loginAlert');
|
displayAlert(message, type, cooldown, 'login')
|
||||||
const text = document.getElementById('loginAlertText');
|
|
||||||
|
|
||||||
elm.style.removeProperty('display');
|
|
||||||
|
|
||||||
// Remove classification classes
|
|
||||||
elm.classList.remove('error');
|
|
||||||
elm.classList.remove('success');
|
|
||||||
elm.classList.remove('warn');
|
|
||||||
|
|
||||||
switch(type) {
|
|
||||||
case 'error':
|
|
||||||
elm.classList.add('error');
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'success':
|
|
||||||
elm.classList.add('success');
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'warn':
|
|
||||||
default:
|
|
||||||
elm.classList.add('warn');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
text.innerText = message;
|
|
||||||
|
|
||||||
// Disappear after cooldown
|
|
||||||
alertTimeout = setTimeout(() => {
|
|
||||||
elm.style.display = 'none';
|
|
||||||
}, cooldown || alertCooldown)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function displayRegisterAlert(message, type, cooldown = null) {
|
async function displayRegisterAlert(message, type, cooldown = null) {
|
||||||
const elm = document.getElementById('registerAlert');
|
displayAlert(message, type, cooldown, 'register')
|
||||||
const text = document.getElementById('registerAlertText');
|
}
|
||||||
|
|
||||||
|
function displayAlert(message, type, cooldown, name) {
|
||||||
|
const elm = document.getElementById(`${name}Alert`);
|
||||||
|
const text = document.getElementById(`${name}AlertText`);
|
||||||
|
|
||||||
elm.style.removeProperty('display');
|
elm.style.removeProperty('display');
|
||||||
|
|
||||||
@ -62,6 +36,8 @@ async function displayRegisterAlert(message, type, cooldown = null) {
|
|||||||
|
|
||||||
text.innerText = message;
|
text.innerText = message;
|
||||||
|
|
||||||
|
clearTimeout(alertTimeout)
|
||||||
|
|
||||||
// Disappear after cooldown
|
// Disappear after cooldown
|
||||||
alertTimeout = setTimeout(() => {
|
alertTimeout = setTimeout(() => {
|
||||||
elm.style.display = 'none';
|
elm.style.display = 'none';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user