Javi

Selfhosted: Delete google photos

Dec 30th, 2025
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. async function waitForDOMStability(timeout = 5000, checkInterval = 500) {
  2. return new Promise((resolve) => {
  3. let timeoutId;
  4. let lastMutationTime = Date.now();
  5.  
  6. const observer = new MutationObserver(() => {
  7. lastMutationTime = Date.now();
  8. clearTimeout(timeoutId);
  9.  
  10. timeoutId = setTimeout(() => {
  11. observer.disconnect();
  12. resolve();
  13. }, checkInterval);
  14. });
  15.  
  16. observer.observe(document.body, {
  17. childList: true,
  18. subtree: true,
  19. attributes: true
  20. });
  21.  
  22. // Initial timeout in case no mutations occur
  23. timeoutId = setTimeout(() => {
  24. observer.disconnect();
  25. resolve();
  26. }, checkInterval);
  27.  
  28. // Safety timeout to prevent infinite waiting
  29. setTimeout(() => {
  30. observer.disconnect();
  31. resolve();
  32. }, timeout);
  33. });
  34. }
  35.  
  36. async function bulkDeleteToTrash() {
  37. while (document.body.innerText.indexOf('Moviendo')!=-1) {
  38. await new Promise(resolve => setTimeout(resolve, 1000));
  39. }
  40. // Select all items
  41. [...document.querySelectorAll('[aria-label*="Seleccionar todas"]')].forEach(e => e.click());
  42. [...document.querySelectorAll('[role="checkbox"] svg:first-child')].forEach(e=>e.parentElement.click())
  43.  
  44. // Wait 1 second
  45. await new Promise(resolve => setTimeout(resolve, 1000));
  46.  
  47. // Click move to trash button
  48. document.querySelector('[aria-label="Mover a la papelera"]')?.click();
  49.  
  50. // Wait 1 second
  51. await new Promise(resolve => setTimeout(resolve, 1000));
  52.  
  53. // Confirm move to trash
  54. document.evaluate(
  55. "//button[contains(., 'Mover a la papelera')]",
  56. document,
  57. null,
  58. XPathResult.FIRST_ORDERED_NODE_TYPE,
  59. null
  60. ).singleNodeValue?.click();
  61.  
  62. // Wait for DOM to stabilize after deletion
  63. await waitForDOMStability();
  64.  
  65. console.log('Bulk delete cycle completed');
  66. }
  67.  
  68. // Run forever
  69. async function runForever() {
  70. while (true) {
  71. await bulkDeleteToTrash();
  72. }
  73. }
  74.  
  75.  
  76.  
  77. // Start the infinite loop
  78. runForever();
Advertisement
Add Comment
Please, Sign In to add comment