Skip to content

First Issue Hide Clock Toggle#150

Open
anishgude wants to merge 2 commits intoprem-k-r:mainfrom
anishgude:main
Open

First Issue Hide Clock Toggle#150
anishgude wants to merge 2 commits intoprem-k-r:mainfrom
anishgude:main

Conversation

@anishgude
Copy link

@anishgude anishgude commented Feb 18, 2026

📌 Description

🎨 Visual Changes (Screenshots / Videos)

🔗 Related Issues

  • Closes #<issue_number>
  • Related to #<issue_number>

✅ Checklist

  • I have read and followed the Contributing Guidelines.
  • My code follows the project's coding style and conventions.
  • I have tested my changes thoroughly to ensure expected behavior.
  • I have verified compatibility across Chrome and Firefox (additional browsers if applicable).
  • I have attached relevant visual evidence (screenshots/videos) if applicable.
  • I have updated the CHANGELOG.md under the appropriate categories with all my changes in this PR.

Hide Clock Toggle Implementation

This PR refactors the clock visibility toggle from a "hide" perspective to a more intuitive "show" perspective.

Changes

index.html:

  • Changed the clock visibility toggle label from "Hide Clock" to "Show Clock"
  • Updated the associated checkbox input ID from "hideClock" to "showClock"

scripts/clock.js:

  • Refactored the entire clock visibility system to use a showClock state instead of hideClock
  • showClock now defaults to "true" in localStorage, meaning the clock displays by default
  • Updated handleClockVisibility() to derive visibility directly from the showClock localStorage value
  • Added a change listener to the showClockCheckbox that:
    • Persists the checked state to localStorage
    • Applies corresponding CSS classes to show/hide the clock and adjust layout
    • Initializes the clock when enabled
  • Enhanced the displayClock() function to respect the showClock state and properly hide both analog and digital clocks when disabled
  • Simplified responsive behavior for small screens (max-width: 500px) to consistently use the showClock flag across all branches
  • Ensures the clock options styling remains consistent with the visibility state

Impact

The refactoring provides a more intuitive user interface where checking the toggle box shows the clock, and unchecking it hides it. The implementation is cleaner and eliminates the logic inversion that previously existed with the "hide" perspective.

@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

📝 Walkthrough

Walkthrough

This PR inverts the clock visibility control semantics from "hide" to "show". The checkbox input, DOM references, and localStorage keys are renamed from hideClock to showClock, and the underlying logic is updated to reflect this positive rather than negative framing throughout the HTML and JavaScript.

Changes

Cohort / File(s) Summary
UI Control Update
index.html
Renamed checkbox label from "Hide Clock" to "Show Clock" and input ID from "hideClock" to "showClock"; added final newline.
Clock Visibility Logic Refactor
scripts/clock.js
Renamed hideClock references to showClock throughout; updated localStorage initialization to default showClock to true; reworked handleClockVisibility and displayClock functions to derive state from showClock; added change listener to persist state and manage clock initialization; simplified responsive behavior to use showClock consistently across screen sizes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

refactor

🚥 Pre-merge checks | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is entirely empty—only the template structure remains with all placeholders unfilled, no actual description, screenshots, or issue references provided. Fill in the description section with the actual changes made, add related issue number(s), check applicable checklist items, and provide screenshots if visual changes apply.
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'First Issue Hide Clock Toggle' is vague and refers to a generic issue number rather than describing the actual change (switching from hide-to-show logic for clock visibility). Revise title to clearly describe the main change, such as 'Convert clock visibility toggle from hide-based to show-based logic' or 'Switch clock toggle from hide to show preference'.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
scripts/clock.js (1)

47-58: Mobile branch applies state then immediately undoes it.

Lines 49–50 call applyClockState(!isClockVisible) and toggleHideState(!isClockVisible), but lines 56–57 unconditionally remove the classes those functions just set (not-applicable, clock-padding-adjusted). When isClockVisible is false, the toggle/apply calls are effectively no-ops.

