diff --git a/Anson-Projects/badfriends/src/analyzer.js b/Anson-Projects/badfriends/src/analyzer.js index 24e63ab79..39ca3f93b 100644 --- a/Anson-Projects/badfriends/src/analyzer.js +++ b/Anson-Projects/badfriends/src/analyzer.js @@ -137,16 +137,21 @@ export async function analyzeFollows(callbacks = {}) { onResults(initialResults); // Step 6: Continue scanning in background (async, don't await) - continueScanningInBackground( - follows, - mutedWords, - accountResults, - initialPostsPerAccount, - maxPostsPerAccount, - onStatus, - onProgress, - onResults - ); + // Use setTimeout to ensure initial results are returned first + setTimeout(() => { + continueScanningInBackground( + follows, + mutedWords, + accountResults, + initialPostsPerAccount, + maxPostsPerAccount, + onStatus, + onProgress, + onResults + ).catch(err => { + console.error('Background scan error:', err); + }); + }, 1000); // Give 1 second for UI to settle return initialResults; } catch (error) { @@ -222,26 +227,37 @@ async function continueScanningInBackground( onProgress, onResults ) { + console.log('Starting background scan...', { startFrom, maxPosts, accountCount: follows.length }); + try { // Fetch additional posts in chunks const chunkSize = 100; let currentPostCount = startFrom; while (currentPostCount < maxPosts) { - const postsToFetch = Math.min(chunkSize, maxPosts - currentPostCount); + const nextPostCount = Math.min(currentPostCount + chunkSize, maxPosts); - onStatus(`Deep scan: Analyzing up to ${currentPostCount + postsToFetch} posts per account...`); + console.log(`Deep scan: fetching up to ${nextPostCount} posts per account...`); + onStatus(`Deep scan: Analyzing up to ${nextPostCount} posts per account...`); // Fetch next chunk for all accounts const additionalFeeds = await getMultipleAuthorFeeds( follows, - currentPostCount + postsToFetch, + nextPostCount, (completed, total) => { - const percentComplete = Math.floor((currentPostCount / maxPosts) * 100); + const percentComplete = Math.floor(((nextPostCount - startFrom) / (maxPosts - startFrom)) * 100); onStatus(`Deep scan: ${percentComplete}% complete (${completed}/${total} accounts)`); } ); + console.log(`Deep scan: received ${additionalFeeds.length} feed results`); + + // Validate we got results + if (!additionalFeeds || additionalFeeds.length === 0) { + console.error('No feeds returned from getMultipleAuthorFeeds'); + break; + } + // Update results with new data const updatedResults = additionalFeeds.map(({ actor, feed }) => { const stats = analyzeAccountPosts(feed, mutedWords); @@ -264,6 +280,8 @@ async function continueScanningInBackground( const problematicAccounts = filterProblematicAccounts(sortedResults); const summary = generateSummary(follows, mutedWords, problematicAccounts); + console.log(`Deep scan: found ${problematicAccounts.length} problematic accounts`); + // Send updated results onResults({ mutedWords, @@ -272,16 +290,14 @@ async function continueScanningInBackground( problematicAccounts, summary, isComplete: false, - scannedPosts: currentPostCount + postsToFetch, + scannedPosts: nextPostCount, maxPosts: maxPosts, }); - currentPostCount += postsToFetch; - - console.log(`Deep scan progress: ${currentPostCount}/${maxPosts} posts per account`); + currentPostCount = nextPostCount; } - // Final results + // Final results - mark as complete onStatus('Deep scan complete!'); onProgress(100, 'complete'); diff --git a/Anson-Projects/badfriends/src/main.js b/Anson-Projects/badfriends/src/main.js index c7a53a0ad..ef14f458a 100644 --- a/Anson-Projects/badfriends/src/main.js +++ b/Anson-Projects/badfriends/src/main.js @@ -224,6 +224,12 @@ function displayResults(results, isUpdate = false) { * Display the list of problematic accounts */ function displayAccountsList(accounts) { + // Don't clear if accounts is undefined or null (defensive) + if (!accounts) { + console.warn('displayAccountsList called with no accounts'); + return; + } + elements.accountsList.innerHTML = ''; if (accounts.length === 0) {