From 9bccd3a4f1cdba1d127e148496cc1a5b66dc9a87 Mon Sep 17 00:00:00 2001 From: Ross Date: Sun, 5 Jul 2026 22:37:58 +0100 Subject: [PATCH] feat: implement force reset functionality to clear local data and storage --- css/main.css | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 26 +++++----- js/main.js | 30 ++++++++++++ 3 files changed, 177 insertions(+), 13 deletions(-) diff --git a/css/main.css b/css/main.css index 4ff4ae0..04171e7 100644 --- a/css/main.css +++ b/css/main.css @@ -1432,4 +1432,138 @@ h2:has(+ #exam-list:empty), h2:has(+ #packet-list:empty){ border-radius: 5px; cursor: pointer; z-index: 10000; +} + +/* Options and Cache Tidy Up */ +.options-details, .cache-details-box { + background: #181818; + border: 1px solid #333; + border-radius: 6px; + margin-bottom: 15px; + padding: 12px 18px; + font-family: sans-serif; +} + +.options-details summary, .cache-details-box summary { + font-weight: bold; + cursor: pointer; + font-size: 15px; + outline: none; + color: #e0e0e0; +} + +.options-details summary:hover, .cache-details-box summary:hover { + color: #fff; +} + +.options-details[open], .cache-details-box[open] { + border-color: #444; +} + +.options-details[open] summary, .cache-details-box[open] summary { + border-bottom: 1px solid #333; + padding-bottom: 8px; + margin-bottom: 12px; +} + +.database-btn-group { + display: flex; + flex-wrap: wrap; + gap: 10px; + margin-bottom: 15px; +} + +.database-btn-group input[type="button"] { + background: #2a2a2a; + color: #eee; + border: 1px solid #444; + padding: 8px 14px; + border-radius: 4px; + cursor: pointer; + font-size: 12px; + font-weight: bold; + transition: background-color 0.2s, border-color 0.2s; +} + +.database-btn-group input[type="button"]:hover { + background: #3a3a3a; + border-color: #666; +} + +.database-btn-group input#btn-delete-answer-databases { + background: #5f0909; + border-color: #8c0d0d; + color: #ffcdd2; +} + +.database-btn-group input#btn-delete-answer-databases:hover { + background: #8c0d0d; + border-color: #b71c1c; +} + +.database-btn-group input#btn-reset-local { + background: #5d2e00; + border-color: #8c4600; + color: #ffe0b2; +} + +.database-btn-group input#btn-reset-local:hover { + background: #8c4600; + border-color: #e65100; +} + +.local-loader-field { + border: 1px solid #333; + padding: 15px; + border-radius: 6px; + background: #111; + margin-bottom: 15px; +} + +.local-loader-field h2 { + margin-top: 0; + font-size: 14px; + color: #ccc; + margin-bottom: 10px; +} + +.local-loader-field input[type="file"] { + background: #222; + border: 1px solid #333; + color: #eee; + padding: 4px; + border-radius: 4px; + font-size: 12px; +} + +.local-loader-field input[type="button"] { + background: #311B92; + color: #fff; + border: none; + padding: 6px 12px; + border-radius: 4px; + font-weight: bold; + cursor: pointer; + font-size: 12px; + margin-left: 5px; +} + +.local-loader-field input[type="button"]:hover { + background: #4527A0; +} + +.view-answers-btn { + background: #2e7d32; + color: white; + border: none; + padding: 10px 16px; + border-radius: 4px; + font-size: 13px; + font-weight: bold; + cursor: pointer; + transition: background-color 0.2s; +} + +.view-answers-btn:hover { + background: #388e3c; } \ No newline at end of file diff --git a/index.html b/index.html index dcd462e..243d1e9 100644 --- a/index.html +++ b/index.html @@ -210,16 +210,16 @@ -
+
-
- -
    +
    + Cached Exams / Questions +
      -
      +
      Options -
      +
      -
      +
      -
      +

      Load local question set

      -

      -

      -
      - - diff --git a/js/main.js b/js/main.js index 7587521..f9cf338 100644 --- a/js/main.js +++ b/js/main.js @@ -44,6 +44,36 @@ function initLogging() { initLogging(); +function checkForceReset() { + try { + const urlParams = new URLSearchParams(window.location.search); + if (urlParams.get("reset") === "1" || urlParams.get("reset") === "true") { + log.info("Force reset parameter detected. Resetting all local data..."); + + // Clear databases + try { + window.indexedDB.deleteDatabase("answers_database"); + window.indexedDB.deleteDatabase("questions_database"); + } catch (dbErr) { + log.error("Failed to delete indexedDB databases:", dbErr); + } + + // Clear storage + localStorage.clear(); + sessionStorage.clear(); + + // Clean query parameter from URL to prevent infinite loops, notify and reload + const cleanUrl = window.location.protocol + "//" + window.location.host + window.location.pathname; + alert("The application has been completely reset. All local data, storage, and databases have been cleared. Click OK to reload."); + window.location.href = cleanUrl; + } + } catch (e) { + log.error("Error during force reset:", e); + } +} + +checkForceReset(); + let URLS = {};