If this is intentional (mobile always shows options), the early calls are unnecessary noise; if not, line 56–57 is undoing the intended hiding. Either way this is confusing — consider restructuring to avoid the contradictory calls.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/clock.js` around lines 47 - 58, The mobile branch currently applies a
hide/show via applyClockState(!isClockVisible) and
toggleHideState(!isClockVisible) then immediately un-does those changes by
unconditionally removing classes from clockOptions and rightDiv; fix by making
the behavior consistent: either (A) if mobile should always show the
clock/options, remove the calls to applyClockState and toggleHideState and just
set showClockCheckbox.checked and call initializeClock when appropriate, or (B)
if the intent is to honor isClockVisible, move the
clockOptions.classList.remove("not-applicable") and
rightDiv.classList.remove("clock-padding-adjusted") into the same conditional
that runs when isClockVisible is true (or otherwise guard them with the proper
isClockVisible check) so applyClockState, toggleHideState, initializeClock,
clockOptions and rightDiv reflect the same visibility state.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@index.html`:
- Around line 1385-1392: The HTML hardcoded texts for the clock toggle (elements
with IDs hideClockBox and hideClockBoxInfo) are being overwritten by locale
files when applyLanguage() runs using the translationMap; update all locale
translation entries so their keys match the intended default phrasing: in every
locale file (e.g., en.js, fr.js, es.js, de.js, etc.) change the "hideClockBox"
value from "Hide Clock" to "Show Clock" and change "hideClockBoxInfo" from "Hide
the clock and date" to "Show or hide the clock and date" so translations align
with the HTML defaults and avoid semantic inversion when applyLanguage() is
applied at startup.

In `@scripts/clock.js`:
- Around line 72-86: The change listener on showClockCheckbox currently skips
calling initializeClock() when unchecked but does not stop any existing timers;
modify the handler (the function attached to showClockCheckbox.addEventListener)
to clear running intervals when hiding by calling clearInterval on
analogIntervalId and digitalIntervalId (and nulling them) before calling
applyClockState/toggleHideState, so any previously started timers from
initializeClock() are stopped when the clock is hidden; ensure you reference the
existing variables analogIntervalId and digitalIntervalId and perform the
clearInterval calls only when isChecked is false.

---

Nitpick comments:
In `@scripts/clock.js`:
- Around line 47-58: The mobile branch currently applies a hide/show via
applyClockState(!isClockVisible) and toggleHideState(!isClockVisible) then
immediately un-does those changes by unconditionally removing classes from
clockOptions and rightDiv; fix by making the behavior consistent: either (A) if
mobile should always show the clock/options, remove the calls to applyClockState
and toggleHideState and just set showClockCheckbox.checked and call
initializeClock when appropriate, or (B) if the intent is to honor
isClockVisible, move the clockOptions.classList.remove("not-applicable") and
rightDiv.classList.remove("clock-padding-adjusted") into the same conditional
that runs when isClockVisible is true (or otherwise guard them with the proper
isClockVisible check) so applyClockState, toggleHideState, initializeClock,
clockOptions and rightDiv reflect the same visibility state.

Comment on lines +1385 to 1392
<div class="bigText" id="hideClockBox">Show Clock</div>
<div class="infoText" id="hideClockBoxInfo">Show or hide the clock and date
</div>
</div>
<label class="switch">
<input id="hideClock" type="checkbox">
<input id="showClock" type="checkbox">
<span class="toggle"></span>
</label>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Comprehensive search for hideClockBox and hideClockBoxInfo references
echo "=== Searching for hideClockBox references ==="
rg "hideClockBox" -n -C 2

echo -e "\n=== Searching for hideClockBoxInfo references ==="
rg "hideClockBoxInfo" -n -C 2

echo -e "\n=== Searching for showClock references ==="
rg "showClock" -n -C 2

Repository: prem-k-r/MaterialYouNewTab

Length of output: 17772


🏁 Script executed:

