diff --git a/src/main/resources/static/js/cacheFormInputs.js b/src/main/resources/static/js/cacheFormInputs.js index 1cd504b7f..64760bf41 100644 --- a/src/main/resources/static/js/cacheFormInputs.js +++ b/src/main/resources/static/js/cacheFormInputs.js @@ -1,10 +1,10 @@ document.addEventListener("DOMContentLoaded", function() { - + var cacheInputs = localStorage.getItem("cacheInputs") || "disabled"; if (cacheInputs !== "enabled") { return; // Stop execution if caching is not enabled } - + // Function to generate a key based on the form's action attribute function generateStorageKey(form) { const action = form.getAttribute('action'); @@ -24,11 +24,11 @@ document.addEventListener("DOMContentLoaded", function() { for (let i = 0; i < elements.length; i++) { const element = elements[i]; // Skip elements without names, passwords, files, hidden fields, and submit/reset buttons - if (!element.name || - element.type === 'password' || - element.type === 'file' || - //element.type === 'hidden' || - element.type === 'submit' || + if (!element.name || + element.type === 'password' || + element.type === 'file' || + //element.type === 'hidden' || + element.type === 'submit' || element.type === 'reset') { continue; } diff --git a/src/main/resources/static/js/csrf.js b/src/main/resources/static/js/csrf.js index 2dc1c0ca2..20b8b00f1 100644 --- a/src/main/resources/static/js/csrf.js +++ b/src/main/resources/static/js/csrf.js @@ -18,7 +18,7 @@ document.addEventListener('DOMContentLoaded', function() { // Find all forms and add CSRF token const forms = document.querySelectorAll('form'); const csrfToken = decodeCsrfToken(getCsrfToken()); - + // Only proceed if we have a cookie-based token if (csrfToken) { forms.forEach(form => { @@ -34,4 +34,4 @@ document.addEventListener('DOMContentLoaded', function() { form.appendChild(csrfInput); }); } -}); \ No newline at end of file +}); diff --git a/src/main/resources/static/js/darkmode.js b/src/main/resources/static/js/darkmode.js index 08c0c380d..abfe737c9 100644 --- a/src/main/resources/static/js/darkmode.js +++ b/src/main/resources/static/js/darkmode.js @@ -102,4 +102,4 @@ document.addEventListener("DOMContentLoaded", function () { toggleDarkMode(); }); } -}); \ No newline at end of file +}); diff --git a/src/main/resources/static/js/fetch-utils.js b/src/main/resources/static/js/fetch-utils.js index d606d71ac..dfe2604a8 100644 --- a/src/main/resources/static/js/fetch-utils.js +++ b/src/main/resources/static/js/fetch-utils.js @@ -4,7 +4,7 @@ window.fetchWithCsrf = async function(url, options = {}) { .split('; ') .find(row => row.startsWith('XSRF-TOKEN=')) ?.split('=')[1]; - + if (cookieValue) { return cookieValue; } @@ -14,10 +14,10 @@ window.fetchWithCsrf = async function(url, options = {}) { // Create a new options object to avoid modifying the passed object const fetchOptions = { ...options }; - + // Ensure headers object exists fetchOptions.headers = { ...options.headers }; - + // Add CSRF token if available const csrfToken = getCsrfToken(); if (csrfToken) { @@ -25,4 +25,4 @@ window.fetchWithCsrf = async function(url, options = {}) { } return fetch(url, fetchOptions); -} \ No newline at end of file +} diff --git a/src/main/resources/static/js/game.js b/src/main/resources/static/js/game.js index 3746ef63d..df04c5dd5 100644 --- a/src/main/resources/static/js/game.js +++ b/src/main/resources/static/js/game.js @@ -32,8 +32,8 @@ function initializeGame() { const BASE_SPAWN_INTERVAL_MS = 1250; // milliseconds before a new enemy spawns const LEVEL_INCREASE_FACTOR_MS = 25; // milliseconds to decrease the spawn interval per level const MAX_SPAWN_RATE_REDUCTION_MS = 800; // Max milliseconds from the base spawn interval - - + + let keysPressed = {}; const pdfs = []; const projectiles = []; @@ -42,7 +42,7 @@ function initializeGame() { let pdfSpeed = BASE_PDF_SPEED; let gameOver = false; - + function handleKeys() { if (keysPressed["ArrowLeft"]) { playerX -= PLAYER_MOVE_SPEED; @@ -72,7 +72,7 @@ function initializeGame() { function onKeyUp(event) { keysPressed[event.key] = false; } - + document.removeEventListener("keydown", onKeydown); document.removeEventListener("keyup", onKeyUp); document.addEventListener("keydown", onKeydown); @@ -243,7 +243,7 @@ function initializeGame() { let spawnPdfTimeout; - + function spawnPdfInterval() { if (gameOver || paused) { diff --git a/src/main/resources/static/js/settings.js b/src/main/resources/static/js/settings.js index 8f6289af2..6954913c5 100644 --- a/src/main/resources/static/js/settings.js +++ b/src/main/resources/static/js/settings.js @@ -39,4 +39,3 @@ document.getElementById("cacheInputs").addEventListener("change", function () { cacheInputs = this.checked ? "enabled" : "disabled"; localStorage.setItem("cacheInputs", cacheInputs); }); - diff --git a/src/main/resources/templates/account.html b/src/main/resources/templates/account.html index c26b93d0c..0fa365043 100644 --- a/src/main/resources/templates/account.html +++ b/src/main/resources/templates/account.html @@ -308,37 +308,36 @@ document.getElementById('syncToAccount').addEventListener('click', async function() { /**/ - - let settings = {}; - for (let i = 0; i < localStorage.length; i++) { - const key = localStorage.key(i); - if(key !== 'debug' && key !== '0' && key !== '1' && !key.includes('pdfjs') && !key.includes('posthog') && !key.includes('pageViews')) { - settings[key] = localStorage.getItem(key); - } - } - - try { - const response = await window.fetchWithCsrf(urlUpdateUserSettings, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(settings) - }); - - if (response.ok) { - location.reload(); - } else { - alert('Error syncing settings to account'); - } - } catch (error) { - console.error('Error:', error); - alert('Error syncing settings to account'); - } - }); + const urlUpdateUserSettings = /*[[@{/api/v1/user/updateUserSettings}]]*/ "/api/v1/user/updateUserSettings"; + /*]]>*/ + let settings = {}; + for (let i = 0; i < localStorage.length; i++) { + const key = localStorage.key(i); + if(key !== 'debug' && key !== '0' && key !== '1' && !key.includes('pdfjs') && !key.includes('posthog') && !key.includes('pageViews')) { + settings[key] = localStorage.getItem(key); + } + } + + try { + const response = await window.fetchWithCsrf(urlUpdateUserSettings, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(settings) + }); + + if (response.ok) { + location.reload(); + } else { + alert('Error syncing settings to account'); + } + } catch (error) { + console.error('Error:', error); + alert('Error syncing settings to account'); + } + }); });