Load disclaimer modal dynamically

This commit is contained in:
thePR0M3TH3AN
2025-09-22 09:41:07 -04:00
parent 0373859ad3
commit c4289161e1
3 changed files with 25 additions and 9 deletions

View File

@@ -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=")) {

View File

@@ -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);
}
}

View File

@@ -171,6 +171,12 @@ Promise.all([
// Also run once on initial load
handleHashChange();
return import("./disclaimer.js");
})
.then(({ default: disclaimerModal }) => {
disclaimerModal.init();
disclaimerModal.show();
});
/* -------------------------------------------