diff --git a/js/admin.js b/js/admin.js index a21ae60..10bcdd8 100644 --- a/js/admin.js +++ b/js/admin.js @@ -208,6 +208,7 @@ export const admin = (() => { storage('config').clear(); storage('comment').clear(); storage('session').clear(); + storage('information').clear(); } if (!session.isAdmin() || (JSON.parse(atob((session.getToken() ?? '.').split('.')[1])).exp ?? 0) < ((new Date()).getTime() / 1000)) { diff --git a/js/comment.js b/js/comment.js index 3d3016b..ac26ad9 100644 --- a/js/comment.js +++ b/js/comment.js @@ -177,14 +177,19 @@ export const comment = (() => { } const btn = util.disableButton(button); + const isPresence = presence ? presence.value === "1" : true; if (!session.isAdmin()) { storage('information').set('name', nameValue); + + if (!id) { + storage('information').set('presence', isPresence); + } } const response = await request(HTTP_POST, '/api/comment') .token(session.getToken()) - .body(dto.postCommentRequest(id, nameValue, presence ? presence.value === "1" : true, form.value)) + .body(dto.postCommentRequest(id, nameValue, isPresence, form.value)) .send(dto.postCommentResponse) .then((res) => res, () => null); @@ -210,10 +215,6 @@ export const comment = (() => { owns.set(response.data.uuid, response.data.own); form.value = null; - if (presence) { - presence.value = "0"; - } - if (!id) { const newPage = await pagination.reset(); if (newPage) { diff --git a/js/guest.js b/js/guest.js index 69187d6..a728597 100644 --- a/js/guest.js +++ b/js/guest.js @@ -7,6 +7,8 @@ import { confetti } from './confetti.js'; export const guest = (() => { + const information = storage('information'); + const countDownDate = () => { const until = document.getElementById('count-down')?.getAttribute('data-time')?.replace(' ', 'T'); if (!until) { @@ -81,7 +83,7 @@ export const guest = (() => { const form = document.getElementById('form-name'); if (form) { - form.value = storage('information').get('name') ?? name; + form.value = information.get('name') ?? name; } util.opacity('loading', 0.025); @@ -118,8 +120,13 @@ export const guest = (() => { storage('tracker').clear(); } + const presence = document.getElementById('form-presence'); + if (presence && information.get('presence') !== undefined) { + presence.value = information.get('presence') ? "1" : "2"; + } + const info = document.getElementById('information'); - if (info && storage('information').get('info')) { + if (info && information.get('info')) { info.remove(); } diff --git a/js/pagination.js b/js/pagination.js index 1b2324b..3c2631f 100644 --- a/js/pagination.js +++ b/js/pagination.js @@ -63,7 +63,7 @@ export const pagination = (() => { }; const reset = async () => { - if (pageNow == 0) { + if (pageNow === 0) { return false; } diff --git a/js/storage.js b/js/storage.js index 078f6c5..553ca70 100644 --- a/js/storage.js +++ b/js/storage.js @@ -11,6 +11,8 @@ export const storage = (table) => { localStorage.setItem(table, JSON.stringify(storage)); }; + const has = (key) => Object.keys(get()).includes(String(key)); + const unset = (key) => { if (!has(key)) { return; @@ -21,8 +23,6 @@ export const storage = (table) => { localStorage.setItem(table, JSON.stringify(storage)); }; - const has = (key) => Object.keys(get()).includes(String(key)); - const clear = () => localStorage.setItem(table, JSON.stringify({})); if (!localStorage.getItem(table)) { diff --git a/js/theme.js b/js/theme.js index e6c3ad5..46822f3 100644 --- a/js/theme.js +++ b/js/theme.js @@ -129,10 +129,12 @@ export const theme = (() => { } } + const toggle = document.getElementById('darkMode'); + if (isDarkMode()) { onDark(); document.documentElement.setAttribute(THEME_BS_DATA, THEME_DARK); - const toggle = document.getElementById('darkMode'); + theme.set('active', THEME_DARK); if (toggle) { toggle.checked = true; } @@ -140,7 +142,6 @@ export const theme = (() => { onLight(); document.documentElement.setAttribute(THEME_BS_DATA, THEME_LIGHT); theme.set('active', THEME_LIGHT); - const toggle = document.getElementById('darkMode'); if (toggle) { toggle.checked = false; }