Skip to content

Instantly share code, notes, and snippets.

@wusisu
Created April 19, 2020 14:30
Show Gist options
  • Save wusisu/0d01b2d362a353874fa8341f749114ca to your computer and use it in GitHub Desktop.
Save wusisu/0d01b2d362a353874fa8341f749114ca to your computer and use it in GitHub Desktop.
浏览器 js 脚本删除 google photos 所有照片
// 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[title="删除"]',
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: 7000,
press_button_delay: 1000
};
let imageCount = 0;
let checkboxes;
let buttons = {
deleteButton: null,
confirmationButton: null
}
let deleteTask = setInterval(() => {
checkboxes = document.querySelectorAll(ELEMENT_SELECTORS['checkboxClass']);
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() });
console.log("[INFO] Deleting", checkboxes.length, "images");
setTimeout(() => {
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`);
clearInterval(deleteTask);
console.log("[SUCCESS] Tool exited.");
return;
}
}, TIME_CONFIG['press_button_delay']);
}, TIME_CONFIG['press_button_delay']);
}, TIME_CONFIG['delete_cycle']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment