google-photos-delete-tool icon indicating copy to clipboard operation
google-photos-delete-tool copied to clipboard

Selects images, doesn't seem to delete them

Open apple-corps opened this issue 3 years ago • 9 comments

I increased the timeouts by a factor of 2X. I see the photos selected, but I don't see the delete actions occur.

Rather it seems to repeatedly: Select the same images, clear upon deleation, and select those images again.

I checked and my language was set to US English. I set to English and the behavior was the same.

Maybe a side effect of using Chromium vs. Chrome?

Version 89.0.4389.82 (Official Build) Arch Linux (64-bit)

apple-corps avatar Mar 10 '21 19:03 apple-corps

I experience the same on both Edge as Chrome. Console does prints it is deleting but it seems the actual delete does not happen

This branch contains the necessary fixes (not my work): https://raw.githubusercontent.com/gutschik/google-photos-delete-tool/master/delete_photos.js

simkin avatar Mar 12 '21 08:03 simkin

Just seen this update, tried out the updated code works fine on Chrome 89.0.4389.82, thanks for fixing, hope this code will be promoted for other users

sameclarke avatar Mar 15 '21 11:03 sameclarke

Same issue here. But used the above modified script and it runs wonderfully!!!!! Thanks!!

bluemantwo avatar Mar 16 '21 02:03 bluemantwo

Looks like you need to update the button[title="Delete"] to button[aria-label="Delete"].

krivaten avatar Apr 07 '21 19:04 krivaten

Looks like you need to update the button[title="Delete"] to button[aria-label="Delete"].

This solution works perfectly. Thanks!

jiftechnify avatar Apr 08 '21 16:04 jiftechnify

Great script! Unfortunately, I also ran into issues with delete not working. I made a few changes to help me delete over 40K photos.

  1. I changed my page zoom from 100% to 25% which loaded more checkboxes at once.
  2. I increased the timeouts to handle the increase of checkboxes
  3. I removed setInterval! SetInterval causes the deletion process to restart every 7 seconds regardless of the script finishing the last delete. SetInterval caused conflicts, where the script was effectively stepping on itself, unchecking checked boxes.

I'm posting my changes below.

Modified Code
// How many photos to delete?
// Put a number value, like this
// const maxImageCount = 5896
const maxImageCount = "ALL_PHOTOS";

// Selector for Images and buttons
const ELEMENT_SELECTORS = {
    checkboxClass: '.ckGgle',
    deleteButton: 'button[aria-label="Delete"]',
    confirmationButton: '#yDmH0d > div.llhEMd.iWO5td > div > div.g3VIld.V639qd.bvQPzd.oEOLpc.Up8vH.J9Nfi.A9Uzve.iWO5td > div.XfpsVe.J9fJmf > button.VfPpkd-LgbsSe.VfPpkd-LgbsSe-OWXEXe-k8QpJ.nCP5yc.kHssdc.HvOprf'
}

// Time Configuration (in milliseconds)
const TIME_CONFIG = {
    delete_cycle: 12000,
    press_button_delay: 8000
};

const MAX_RETRIES = 10;

let imageCount = 0;

let checkboxes;
let buttons = {
    deleteButton: null,
    confirmationButton: null
}

let deleteTask = () => {
    let attemptCount = 1;

    do {
        checkboxes = document.querySelectorAll(ELEMENT_SELECTORS['checkboxClass']);

    } while (checkboxes.length <= 0 && attemptCount++ < MAX_RETRIES);


    if (checkboxes.length <= 0) {
        console.log("[INFO] No more images to delete.");
        clearInterval(deleteTask);
        console.log("[SUCCESS] Tool exited.");
        return;
    }

    imageCount += checkboxes.length;

    checkboxes.forEach((checkbox) => { checkbox.click() });
    setTimeout(() => {
      console.log("[INFO] Deleting", checkboxes.length, "images");
      buttons.deleteButton = document.querySelector(ELEMENT_SELECTORS['deleteButton']);
      buttons.deleteButton.click();

      setTimeout(() => {
        buttons.confirmation_button = document.querySelector(ELEMENT_SELECTORS['confirmationButton']);
        buttons.confirmation_button.click();

        console.log(`[INFO] ${imageCount}/${maxImageCount} Deleted`);
        if (maxImageCount !== "ALL_PHOTOS" && imageCount >= parseInt(maxImageCount)) {
            console.log(`${imageCount} photos deleted as requested`);
            
            console.log("[SUCCESS] Tool exited.");
            return;
        } else { setTimeout(deleteTask, TIME_CONFIG.delete_cycle) }

      }, TIME_CONFIG.press_button_delay)
    }, TIME_CONFIG.press_button_delay)
};deleteTask();

sandro avatar Apr 28 '21 16:04 sandro

Thanks Sandro, it works

garyson03152003 avatar May 10 '21 05:05 garyson03152003

Thanks Sandro! works like a charm!

cocoonkid avatar Jul 01 '21 13:07 cocoonkid

The language needs to be English otherwise it will not find the "delete" button

gampam2000 avatar May 10 '22 19:05 gampam2000