From 0c71d1ccf83f825f7d9361b506f223cfd4f8481e Mon Sep 17 00:00:00 2001 From: Shubham-Patel07 Date: Mon, 18 Dec 2023 21:41:26 +0530 Subject: [PATCH 01/40] Fix: Used get(0) function insted of getFirst() to check weather the string is not empty, in ChallangeController and ChallengeUI --- .../java/org/owasp/wrongsecrets/challenges/ChallengeUI.java | 2 +- .../org/owasp/wrongsecrets/challenges/ChallengesController.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/owasp/wrongsecrets/challenges/ChallengeUI.java b/src/main/java/org/owasp/wrongsecrets/challenges/ChallengeUI.java index ad520dd5d..74ba9a104 100644 --- a/src/main/java/org/owasp/wrongsecrets/challenges/ChallengeUI.java +++ b/src/main/java/org/owasp/wrongsecrets/challenges/ChallengeUI.java @@ -105,7 +105,7 @@ private String documentation(Function extractor) { return challengeDefinition.source(runtimeEnvironment).map(extractor).orElse(""); } else { // We cannot run the challenge but showing documentation should still be possible - return extractor.apply(challengeDefinition.sources().getFirst()); + return extractor.apply(challengeDefinition.sources().get(0)); } } diff --git a/src/main/java/org/owasp/wrongsecrets/challenges/ChallengesController.java b/src/main/java/org/owasp/wrongsecrets/challenges/ChallengesController.java index 3bcbf7cb1..aa5c2bb6e 100644 --- a/src/main/java/org/owasp/wrongsecrets/challenges/ChallengesController.java +++ b/src/main/java/org/owasp/wrongsecrets/challenges/ChallengesController.java @@ -97,7 +97,7 @@ public String spoiler(@PathVariable("short-name") String shortName, Model model) Supplier spoilerFromRandomChallenge = () -> { var challengeDefinition = findByShortName(shortName); - return challenges.getChallenge(challengeDefinition).getFirst().spoiler(); + return challenges.getChallenge(challengeDefinition).get(0).spoiler(); }; // We always want to show the spoiler even if we run in a non-supported environment From 71c285cb3f5df20e5d6756d554b48c85a4108fc6 Mon Sep 17 00:00:00 2001 From: Shubham-Patel07 Date: Fri, 12 Jan 2024 22:55:29 +0530 Subject: [PATCH 02/40] Add: changed the logic of button from racdio button to checkbox --- src/main/resources/static/theme-toggle.js | 60 +- .../resources/templates/fragments/header.html | 25 +- src/test/e2e/package-lock.json | 5876 +++++++++++++++++ src/test/e2e/package.json | 4 +- 4 files changed, 5925 insertions(+), 40 deletions(-) create mode 100644 src/test/e2e/package-lock.json diff --git a/src/main/resources/static/theme-toggle.js b/src/main/resources/static/theme-toggle.js index ef196354f..97b9ed6cf 100644 --- a/src/main/resources/static/theme-toggle.js +++ b/src/main/resources/static/theme-toggle.js @@ -1,34 +1,38 @@ (function () { - const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)') - let initialTheme - if (localStorage.getItem('darkmode-pref-set') === 'true') { - initialTheme = localStorage.getItem('darkMode') === 'true' - } else { - initialTheme = darkModeMediaQuery.matches - } + const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)'); - function updateToggle (darkMode) { - document.querySelector(".theme-toggle input[type=radio][value='dark']").checked = darkMode - document.querySelector(".theme-toggle input[type=radio][value='light']").checked = !darkMode + function updateToggle(darkMode) { + const checkbox = document.querySelector(".theme-toggle input[type='checkbox']"); + if (checkbox) { + checkbox.checked = darkMode; + } - document.body.classList.toggle('dark-mode', darkMode) - localStorage.setItem('darkMode', darkMode) - localStorage.setItem('darkmode-pref-set', 'true') - } + document.body.classList.toggle('dark-mode', darkMode); + localStorage.setItem('darkMode', darkMode); + localStorage.setItem('darkmode-pref-set', 'true'); + } - darkModeMediaQuery.addEventListener('change', (e) => { - const darkModeOn = e.matches - updateToggle(darkModeOn) - }) + // Listen for system theme changes + darkModeMediaQuery.addEventListener('change', (e) => { + updateToggle(e.matches); + }); - window.addEventListener('load', function () { - const radios = document.querySelectorAll('.theme-toggle input[type=radio]') - radios.forEach((radio) => { - radio.addEventListener('change', function (e) { - updateToggle(e.target.value === 'dark') - }) - }) + // Set up event listener and initial theme on page load + window.addEventListener('load', function () { + const checkbox = document.querySelector(".theme-toggle input[type='checkbox']"); + if (checkbox) { + checkbox.addEventListener('change', function () { + updateToggle(checkbox.checked); + }); - updateToggle(initialTheme) - }) -})() + // Initialize theme based on user preference or system preference + let initialTheme; + if (localStorage.getItem('darkmode-pref-set') === 'true') { + initialTheme = localStorage.getItem('darkMode') === 'true'; + } else { + initialTheme = darkModeMediaQuery.matches; + } + updateToggle(initialTheme); + } + }); +})(); diff --git a/src/main/resources/templates/fragments/header.html b/src/main/resources/templates/fragments/header.html index 8b2a6080c..44fefc2fd 100644 --- a/src/main/resources/templates/fragments/header.html +++ b/src/main/resources/templates/fragments/header.html @@ -51,16 +51,21 @@ About -