Advertisement
Guest User

Bulk Delete All Messages in Google Fi Web App with Custom JavaScript

a guest
Nov 10th, 2024
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 3.24 KB | Source Code | 0 0
  1. /**
  2.  * Custom JavaScript to bulk delete all messages in the Google Fi Web App.
  3.  * Paste this script into the JavaScript console of your browser while on the
  4.  * Google Fi messages page, and it will automatically delete all conversations.
  5.  *
  6.  * NOTE: This script is for personal use only. Use it responsibly.
  7.  */
  8.  
  9. // Function to simulate clicking the menu button and delete option for a single conversation
  10. async function deleteConversation(conversationItem) {
  11.   try {
  12.     // Step 1: Locate and click the menu button for the conversation
  13.     const menuButton = conversationItem.querySelector('button[data-e2e-conversation-list-item-menu]');
  14.     if (!menuButton) {
  15.       console.warn('Menu button not found for a conversation. Skipping.');
  16.       return;
  17.     }
  18.     menuButton.click();
  19.  
  20.     // Step 2: Wait for the menu to appear
  21.     await new Promise(resolve => setTimeout(resolve, 1000));
  22.  
  23.     // Step 3: Locate and click the "Delete" option in the menu
  24.     const deleteButton = Array.from(document.querySelectorAll('button'))
  25.       .find(button => button.innerHTML.includes('<span class="mat-mdc-menu-item-text">Delete</span>'));
  26.     if (!deleteButton) {
  27.       console.warn('Delete button not found in menu. Skipping.');
  28.       return;
  29.     }
  30.     deleteButton.click();
  31.  
  32.     // Step 4: Wait for the "Confirm Delete" dialog to appear
  33.     await new Promise(resolve => setTimeout(resolve, 1000));
  34.  
  35.     // Step 5: Locate and click the "Confirm Delete" button in the dialog
  36.     const confirmButton = Array.from(document.querySelectorAll('button'))
  37.       .find(button => button.innerHTML.includes('<span class="mdc-button__label"> Delete </span>'));
  38.     if (!confirmButton) {
  39.       console.warn('Confirm button not found in dialog. Skipping.');
  40.       return;
  41.     }
  42.     confirmButton.click();
  43.  
  44.     console.log('Conversation deleted successfully.');
  45.   } catch (error) {
  46.     console.error('Error deleting conversation:', error);
  47.   }
  48. }
  49.  
  50. // Function to iterate through all conversations and delete them one by one
  51. async function deleteAllConversations() {
  52.   while (true) {
  53.     // Step 1: Get a list of all visible conversations on the page
  54.     const conversations = document.querySelectorAll('mws-conversation-list-item');
  55.     if (conversations.length === 0) {
  56.       console.log('No more conversations to delete.');
  57.       break; // Exit the loop when no conversations are left
  58.     }
  59.  
  60.     console.log(`Found ${conversations.length} conversations. Starting deletion loop.`);
  61.    
  62.     // Step 2: Loop through each conversation and delete it
  63.     for (let i = 0; i < conversations.length; i++) {
  64.       console.log(`Deleting conversation ${i + 1} of ${conversations.length}`);
  65.       await deleteConversation(conversations[i]);
  66.  
  67.       // Step 3: Wait between deletions to avoid overwhelming the UI
  68.       await new Promise(resolve => setTimeout(resolve, 2000));
  69.     }
  70.  
  71.     // Step 4: Wait for more conversations to load dynamically, if applicable
  72.     await new Promise(resolve => setTimeout(resolve, 3000));
  73.   }
  74.  
  75.   console.log('Finished deleting all conversations.');
  76. }
  77.  
  78. // Start the deletion process
  79. deleteAllConversations().then(() => {
  80.   console.log('Script completed successfully.');
  81. }).catch(err => {
  82.   console.error('Error during execution:', err);
  83. });
Tags: google fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement