From c4289161e11c3524fdba2200ac23902ac82d6a75 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Mon, 22 Sep 2025 09:41:07 -0400 Subject: [PATCH] Load disclaimer modal dynamically --- js/app.js | 4 +--- js/disclaimer.js | 24 ++++++++++++++++++------ js/index.js | 6 ++++++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/js/app.js b/js/app.js index 5d45bc03..51997718 100644 --- a/js/app.js +++ b/js/app.js @@ -4,7 +4,6 @@ import { loadView } from "./viewManager.js"; import { nostrClient } from "./nostr.js"; import { torrentClient } from "./webtorrent.js"; import { isDevMode } from "./config.js"; -import disclaimerModal from "./disclaimer.js"; import { isWhitelistEnabled } from "./config.js"; import { initialWhitelist, @@ -208,9 +207,8 @@ class bitvidApp { } } - // 5. Setup general event listeners, show disclaimers + // 5. Setup general event listeners this.setupEventListeners(); - disclaimerModal.show(); // 6) Load the default view ONLY if there's no #view= already if (!window.location.hash || !window.location.hash.startsWith("#view=")) { diff --git a/js/disclaimer.js b/js/disclaimer.js index e1a13980..bdfa4454 100644 --- a/js/disclaimer.js +++ b/js/disclaimer.js @@ -2,17 +2,29 @@ class DisclaimerModal { constructor() { - // Initialize elements when the disclaimer HTML is in the DOM. - this.init(); + this.modal = null; + this.acceptButton = null; + this.acceptHandler = null; } init() { this.modal = document.getElementById("disclaimerModal"); - this.acceptButton = document.getElementById("acceptDisclaimer"); - if (this.acceptButton) { - this.acceptButton.addEventListener("click", () => { + const nextAcceptButton = document.getElementById("acceptDisclaimer"); + + if (!this.acceptHandler) { + this.acceptHandler = () => { this.hide(); - }); + }; + } + + if (this.acceptButton && this.acceptHandler) { + this.acceptButton.removeEventListener("click", this.acceptHandler); + } + + this.acceptButton = nextAcceptButton || null; + + if (this.acceptButton && this.acceptHandler) { + this.acceptButton.addEventListener("click", this.acceptHandler); } } diff --git a/js/index.js b/js/index.js index ce3b6db5..64d41275 100644 --- a/js/index.js +++ b/js/index.js @@ -171,6 +171,12 @@ Promise.all([ // Also run once on initial load handleHashChange(); + + return import("./disclaimer.js"); + }) + .then(({ default: disclaimerModal }) => { + disclaimerModal.init(); + disclaimerModal.show(); }); /* -------------------------------------------