Skip to content

refactor(js): centralize page bootstrapping into single DOMContentLoaded handler - #646

Merged
jbampton merged 4 commits into
NextCommunity:mainfrom
titas-mahato:centralize-domcontentloaded-bootstrap
Oct 4, 2026
Merged

jbampton merged 4 commits into
NextCommunity:mainfrom
titas-mahato:centralize-domcontentloaded-bootstrap

Conversation

@titas-mahato

Copy link
Copy Markdown
Member

Closes #644

Summary

Consolidates multiple scattered DOMContentLoaded listeners in src/assets/js/script.js into a centralized bootstrap() function.

Changes

  • Extracted footer surge state check into initFooterSurgeState().
  • Extracted dev tools and console state setup into initConsoleState().
  • Unified all initialization routines under a single bootstrap() function on document.addEventListener("DOMContentLoaded", bootstrap).
  • Verified formatting and linting with Biome.

@deepsource-io

deepsource-io Bot commented Oct 3, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in e9a1615...fa7e110 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
JavaScript Oct 3, 2026 8:29a.m. Review ↗
Secrets Oct 3, 2026 8:29a.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

Comment thread src/assets/js/script.js Outdated
Comment on lines +1436 to +1444
function initFooterSurgeState() {
const unlockedEggs = JSON.parse(localStorage.getItem("unlockedEggs") || "[]");
if (unlockedEggs.includes("footer_surge")) {
finalizeFooterDot(
document.getElementById("footer-dot-core"),
document.getElementById("footer-dot-ping"),
);
}
});
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unexpected function declaration in the global scope, wrap in an IIFE for a local variable, assign as global property for a global variable


It is considered a best practice to avoid 'polluting' the global scope with variables that are intended to be local to the script. Global variables created from a script can produce name collisions with global variables created from another script, which will usually lead to runtime errors or unexpected behavior. It is mostly useful for browser scripts.

Comment thread src/assets/js/script.js Outdated
Comment on lines +1469 to +1480
function bootstrap() {
initSkillXP();
initFooterSurgeState();
initConsoleState();
initDotEasterEgg();
initSkillMining();
// Initialize the profile counter
initProfileTracker();

applyTheme(localStorage.getItem("theme") || "light");
updateGameUI();
});
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unexpected function declaration in the global scope, wrap in an IIFE for a local variable, assign as global property for a global variable


It is considered a best practice to avoid 'polluting' the global scope with variables that are intended to be local to the script. Global variables created from a script can produce name collisions with global variables created from another script, which will usually lead to runtime errors or unexpected behavior. It is mostly useful for browser scripts.

@deepsource-io

deepsource-io Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in e9a1615...03348fa on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

Important

Some issues found as part of this review are outside of the diff in this pull request and aren't shown in the inline review comments due to GitHub's API limitations. You can see those issues on the DeepSource dashboard.

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
JavaScript Oct 3, 2026 9:39a.m. Review ↗
Secrets Oct 3, 2026 9:39a.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

Comment thread src/assets/js/script.js Outdated
/**
* INITIALIZATION
*/
document.addEventListener("DOMContentLoaded", () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Function has a cyclomatic complexity of 8 with "medium" risk


A function with high cyclomatic complexity can be hard to understand and
maintain. Cyclomatic complexity is a software metric that measures the number of
independent paths through a function. A higher cyclomatic complexity indicates
that the function has more decision points and is more complex.

@titas-mahato

Copy link
Copy Markdown
Member Author

I saw the DeepSource check failed. The first commit was flagged for global scope declarations, and when I inlined it, it was flagged for complexity.

I'm now working on wrapping the helpers in a local scope so both the scope and complexity checks pass cleanly. Will push an update in a bit.

Comment thread src/assets/js/script.js Outdated
devPanel.classList.remove("hidden");
(() => {
function initFooterSurgeState() {
const unlockedEggs = JSON.parse(localStorage.getItem("unlockedEggs") || "[]");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

'unlockedEggs' is already declared in the upper scope on line 20 column 7


Two variables can have the same name if they're declared in different scopes. In the example below, the parameter x is said to "shadow" the variable x declared above it. The outer x can no longer be accessed inside the sum function.

@jbampton jbampton added this to the Hacktoberfest 2026 milestone Oct 4, 2026
@jbampton jbampton self-assigned this Oct 4, 2026
@jbampton
jbampton requested a balanced review from Copilot October 4, 2026 02:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The focused initialization refactor has no identified blocking regressions or unresolved findings.

Review effort: Balanced
Findings: None

What changed in this PR

Centralizes page initialization in script.js, addressing #644 by consolidating scattered DOMContentLoaded listeners.

Changes:

  • Extracts footer surge and console state setup into helper functions.
  • Groups initialization calls in one handler within an isolated scope.
File Description
src/​assets/​js/​script.js Consolidates initialization listeners and extracts state setup helpers.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@jbampton jbampton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you 🏂

@jbampton
jbampton merged commit b391a41 into NextCommunity:main Oct 4, 2026
16 checks passed
@github-project-automation github-project-automation Bot moved this from Reviewer approved to Done in Next Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Centralize page bootstrapping instead of scattering multiple DOMContentLoaded blocks

3 participants