#!/bin/bash
# Check how the localization system actually applies these keys to DOM elements
echo "=== Search for localization mechanism in JavaScript ==="
rg -n "hideClockBox\|hideClockBoxInfo" scripts/ -t js -C 3

echo -e "\n=== Check how languages.js keys are used ==="
rg -n "languages\[" scripts/ -t js -C 2 | head -50

echo -e "\n=== Look for text content assignment in clock.js ==="
rg -n "textContent\|innerHTML" scripts/clock.js -C 2 | grep -A2 -B2 "hideClockBox\|hideClockBoxInfo" || echo "Not found in clock.js"

echo -e "\n=== Check if HTML text should be localized ==="
cat index.html | sed -n '1383,1393p'

Repository: prem-k-r/MaterialYouNewTab

Length of output: 1058


🏁 Script executed:

#!/bin/bash
# Search more broadly for how localization keys are applied to DOM elements
echo "=== Search for text content localization patterns ==="
rg -n "textContent\|innerHTML\|innerText" scripts/ -t js -B2 -A2 | head -80

echo -e "\n=== Look for how languages array is used ==="
rg -n "languages\[" scripts/ -t js -B1 -A1 | head -60

echo -e "\n=== Check the localization/language loading mechanism ==="
rg -n "function.*language\|function.*locali" scripts/ -t js -i

echo -e "\n=== Look for getElementById with hideClockBox pattern ==="
rg -n "getElementById" scripts/ -t js | grep -i "clock\|hide"

Repository: prem-k-r/MaterialYouNewTab

Length of output: 3399


🏁 Script executed:

#!/bin/bash
# Search more specifically for localization mechanisms
echo "=== Look for where languages array elements are used ==="
rg -n "languages\s*=" scripts/ -t js -A 5

echo -e "\n=== Check how text content gets localized ==="
find scripts -name "*.js" -exec grep -l "textContent\|innerHTML" {} \; | head -5

echo -e "\n=== Search for any language setting or localization callback ==="
rg -n "setTextContent\|applyLocal\|updateText\|translation" scripts/ -t js -i

echo -e "\n=== Check if hideClockBox text is referenced in any JS files ==="
rg -n "Show Clock\|Hide Clock" scripts/ -t js

echo -e "\n=== Look at the full languages.js file to understand its purpose ==="
head -30 scripts/languages.js

Repository: prem-k-r/MaterialYouNewTab

Length of output: 1659


🏁 Script executed:

#!/bin/bash
# Look for where translations are actually applied to DOM elements
echo "=== Search for translation application patterns ==="
rg -n "translations\[" scripts/ -t js -B2 -A2

echo -e "\n=== Look for full languages.js to see how languages array is used ==="
wc -l scripts/languages.js

echo -e "\n=== Look for the key registration in languages.js ==="
grep -n "hideClockBox\|hideClockBoxInfo" scripts/languages.js

echo -e "\n=== Check if there's a localization utility/helper ==="
ls -la scripts/ | grep -i "local\|lang\|trans"

echo -e "\n=== Search for where element IDs get their text from ==="
rg -n "\[key\]\|languages\[" scripts/ -t js | head -20

Repository: prem-k-r/MaterialYouNewTab

Length of output: 15064


🏁 Script executed:

#!/bin/bash
# Look at the entire languages.js file to understand how it processes the keys array
echo "=== Viewing lines around the keys array in languages.js ==="
sed -n '140,200p' scripts/languages.js

echo -e "\n=== Look for the function that applies these translations ==="
sed -n '270,320p' scripts/languages.js

Repository: prem-k-r/MaterialYouNewTab

Length of output: 3925


🏁 Script executed:

#!/bin/bash
# Verify the complete picture: check one locale file and confirm the English locale
echo "=== English locale file content for clock items ==="
sed -n '39,45p' locales/en.js

echo -e "\n=== Check how applyTranslations actually runs ==="
sed -n '305,310p' scripts/languages.js

echo -e "\n=== Verify when the language function is called ==="
rg -n "function applyLanguage\|applyLanguage(" scripts/ -t js -B2 -A2 | head -30

