Skip to content

Instantly share code, notes, and snippets.

@JKamsker
Created September 8, 2025 10:10
Show Gist options
  • Select an option

  • Save JKamsker/ab9e67dc865d8a3da1d3d46e48514e5f to your computer and use it in GitHub Desktop.

Select an option

Save JKamsker/ab9e67dc865d8a3da1d3d46e48514e5f to your computer and use it in GitHub Desktop.
Delete all Google Jules Tasks
/**
* This script automates the process of deleting ALL tasks, starting from the last one.
* It is designed to be run in the browser's developer console.
*/
async function deleteAllTasksReverse() {
// 1. Find all task options buttons.
const allOptionsButtons = document.querySelectorAll("swebot-task-tile > swebot-task-options > button");
if (allOptionsButtons.length === 0) {
console.log("No tasks found to delete.");
return;
}
console.log(`Found ${allOptionsButtons.length} tasks. Starting deletion from last to first.`);
// 2. Loop through the buttons in reverse order (from last to first).
for (let i = allOptionsButtons.length - 1; i >= 0; i--) {
const optionsButton = allOptionsButtons[i];
const taskNumber = i + 1;
console.log(`--- Processing Task #${taskNumber} ---`);
if (!optionsButton) {
console.error(`Error: Could not find the options button for task #${taskNumber}. Skipping.`);
continue;
}
// Step A: Click the options button to open the menu
console.log(`Step 1: Clicking options for task #${taskNumber}...`);
optionsButton.click();
await new Promise(resolve => setTimeout(resolve, 500)); // Wait for context menu
// Step B: Find and click the "Delete" button in the context menu
const allMenuButtons = document.querySelectorAll('.cdk-overlay-pane button.cdk-menu-item');
const deleteButton = Array.from(allMenuButtons).find(btn => btn.textContent.trim() === 'Delete');
if (!deleteButton) {
console.error(`Error: Could not find 'Delete' button for task #${taskNumber}. Skipping.`);
// Attempt to close the menu by simulating an escape key press or clicking elsewhere might be needed if script hangs
continue;
}
console.log(`Step 2: Clicking 'Delete' for task #${taskNumber}...`);
deleteButton.click();
await new Promise(resolve => setTimeout(resolve, 500)); // Wait for confirmation modal
// Step C: Find and click the final "Delete" button in the confirmation dialog
const confirmDeleteButton = document.querySelector("swebot-delete-dialog .delete-button");
if (!confirmDeleteButton) {
console.error(`Error: Could not find final 'Delete' confirmation for task #${taskNumber}. Skipping.`);
continue;
}
console.log(`Step 3: Confirming deletion for task #${taskNumber}...`);
confirmDeleteButton.click();
console.log(`--- Task #${taskNumber} deletion confirmed. ---`);
// Step D: Wait a moment for the UI to update before processing the next task.
await new Promise(resolve => setTimeout(resolve, 1000));
}
console.log("Process complete: All tasks have been processed.");
}
// Execute the function.
deleteAllTasksReverse();
@programming-with-ia
Copy link

bro, for need Memories

@programming-with-ia
Copy link

bro, for need Memories

/**
 * Helper function to wait for an element to appear or disappear.
 * @param {string} selector - The CSS selector to query.
 * @param {boolean} [shouldExist=true] - If true, waits for the element to exist. If false, waits for it to not exist.
 * @param {number} [timeout=3000] - Max time to wait in milliseconds.
 * @returns {Promise<Element|null>} A promise that resolves with the element (if found) or null (if timed out or disappearing).
 */
async function waitForElement(selector, shouldExist = true, timeout = 3000) {
  const startTime = Date.now();
  while (Date.now() - startTime < timeout) {
    const element = document.querySelector(selector);
    
    // Case 1: We want the element, and we found it.
    if (shouldExist && element) {
      return element;
    }
    
    // Case 2: We want the element to disappear, and it's gone.
    if (!shouldExist && !element) {
      return null; // Success, it's gone.
    }

    // Wait 100ms before polling again
    await new Promise(r => setTimeout(r, 100));
  }
  
  // If we're here, it timed out.
  console.error(`Timeout: Waited ${timeout / 1000}s for element '${selector}' to ${shouldExist ? 'appear' : 'disappear'}.`);
  return null;
}

/**
 * Main function to find and delete all memory items.
 */
async function deleteAllMemories() {
  const optionsButtons = document.querySelectorAll('tr.memory-row button.cdk-menu-trigger');

  console.log(`Found ${optionsButtons.length} rows to delete.`);
  if (optionsButtons.length === 0) {
    console.log("No rows found. Make sure you are on the correct page.");
    return;
  }

  for (const [index, button] of optionsButtons.entries()) {
    console.log(`Processing item ${index + 1} of ${optionsButtons.length}...`);
    
    // 1. Click the '...' button (opens the menu)
    button.click();

    // 2. Wait for the menu 'Delete' button to appear, then click it
    const menuDeleteIcon = await waitForElement('mat-icon[svgicon="delete"]');
    if (!menuDeleteIcon) {
      console.error("Stopping script: Could not find menu 'Delete' icon.");
      break;
    }
    
    const menuDeleteButton = menuDeleteIcon.closest('button');
    if (!menuDeleteButton) {
      console.error("Stopping script: Found menu 'Delete' icon but not its button.");
      break;
    }
    
    menuDeleteButton.click();

    // 3. Wait for the dialog's 'Delete' button to appear, then click it
    const dialogDeleteButton = await waitForElement('div.dialog button.delete-button');
    if (!dialogDeleteButton) {
      console.error("Stopping script: Could not find dialog 'Delete' button.");
      break;
    }
    
    dialogDeleteButton.click();
    
    // 4. Wait for the confirmation dialog to CLOSE
    console.log("Waiting for dialog to close...");
    await waitForElement('div.dialog', false); // Wait for it to disappear
    
    // Add a tiny buffer for the UI to settle before the next loop
    await new Promise(r => setTimeout(r, 250));
  }

  console.log('Finished deleting all items.');
}

// Run the function
deleteAllMemories();

@JKamsker
Copy link
Author

JKamsker commented Nov 2, 2025

@programming-with-ia
Copy link

nothing bro, i need to bulk delete memories i am searching and i found your gist,
now i have solution

@JKamsker
Copy link
Author

JKamsker commented Nov 2, 2025

lol - hope it helped @programming-with-ia

@programming-with-ia
Copy link

lol - hope it helped @programming-with-ia

of course, super helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment