Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function waitForDOMStability(timeout = 5000, checkInterval = 500) {
- return new Promise((resolve) => {
- let timeoutId;
- let lastMutationTime = Date.now();
- const observer = new MutationObserver(() => {
- lastMutationTime = Date.now();
- clearTimeout(timeoutId);
- timeoutId = setTimeout(() => {
- observer.disconnect();
- resolve();
- }, checkInterval);
- });
- observer.observe(document.body, {
- childList: true,
- subtree: true,
- attributes: true
- });
- // Initial timeout in case no mutations occur
- timeoutId = setTimeout(() => {
- observer.disconnect();
- resolve();
- }, checkInterval);
- // Safety timeout to prevent infinite waiting
- setTimeout(() => {
- observer.disconnect();
- resolve();
- }, timeout);
- });
- }
- async function bulkDeleteToTrash() {
- while (document.body.innerText.indexOf('Moviendo')!=-1) {
- await new Promise(resolve => setTimeout(resolve, 1000));
- }
- // Select all items
- [...document.querySelectorAll('[aria-label*="Seleccionar todas"]')].forEach(e => e.click());
- [...document.querySelectorAll('[role="checkbox"] svg:first-child')].forEach(e=>e.parentElement.click())
- // Wait 1 second
- await new Promise(resolve => setTimeout(resolve, 1000));
- // Click move to trash button
- document.querySelector('[aria-label="Mover a la papelera"]')?.click();
- // Wait 1 second
- await new Promise(resolve => setTimeout(resolve, 1000));
- // Confirm move to trash
- document.evaluate(
- "//button[contains(., 'Mover a la papelera')]",
- document,
- null,
- XPathResult.FIRST_ORDERED_NODE_TYPE,
- null
- ).singleNodeValue?.click();
- // Wait for DOM to stabilize after deletion
- await waitForDOMStability();
- console.log('Bulk delete cycle completed');
- }
- // Run forever
- async function runForever() {
- while (true) {
- await bulkDeleteToTrash();
- }
- }
- // Start the infinite loop
- runForever();
Advertisement
Add Comment
Please, Sign In to add comment