Back
Todo
#code make a script that will collect emails from fastmail and scroll down automatically: const emailData = []; (async () => { const scrollContainer = document.querySelector('ul.u-list-body.v-Mailbox'); if (!scrollContainer) { console.error('Unable to find the scroll container.'); return; } const processedItems = new Set(); let previousItemCount = 0; // Utility function to delay execution function wait(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } while (true) { let liElements = document.querySelectorAll('li.v-MailboxItem'); // Process any new li elements for (const li of liElements) { // Use a unique key. If 'id' is stable and unique, keep it. // Otherwise, consider using something like li.querySelector('.v-MailboxItem-link').href or subject text. const uniqueKey = li.id || li.querySelector('a.v-MailboxItem-link')?.href; if (!uniqueKey) continue; // If we can't find a stable key, skip. if (!processedItems.has(uniqueKey)) { processedItems.add(uniqueKey); // Simulate the action of viewing the email to get the "v-Message-toName" li.click(); await wait(1000); // Wait longer to ensure the email content is loaded const span = document.querySelector('span.v-Message-toName'); if (span) { emailData.push(span.textContent.trim()); } else { console.warn(`No "v-Message-toName" found for item with unique key: ${uniqueKey}`); } // (Optional) Close the opened message or go back if needed. // document.querySelector('button.back-button')?.click(); // await wait(500); } } // Check if we got more items after processing liElements = document.querySelectorAll('li.v-MailboxItem'); const currentItemCount = liElements.length; // If no new items have appeared after processing the currently visible ones, we try scrolling if (currentItemCount > previousItemCount) { previousItemCount = currentItemCount; } else { // Try to scroll further to load more items // Scroll to the bottom of the container scrollContainer.scrollTop = scrollContainer.scrollHeight; await wait(2000); // Check again if new items appeared liElements = document.querySelectorAll('li.v-MailboxItem'); if (liElements.length <= previousItemCount) { // No new items after scrolling break; } else { previousItemCount = liElements.length; } } } console.log('Collected Emails:', emailData); })();
Home
Search
Messages
Notifications
More