Repository: prem-k-r/MaterialYouNewTab

Length of output: 793


🏁 Script executed:

#!/bin/bash
# Final verification: confirm the localization is being applied dynamically
echo "=== Look for where applyLanguage is called ==="
rg -n "applyLanguage" scripts/ -t js

echo -e "\n=== Check if translations are applied on page load ==="
rg -n "window.addEventListener\|document.addEventListener\|DOMContentLoaded" scripts/languages.js -A5

echo -e "\n=== Verify the current language setting mechanism ==="
sed -n '220,250p' scripts/languages.js

Repository: prem-k-r/MaterialYouNewTab

Length of output: 1477


Update locale translations for clock visibility toggle across all 25+ language files.

The localization system will overwrite the hardcoded HTML text "Show Clock" with "Hide Clock" from all locale files on page load. Since applyLanguage() is called at startup (scripts/languages.js:401) and applies translations from locale files to elements with IDs in the translationMap array, users will see conflicting semantics. Update the translation values in all locale files:

  • "hideClockBox": change from "Hide Clock" to "Show Clock"
  • "hideClockBoxInfo": change from "Hide the clock and date" to "Show or hide the clock and date"

This affects all 25+ locale files (en.js, fr.js, es.js, de.js, etc.).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@index.html` around lines 1385 - 1392, The HTML hardcoded texts for the clock
toggle (elements with IDs hideClockBox and hideClockBoxInfo) are being
overwritten by locale files when applyLanguage() runs using the translationMap;
update all locale translation entries so their keys match the intended default
phrasing: in every locale file (e.g., en.js, fr.js, es.js, de.js, etc.) change
the "hideClockBox" value from "Hide Clock" to "Show Clock" and change
"hideClockBoxInfo" from "Hide the clock and date" to "Show or hide the clock and
date" so translations align with the HTML defaults and avoid semantic inversion
when applyLanguage() is applied at startup.

Comment on lines +72 to +86
showClockCheckbox.addEventListener("change", function () {
const isChecked = showClockCheckbox.checked;
localStorage.setItem("showClock", isChecked);
applyClockState(!isChecked);
toggleHideState(!isChecked);

if (window.matchMedia("(max-width: 500px)").matches) {
clockOptions.classList.remove("not-applicable");
rightDiv.classList.remove("clock-padding-adjusted");
}

if (isChecked) {
initializeClock();
}
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Running clock intervals are not stopped when the clock is hidden.

When the user unchecks the toggle, initializeClock() is skipped (line 83), but any previously started analogIntervalId / digitalIntervalId continue to fire, updating DOM elements that are now hidden. Consider clearing the intervals when hiding:

🔧 Proposed fix
 showClockCheckbox.addEventListener("change", function () {
     const isChecked = showClockCheckbox.checked;
     localStorage.setItem("showClock", isChecked);
     applyClockState(!isChecked);
     toggleHideState(!isChecked);
 
     if (window.matchMedia("(max-width: 500px)").matches) {
         clockOptions.classList.remove("not-applicable");
         rightDiv.classList.remove("clock-padding-adjusted");
     }
 
     if (isChecked) {
         initializeClock();
+    } else {
+        if (analogIntervalId) { clearInterval(analogIntervalId); analogIntervalId = null; }
+        if (digitalIntervalId) { clearInterval(digitalIntervalId); digitalIntervalId = null; }
     }
 });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/clock.js` around lines 72 - 86, The change listener on
showClockCheckbox currently skips calling initializeClock() when unchecked but
does not stop any existing timers; modify the handler (the function attached to
showClockCheckbox.addEventListener) to clear running intervals when hiding by
calling clearInterval on analogIntervalId and digitalIntervalId (and nulling
them) before calling applyClockState/toggleHideState, so any previously started
timers from initializeClock() are stopped when the clock is hidden; ensure you
reference the existing variables analogIntervalId and digitalIntervalId and
perform the clearInterval calls only when isChecked is false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant