Skip to content

Instantly share code, notes, and snippets.

@mturilin
Created March 29, 2020 22:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mturilin/dd649f883458846052957ad5fe5d1e27 to your computer and use it in GitHub Desktop.
Save mturilin/dd649f883458846052957ad5fe5d1e27 to your computer and use it in GitHub Desktop.
Delete all Google Photos
for(i = 1; i<=9999; i++) {
console.log("Iteration # --> " + i);
document.querySelectorAll('div[role=checkbox]').forEach(div=>div.click());
document.querySelectorAll('div[aria-label*="Select all photos"]').forEach(div=>div.click());
await new Promise(r => setTimeout(r, 3000));
try{console.log("Selected documents count for iteration [" + i + "]: " + document.evaluate('/html/body/div[1]/div/c-wiz/c-wiz[2]/span/div[1]/div/span', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.innerText);}catch(ex){/*do nothing*/}
document.querySelector('button[title=Delete]').click();
await new Promise(r => setTimeout(r, 5000));
document.evaluate('//span[text()="Move to trash"]', document, null, XPathResult.ANY_TYPE, null ).iterateNext().click();
//wait for new images to load
await new Promise(r => setTimeout(r, 15000));
}
@neshant
Copy link

neshant commented Aug 4, 2023

Thanks for this script there have been slight changes in html tags , here is the updated script

for(i = 1; i<=9999; i++) {
    console.log("Iteration # --> " + i);
    document.querySelectorAll('div[role=checkbox]').forEach(div=>div.click());
    document.querySelectorAll('div[aria-label*="Select all photos"]').forEach(div=>div.click());
    await new Promise(r => setTimeout(r, 3000));
try{console.log("Selected documents count for iteration [" + i + "]: " + document.evaluate('/html/body/div[1]/div/c-wiz/c-wiz[2]/span/div[1]/div/span', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.innerText);}catch(ex){/*do nothing*/}
    document.querySelector('button[aria-label=Delete]').click();
    await new Promise(r => setTimeout(r, 5000));
    document.evaluate('//span[text()="Move to bin"]', document, null, XPathResult.ANY_TYPE, null ).iterateNext().click();

    //wait for new images to load
    await new Promise(r => setTimeout(r, 15000));
}

@dcepelik
Copy link

dcepelik commented Apr 20, 2024

Thanks for this. I made some updates to make sure it works with the current UI, and made it a bit more robust. Note, I don't think I've ever written JS before, so I eyeballed this:

async function googleDontBeEvilAndLetMeJustDeleteMyPhotosFFS() {
    for (;;) {
        document.querySelector('a[href="./explore"]').click();
        await new Promise(r => setTimeout(r, 5000));
        document.querySelector('a[href="./"]').click();
        await new Promise(r => setTimeout(r, 5000));

        document.querySelectorAll('div[role=checkbox]').forEach(div => div.click());
        document.querySelectorAll('div[aria-label*="Select all photos"]').forEach(div => div.click());
        await new Promise(r => setTimeout(r, 5000));
        d = document.querySelector('button[aria-label=Delete]');
        if (!d)
            continue; // try again
        d.click();
        b = null;
        do {
            await new Promise(r => setTimeout(r, 1000));
            console.log("Looking for the stupid button");
            b = document.evaluate('//span[text()="Move to trash"]', document, null, XPathResult.ANY_TYPE, null).iterateNext();
        } while (!b);
        b.click()

        await new Promise(r => setTimeout(r, 5000));
    }
}
await googleDontBeEvilAndLetMeJustDeleteMyPhotosFFS()

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