this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: Wait for DOMContentLoaded

+82 -80
+82 -80
app.js
··· 1 - // Main application code 2 - let currentCursor = null; 3 - const recordsContainer = document.getElementById("recordsContainer"); 4 - const loadMoreButton = document.getElementById("loadMoreButton"); 5 - const loadButton = document.getElementById("loadButton"); 6 - const repoInput = document.getElementById("repoInput"); 1 + document.addEventListener('DOMContentLoaded', () => { 2 + // Main application code 3 + let currentCursor = null; 4 + const recordsContainer = document.getElementById("recordsContainer"); 5 + const loadMoreButton = document.getElementById("loadMoreButton"); 6 + const loadButton = document.getElementById("loadButton"); 7 + const repoInput = document.getElementById("repoInput"); 7 8 8 - // Initialize the AT Protocol client - FIXED VERSION // lol claude wrote that 9 - const agent = new window.AtprotoApi.AtpAgent({ 10 - service: "https://bsky.social", 11 - }); 9 + // Initialize the AT Protocol client - FIXED VERSION // lol claude wrote that 10 + const agent = new window.AtprotoApi.AtpAgent({ 11 + service: "https://bsky.social", 12 + }); 12 13 13 - // Event listeners 14 - loadButton.addEventListener("click", () => { 15 - const repo = repoInput.value.trim(); 16 - if (!repo) { 17 - alert("Please enter a valid repository DID or handle"); 18 - return; 19 - } 14 + // Event listeners 15 + loadButton.addEventListener("click", () => { 16 + const repo = repoInput.value.trim(); 17 + if (!repo) { 18 + alert("Please enter a valid repository DID or handle"); 19 + return; 20 + } 20 21 21 - // Clear previous records and reset cursor 22 - recordsContainer.innerHTML = ""; 23 - currentCursor = null; 24 - loadMoreButton.style.display = "none"; 22 + // Clear previous records and reset cursor 23 + recordsContainer.innerHTML = ""; 24 + currentCursor = null; 25 + loadMoreButton.style.display = "none"; 25 26 26 - // Load the first batch of records 27 - loadRecords(repo); 28 - }); 27 + // Load the first batch of records 28 + loadRecords(repo); 29 + }); 29 30 30 - loadMoreButton.addEventListener("click", () => { 31 - loadRecords(repoInput.value.trim()); 32 - }); 31 + loadMoreButton.addEventListener("click", () => { 32 + loadRecords(repoInput.value.trim()); 33 + }); 33 34 34 - // Function to load records from the repository 35 - async function loadRecords(repo) { 36 - try { 37 - loadButton.disabled = true; 38 - loadMoreButton.disabled = true; 39 - loadMoreButton.textContent = "Loading..."; 35 + // Function to load records from the repository 36 + async function loadRecords(repo) { 37 + try { 38 + loadButton.disabled = true; 39 + loadMoreButton.disabled = true; 40 + loadMoreButton.textContent = "Loading..."; 40 41 41 - // Call the AT Protocol API to list records 42 - const response = await agent.com.atproto.repo.listRecords({ 43 - repo: repo, 44 - collection: "me.comind.blip.thought", 45 - limit: 10, 46 - cursor: currentCursor, 47 - }); 42 + // Call the AT Protocol API to list records 43 + const response = await agent.com.atproto.repo.listRecords({ 44 + repo: repo, 45 + collection: "me.comind.blip.thought", 46 + limit: 10, 47 + cursor: currentCursor, 48 + }); 48 49 49 - // Update the cursor for pagination 50 - currentCursor = response.data.cursor; 50 + // Update the cursor for pagination 51 + currentCursor = response.data.cursor; 51 52 52 - // Show or hide the "Load More" button based on cursor availability 53 - if (currentCursor) { 54 - loadMoreButton.style.display = "block"; 55 - } else { 56 - loadMoreButton.style.display = "none"; 57 - } 53 + // Show or hide the "Load More" button based on cursor availability 54 + if (currentCursor) { 55 + loadMoreButton.style.display = "block"; 56 + } else { 57 + loadMoreButton.style.display = "none"; 58 + } 58 59 59 - // Render the records 60 - renderRecords(response.data.records); 61 - } catch (error) { 62 - console.error("Error loading records:", error); 63 - alert(`Error: ${error.message || "Failed to load records"}`); 64 - } finally { 65 - loadButton.disabled = false; 66 - loadMoreButton.disabled = false; 67 - loadMoreButton.textContent = "Load More"; 68 - } 69 - } 60 + // Render the records 61 + renderRecords(response.data.records); 62 + } catch (error) { 63 + console.error("Error loading records:", error); 64 + alert(`Error: ${error.message || "Failed to load records"}`); 65 + } finally { 66 + loadButton.disabled = false; 67 + loadMoreButton.disabled = false; 68 + loadMoreButton.textContent = "Load More"; 69 + } 70 + } 70 71 71 - // Function to render the records 72 - function renderRecords(records) { 73 - if (records.length === 0) { 74 - recordsContainer.innerHTML += 75 - '<div class="alert alert-info">No records found</div>'; 76 - return; 77 - } 72 + // Function to render the records 73 + function renderRecords(records) { 74 + if (records.length === 0) { 75 + recordsContainer.innerHTML += 76 + '<div class="alert alert-info">No records found</div>'; 77 + return; 78 + } 78 79 79 - records.forEach((record) => { 80 - const { value } = record; 81 - const thoughtEl = document.createElement("div"); 82 - thoughtEl.className = "card thought-card p-3"; 80 + records.forEach((record) => { 81 + const { value } = record; 82 + const thoughtEl = document.createElement("div"); 83 + thoughtEl.className = "card thought-card p-3"; 83 84 84 - // Format the date/time 85 - const createdAt = new Date(value.createdAt); 86 - const formattedDate = createdAt.toLocaleString(); 85 + // Format the date/time 86 + const createdAt = new Date(value.createdAt); 87 + const formattedDate = createdAt.toLocaleString(); 87 88 88 - // Get the thought data 89 - const thought = value.generated; 89 + // Get the thought data 90 + const thought = value.generated; 90 91 91 - // Build the HTML 92 - thoughtEl.innerHTML = ` 92 + // Build the HTML 93 + thoughtEl.innerHTML = ` 93 94 <div class="card-body"> 94 95 <div class="d-flex justify-content-between align-items-start"> 95 96 <span class="thought-type">${thought.thoughtType}</span> ··· 144 145 </div> 145 146 `; 146 147 147 - recordsContainer.appendChild(thoughtEl); 148 - }); 149 - } 148 + recordsContainer.appendChild(thoughtEl); 149 + }); 150 + } 151 + });