// js/app.js 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 { initialBlacklist, initialEventBlacklist } from "./lists.js"; /** * Simple "decryption" placeholder for private videos. */ function fakeDecrypt(str) { return str.split("").reverse().join(""); } /** * Simple IntersectionObserver-based lazy loader for images (or videos). * * Usage: * const mediaLoader = new MediaLoader(); * mediaLoader.observe(imgElement); * * This will load the real image source from `imgElement.dataset.lazy` * once the image enters the viewport. */ class MediaLoader { constructor(rootMargin = "50px") { this.observer = new IntersectionObserver( (entries) => { for (const entry of entries) { if (entry.isIntersecting) { const el = entry.target; const lazySrc = el.dataset.lazy; if (lazySrc) { el.src = lazySrc; delete el.dataset.lazy; } // Stop observing once loaded this.observer.unobserve(el); } } }, { rootMargin } ); } observe(el) { if (el.dataset.lazy) { this.observer.observe(el); } } disconnect() { this.observer.disconnect(); } } class bitvidApp { constructor() { // Basic auth/display elements this.loginButton = document.getElementById("loginButton") || null; this.logoutButton = document.getElementById("logoutButton") || null; this.userStatus = document.getElementById("userStatus") || null; this.userPubKey = document.getElementById("userPubKey") || null; // Lazy-loading helper for images this.mediaLoader = new MediaLoader(); // Optional: a "profile" button or avatar (if used) this.profileButton = document.getElementById("profileButton") || null; this.profileAvatar = document.getElementById("profileAvatar") || null; // Profile modal references (if used in profile-modal.html) this.profileModal = null; this.closeProfileModal = null; this.profileLogoutBtn = null; this.profileModalAvatar = null; this.profileModalName = null; // Upload modal elements this.uploadButton = document.getElementById("uploadButton") || null; this.uploadModal = document.getElementById("uploadModal") || null; this.closeUploadModalBtn = document.getElementById("closeUploadModal") || null; this.uploadForm = document.getElementById("uploadForm") || null; // Optional small inline player stats this.status = document.getElementById("status") || null; this.progressBar = document.getElementById("progress") || null; this.peers = document.getElementById("peers") || null; this.speed = document.getElementById("speed") || null; this.downloaded = document.getElementById("downloaded") || null; // Video player modal references (loaded via video-modal.html) this.playerModal = null; this.modalVideo = null; this.modalStatus = null; this.modalProgress = null; this.modalPeers = null; this.modalSpeed = null; this.modalDownloaded = null; this.closePlayerBtn = null; this.videoTitle = null; this.videoDescription = null; this.videoTimestamp = null; this.creatorAvatar = null; this.creatorName = null; this.creatorNpub = null; this.copyMagnetBtn = null; this.shareBtn = null; // Hide/Show Subscriptions Link this.subscriptionsLink = null; // Notification containers this.errorContainer = document.getElementById("errorContainer") || null; this.successContainer = document.getElementById("successContainer") || null; // Auth state this.pubkey = null; this.currentMagnetUri = null; this.currentVideo = null; this.videoSubscription = null; // Videos stored as a Map (key=event.id) this.videosMap = new Map(); // Simple cache for user profiles this.profileCache = new Map(); // NEW: reference to the login modal's close button this.closeLoginModalBtn = document.getElementById("closeLoginModal") || null; // Build a set of blacklisted event IDs (hex) from nevent strings, skipping empties this.blacklistedEventIds = new Set(); for (const neventStr of initialEventBlacklist) { // Skip any empty or obviously invalid strings if (!neventStr || neventStr.trim().length < 8) { continue; } try { const decoded = window.NostrTools.nip19.decode(neventStr); if (decoded.type === "nevent" && decoded.data.id) { this.blacklistedEventIds.add(decoded.data.id); } } catch (err) { console.error( "[bitvidApp] Invalid nevent in blacklist:", neventStr, err ); } } } forceRefreshAllProfiles() { // 1) Grab the newest set of videos from nostrClient const activeVideos = nostrClient.getActiveVideos(); // 2) Build a unique set of pubkeys const uniqueAuthors = new Set(activeVideos.map((v) => v.pubkey)); // 3) For each author, fetchAndRenderProfile with forceRefresh = true for (const authorPubkey of uniqueAuthors) { this.fetchAndRenderProfile(authorPubkey, true); } } async init() { try { // Force update of any registered service workers to ensure latest code is used. if ("serviceWorker" in navigator) { navigator.serviceWorker.getRegistrations().then((registrations) => { registrations.forEach((registration) => registration.update()); }); } // 1. Initialize the video modal (components/video-modal.html) await this.initModal(); this.updateModalElements(); // 2. Initialize the upload modal (components/upload-modal.html) await this.initUploadModal(); // 3. (Optional) Initialize the profile modal (components/profile-modal.html) await this.initProfileModal(); // 4. Connect to Nostr await nostrClient.init(); // Grab the "Subscriptions" link by its id in the sidebar this.subscriptionsLink = document.getElementById("subscriptionsLink"); const savedPubKey = localStorage.getItem("userPubKey"); if (savedPubKey) { // Auto-login if a pubkey was saved this.login(savedPubKey, false); // If the user was already logged in, show the Subscriptions link if (this.subscriptionsLink) { this.subscriptionsLink.classList.remove("hidden"); } } // 5. Setup general event listeners, show disclaimers 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=")) { console.log( "[app.init()] No #view= in the URL, loading default home view" ); await loadView("views/most-recent-videos.html"); } else { console.log( "[app.init()] Found hash:", window.location.hash, "so skipping default load" ); } // 7. Once loaded, get a reference to #videoList this.videoList = document.getElementById("videoList"); // 8. Subscribe or fetch videos await this.loadVideos(); // 9. Check URL ?v= param this.checkUrlParams(); // Keep an array of active interval IDs so we can clear them on modal close this.activeIntervals = []; } catch (error) { console.error("Init failed:", error); this.showError("Failed to connect to Nostr relay"); } } /** * Initialize the main video modal (video-modal.html). */ async initModal() { try { const resp = await fetch("components/video-modal.html"); if (!resp.ok) { throw new Error(`HTTP error! status: ${resp.status}`); } const html = await resp.text(); const modalContainer = document.getElementById("modalContainer"); if (!modalContainer) { throw new Error("Modal container element not found!"); } // Instead of overwriting, we append a new DIV with the fetched HTML const wrapper = document.createElement("div"); wrapper.innerHTML = html; // set the markup modalContainer.appendChild(wrapper); // append the markup // Now we can safely find elements inside: const closeButton = document.getElementById("closeModal"); if (!closeButton) { throw new Error("Close button not found in video-modal!"); } closeButton.addEventListener("click", () => { this.hideModal(); }); // Setup scroll-based nav hide const modalNav = document.getElementById("modalNav"); const playerModal = document.getElementById("playerModal"); if (!modalNav || !playerModal) { throw new Error("Modal nav (#modalNav) or #playerModal not found!"); } let lastScrollY = 0; playerModal.addEventListener("scroll", (e) => { const currentScrollY = e.target.scrollTop; const shouldShowNav = currentScrollY <= lastScrollY || currentScrollY < 50; modalNav.style.transform = shouldShowNav ? "translateY(0)" : "translateY(-100%)"; lastScrollY = currentScrollY; }); console.log("Video modal initialization successful"); return true; } catch (error) { console.error("initModal failed:", error); this.showError(`Failed to initialize video modal: ${error.message}`); return false; } } /** * After we load the video modal, store references in `this.*`. */ updateModalElements() { this.playerModal = document.getElementById("playerModal") || null; this.modalVideo = document.getElementById("modalVideo") || null; this.modalStatus = document.getElementById("modalStatus") || null; this.modalProgress = document.getElementById("modalProgress") || null; this.modalPeers = document.getElementById("modalPeers") || null; this.modalSpeed = document.getElementById("modalSpeed") || null; this.modalDownloaded = document.getElementById("modalDownloaded") || null; this.closePlayerBtn = document.getElementById("closeModal") || null; this.videoTitle = document.getElementById("videoTitle") || null; this.videoDescription = document.getElementById("videoDescription") || null; this.videoTimestamp = document.getElementById("videoTimestamp") || null; this.creatorAvatar = document.getElementById("creatorAvatar") || null; this.creatorName = document.getElementById("creatorName") || null; this.creatorNpub = document.getElementById("creatorNpub") || null; this.copyMagnetBtn = document.getElementById("copyMagnetBtn") || null; this.shareBtn = document.getElementById("shareBtn") || null; // Attach the event listeners for the copy/share buttons if (this.copyMagnetBtn) { this.copyMagnetBtn.addEventListener("click", () => { this.handleCopyMagnet(); }); } // UPDATED: This share button just copies the ?v= URL to the clipboard: if (this.shareBtn) { this.shareBtn.addEventListener("click", () => { if (!this.currentVideo) { this.showError("No video is loaded to share."); return; } try { const nevent = window.NostrTools.nip19.neventEncode({ id: this.currentVideo.id, }); const shareUrl = `${window.location.origin}${window.location.pathname}?v=${nevent}`; navigator.clipboard .writeText(shareUrl) .then(() => this.showSuccess("Video link copied to clipboard!")) .catch(() => this.showError("Failed to copy the link.")); } catch (err) { console.error("Error generating share link:", err); this.showError("Could not generate link."); } }); } } /** * Show the modal and set the "Please stand by" poster on the video. */ showModalWithPoster() { if (this.playerModal) { this.playerModal.style.display = "flex"; this.playerModal.classList.remove("hidden"); } if (this.modalVideo) { this.modalVideo.poster = "assets/gif/please-stand-by.gif"; } } /** * Initialize the upload modal (upload-modal.html). */ async initUploadModal() { try { const resp = await fetch("components/upload-modal.html"); if (!resp.ok) { throw new Error(`HTTP error! status: ${resp.status}`); } const html = await resp.text(); const modalContainer = document.getElementById("modalContainer"); if (!modalContainer) { throw new Error("Modal container element not found!"); } // Append the upload modal markup const wrapper = document.createElement("div"); wrapper.innerHTML = html; modalContainer.appendChild(wrapper); // Grab references this.uploadModal = document.getElementById("uploadModal") || null; this.closeUploadModalBtn = document.getElementById("closeUploadModal") || null; this.uploadForm = document.getElementById("uploadForm") || null; // Optional: if close button found, wire up if (this.closeUploadModalBtn) { this.closeUploadModalBtn.addEventListener("click", () => { if (this.uploadModal) { this.uploadModal.classList.add("hidden"); } }); } // If the form is found, wire up if (this.uploadForm) { this.uploadForm.addEventListener("submit", (e) => { e.preventDefault(); this.handleUploadSubmit(); }); } console.log("Upload modal initialization successful"); return true; } catch (error) { console.error("initUploadModal failed:", error); this.showError(`Failed to initialize upload modal: ${error.message}`); return false; } } /** * (Optional) Initialize a separate profile modal (profile-modal.html). */ async initProfileModal() { try { console.log("Starting profile modal initialization..."); const resp = await fetch("components/profile-modal.html"); if (!resp.ok) { // If you don't have a profile modal, comment this entire method out. throw new Error(`HTTP error! status: ${resp.status}`); } const html = await resp.text(); const modalContainer = document.getElementById("modalContainer"); if (!modalContainer) { throw new Error("Modal container element not found!"); } const wrapper = document.createElement("div"); wrapper.innerHTML = html; modalContainer.appendChild(wrapper); // Now references this.profileModal = document.getElementById("profileModal") || null; this.closeProfileModal = document.getElementById("closeProfileModal") || null; this.profileLogoutBtn = document.getElementById("profileLogoutBtn") || null; this.profileModalAvatar = document.getElementById("profileModalAvatar") || null; this.profileModalName = document.getElementById("profileModalName") || null; // Wire up if (this.closeProfileModal) { this.closeProfileModal.addEventListener("click", () => { this.profileModal.classList.add("hidden"); }); } if (this.profileLogoutBtn) { this.profileLogoutBtn.addEventListener("click", () => { // On "Logout" inside the profile modal this.logout(); this.profileModal.classList.add("hidden"); }); } console.log("Profile modal initialization successful"); return true; } catch (error) { console.error("initProfileModal failed:", error); // Not critical if missing return false; } } /** * Setup general event listeners for logout, modals, etc. */ setupEventListeners() { // 1) Logout button if (this.logoutButton) { this.logoutButton.addEventListener("click", () => { this.logout(); }); } // 2) Profile button if (this.profileButton) { this.profileButton.addEventListener("click", () => { if (this.profileModal) { this.profileModal.classList.remove("hidden"); } }); } // 3) Upload button => show upload modal if (this.uploadButton) { this.uploadButton.addEventListener("click", () => { if (this.uploadModal) { this.uploadModal.classList.remove("hidden"); } }); } // 4) Login button => show the login modal if (this.loginButton) { this.loginButton.addEventListener("click", () => { console.log("Login button clicked!"); const loginModal = document.getElementById("loginModal"); if (loginModal) { loginModal.classList.remove("hidden"); } }); } // 5) Close login modal button => hide modal if (this.closeLoginModalBtn) { this.closeLoginModalBtn.addEventListener("click", () => { console.log("[app.js] closeLoginModal button clicked!"); const loginModal = document.getElementById("loginModal"); if (loginModal) { loginModal.classList.add("hidden"); } }); } // 6) NIP-07 button inside the login modal => call the extension & login const nip07Button = document.getElementById("loginNIP07"); if (nip07Button) { nip07Button.addEventListener("click", async () => { console.log( "[app.js] loginNIP07 clicked! Attempting extension login..." ); try { const pubkey = await nostrClient.login(); // call the extension console.log("[NIP-07] login returned pubkey:", pubkey); this.login(pubkey, true); // Hide the login modal const loginModal = document.getElementById("loginModal"); if (loginModal) { loginModal.classList.add("hidden"); } } catch (err) { console.error("[NIP-07 login error]", err); this.showError("Failed to login with NIP-07. Please try again."); } }); } // 7) Cleanup on page unload window.addEventListener("beforeunload", async () => { await this.cleanup(); }); // 8) Handle back/forward navigation => hide video modal window.addEventListener("popstate", async () => { console.log("[popstate] user navigated back/forward; cleaning modal..."); await this.hideModal(); }); // 9) Event delegation on the video list container for playing videos if (this.videoList) { this.videoList.addEventListener("click", (event) => { const magnetTrigger = event.target.closest("[data-play-magnet]"); if (magnetTrigger) { // For a normal left-click (button 0, no Ctrl/Cmd), prevent navigation: if (event.button === 0 && !event.ctrlKey && !event.metaKey) { event.preventDefault(); // Stop browser from following the href const magnet = magnetTrigger.dataset.playMagnet; this.playVideo(magnet); } } }); } // 10) Event delegation for the “Application Form” button inside the login modal document.addEventListener("click", (event) => { if (event.target && event.target.id === "openApplicationModal") { // Hide the login modal const loginModal = document.getElementById("loginModal"); if (loginModal) { loginModal.classList.add("hidden"); } // Show the application modal const appModal = document.getElementById("nostrFormModal"); if (appModal) { appModal.classList.remove("hidden"); } } }); } /** * Attempt to load the user's own profile from Nostr (kind:0). */ async loadOwnProfile(pubkey) { try { const events = await nostrClient.pool.list(nostrClient.relays, [ { kinds: [0], authors: [pubkey], limit: 1 }, ]); let displayName = "User"; let picture = "assets/svg/default-profile.svg"; if (events.length && events[0].content) { const data = JSON.parse(events[0].content); displayName = data.name || data.display_name || "User"; picture = data.picture || "assets/svg/default-profile.svg"; } // If you have a top-bar avatar (profileAvatar) if (this.profileAvatar) { this.profileAvatar.src = picture; } // If you want to show name somewhere if (this.profileModalName) { this.profileModalName.textContent = displayName; } if (this.profileModalAvatar) { this.profileModalAvatar.src = picture; } } catch (error) { console.error("loadOwnProfile error:", error); } } async fetchAndRenderProfile(pubkey, forceRefresh = false) { const now = Date.now(); // 1) Check if we have a cached entry const cacheEntry = this.profileCache.get(pubkey); if (!forceRefresh && cacheEntry && now - cacheEntry.timestamp < 60000) { // If it's less than 60 seconds old, just update DOM with it this.updateProfileInDOM(pubkey, cacheEntry.profile); return; } // 2) Otherwise, fetch from Nostr try { const userEvents = await nostrClient.pool.list(nostrClient.relays, [ { kinds: [0], authors: [pubkey], limit: 1 }, ]); if (userEvents.length > 0 && userEvents[0].content) { const data = JSON.parse(userEvents[0].content); const profile = { name: data.name || data.display_name || "Unknown", picture: data.picture || "assets/svg/default-profile.svg", }; // Cache it this.profileCache.set(pubkey, { profile, timestamp: now }); // Update DOM this.updateProfileInDOM(pubkey, profile); } } catch (err) { console.error("Profile fetch error:", err); } } updateProfileInDOM(pubkey, profile) { // For any .author-pic[data-pubkey=...] const picEls = document.querySelectorAll( `.author-pic[data-pubkey="${pubkey}"]` ); picEls.forEach((el) => { el.src = profile.picture; }); // For any .author-name[data-pubkey=...] const nameEls = document.querySelectorAll( `.author-name[data-pubkey="${pubkey}"]` ); nameEls.forEach((el) => { el.textContent = profile.name; }); } /** * Actually handle the upload form submission. */ async handleUploadSubmit() { if (!this.pubkey) { this.showError("Please login to post a video."); return; } const titleEl = document.getElementById("uploadTitle"); const magnetEl = document.getElementById("uploadMagnet"); const thumbEl = document.getElementById("uploadThumbnail"); const descEl = document.getElementById("uploadDescription"); const privEl = document.getElementById("uploadIsPrivate"); const formData = { version: 2, title: titleEl?.value.trim() || "", magnet: magnetEl?.value.trim() || "", thumbnail: thumbEl?.value.trim() || "", description: descEl?.value.trim() || "", mode: isDevMode ? "dev" : "live", isPrivate: privEl?.checked || false, }; if (!formData.title || !formData.magnet) { this.showError("Title and Magnet are required."); return; } try { await nostrClient.publishVideo(formData, this.pubkey); // Clear fields if (titleEl) titleEl.value = ""; if (magnetEl) magnetEl.value = ""; if (thumbEl) thumbEl.value = ""; if (descEl) descEl.value = ""; if (privEl) privEl.checked = false; // Hide the modal if (this.uploadModal) { this.uploadModal.classList.add("hidden"); } // *** Refresh to show the newly uploaded video in the grid *** await this.loadVideos(); this.showSuccess("Video shared successfully!"); } catch (err) { console.error("Failed to publish video:", err); this.showError("Failed to share video. Please try again later."); } } /** * Called upon successful login. */ async login(pubkey, saveToStorage = true) { console.log("[app.js] login() called with pubkey =", pubkey); this.pubkey = pubkey; // Hide login button if present if (this.loginButton) { this.loginButton.classList.add("hidden"); } // Optionally hide logout or userStatus if (this.logoutButton) { this.logoutButton.classList.add("hidden"); } if (this.userStatus) { this.userStatus.classList.add("hidden"); } // Show the upload button, profile button, etc. if (this.uploadButton) { this.uploadButton.classList.remove("hidden"); } if (this.profileButton) { this.profileButton.classList.remove("hidden"); } // Show the "Subscriptions" link if it exists if (this.subscriptionsLink) { this.subscriptionsLink.classList.remove("hidden"); } // (Optional) load the user's own Nostr profile this.loadOwnProfile(pubkey); // Save pubkey locally if requested if (saveToStorage) { localStorage.setItem("userPubKey", pubkey); } // Refresh the video list so the user sees any private videos, etc. await this.loadVideos(); // Force a fresh fetch of all profile pictures/names this.forceRefreshAllProfiles(); } /** * Logout logic */ async logout() { nostrClient.logout(); this.pubkey = null; // Show the login button again if (this.loginButton) { this.loginButton.classList.remove("hidden"); } // Hide logout or userStatus if (this.logoutButton) { this.logoutButton.classList.add("hidden"); } if (this.userStatus) { this.userStatus.classList.add("hidden"); } if (this.userPubKey) { this.userPubKey.textContent = ""; } // Hide upload & profile if (this.uploadButton) { this.uploadButton.classList.add("hidden"); } if (this.profileButton) { this.profileButton.classList.add("hidden"); } // Hide the Subscriptions link if (this.subscriptionsLink) { this.subscriptionsLink.classList.add("hidden"); } // Clear localStorage localStorage.removeItem("userPubKey"); // Refresh the video list so user sees only public videos again await this.loadVideos(); // Force a fresh fetch of all profile pictures/names (public ones in this case) this.forceRefreshAllProfiles(); } /** * Cleanup resources on unload or modal close. */ async cleanup() { try { // If there's a small inline player if (this.videoElement) { this.videoElement.pause(); this.videoElement.src = ""; this.videoElement.load(); } // If there's a modal video if (this.modalVideo) { this.modalVideo.pause(); this.modalVideo.src = ""; this.modalVideo.load(); } // Tell webtorrent to cleanup await torrentClient.cleanup(); } catch (err) { console.error("Cleanup error:", err); } } /** * Hide the video modal. */ async hideModal() { // 1) Clear intervals, cleanup, etc. (unchanged) if (this.activeIntervals && this.activeIntervals.length) { this.activeIntervals.forEach((id) => clearInterval(id)); this.activeIntervals = []; } try { await fetch("/webtorrent/cancel/", { mode: "no-cors" }); } catch (err) { // ignore } await this.cleanup(); // 2) Hide the modal if (this.playerModal) { this.playerModal.style.display = "none"; this.playerModal.classList.add("hidden"); } this.currentMagnetUri = null; // 3) Remove only `?v=` but **keep** the hash const url = new URL(window.location.href); url.searchParams.delete("v"); // remove ?v= param const newUrl = url.pathname + url.search + url.hash; window.history.replaceState({}, "", newUrl); } /** * Subscribe to videos (older + new) and render them as they come in. */ async loadVideos(forceFetch = false) { console.log("Starting loadVideos... (forceFetch =", forceFetch, ")"); // If forceFetch is true, unsubscribe from the old subscription to start fresh if (forceFetch && this.videoSubscription) { // Call unsubscribe on the subscription object directly. this.videoSubscription.unsub(); this.videoSubscription = null; } // The rest of your existing logic: if (!this.videoSubscription) { if (this.videoList) { this.videoList.innerHTML = `
Loading videos as they arrive...
`; } // Create a new subscription this.videoSubscription = nostrClient.subscribeVideos(() => { const updatedAll = nostrClient.getActiveVideos(); // Filter out blacklisted authors & blacklisted event IDs const filteredVideos = updatedAll.filter((video) => { // 1) If the event ID is in our blacklisted set, skip if (this.blacklistedEventIds.has(video.id)) { return false; } // 2) Check author if you’re blacklisting authors by npub const authorNpub = this.safeEncodeNpub(video.pubkey) || video.pubkey; if (initialBlacklist.includes(authorNpub)) { return false; } return true; }); this.renderVideoList(filteredVideos); }); // *** IMPORTANT ***: Unsubscribe once we get the historical EOSE // so that we do not hold an open subscription forever: if (this.videoSubscription) { this.videoSubscription.on("eose", () => { this.videoSubscription.unsub(); console.log("[loadVideos] unsubscribed after EOSE"); }); } } else { // Already subscribed: just show what's cached const allCached = nostrClient.getActiveVideos(); const filteredCached = allCached.filter((video) => { if (this.blacklistedEventIds.has(video.id)) { return false; } const authorNpub = this.safeEncodeNpub(video.pubkey) || video.pubkey; return !initialBlacklist.includes(authorNpub); }); this.renderVideoList(filteredCached); } } /** * Returns true if there's at least one strictly older version * (same videoRootId, created_at < current) which is NOT deleted. */ hasOlderVersion(video, allEvents) { if (!video || !video.videoRootId) return false; const rootId = video.videoRootId; const currentTs = video.created_at; // among ALL known events (including overshadowed), find older, not deleted const olderMatches = allEvents.filter( (v) => v.videoRootId === rootId && v.created_at < currentTs && !v.deleted ); return olderMatches.length > 0; } async renderVideoList(videos) { if (!this.videoList) return; // Check if there's anything to show if (!videos || videos.length === 0) { this.videoList.innerHTML = `No public videos available yet. Be the first to upload one!
`; return; } // Sort newest first videos.sort((a, b) => b.created_at - a.created_at); // Convert allEvents to an array for checking older overshadowed events const fullAllEventsArray = Array.from(nostrClient.allEvents.values()); const fragment = document.createDocumentFragment(); videos.forEach((video, index) => { if (!video.id || !video.title) { console.error("Video missing ID/title:", video); return; } const nevent = window.NostrTools.nip19.neventEncode({ id: video.id }); const shareUrl = `${window.location.pathname}?v=${encodeURIComponent( nevent )}`; const canEdit = video.pubkey === this.pubkey; const highlightClass = video.isPrivate && canEdit ? "border-2 border-yellow-500" : "border-none"; const timeAgo = this.formatTimeAgo(video.created_at); // Check if there's an older version (for revert button) let hasOlder = false; if (canEdit && video.videoRootId) { hasOlder = this.hasOlderVersion(video, fullAllEventsArray); } const revertButton = hasOlder ? ` ` : ""; // Gear menu (only shown if canEdit) const gearMenu = canEdit ? `