Last active
November 4, 2024 13:37
-
-
Save sanghviharshit/59aa5615a9ec2dc548c23870e21ce069 to your computer and use it in GitHub Desktop.
Delete all Google photos in small batches from GUI using Tampermonkey. Totally unattended JS version for tampermonkey. It launches on page load and it will loop till all photos are deleted.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name deleteGooglePhotos | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-07-23 | |
// @description Delete all Google photos in small batches. Based on original script from [Reddit](https://www.reddit.com/r/googlephotos/comments/kmolp9/comment/l428wca/) | |
// @author Harshit Sanghvi, u/ApplicationJunior832 | |
// @match https://photos.google.com/ | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=google.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
console.clear(); | |
console.log("Google Photos Deleter V2"); | |
const trigger = (el, etype, custom) => { | |
const evt = custom ?? new Event( etype, { bubbles: true } ); | |
el.dispatchEvent( evt ); | |
}; | |
function fDelete() { | |
console.log("fDelete()"); | |
let dd = document.getElementsByTagName("button"); | |
for (let i = 0; i < dd.length; i++) { | |
let d = dd[i]; | |
if (d.ariaLabel == "Delete") { | |
setTimeout( _ => trigger( d, 'click' ), 300); | |
break; | |
} | |
} | |
} | |
function fDeleteConfirm() { | |
console.log("fDeleteConfirm()"); | |
let dd = document.getElementsByTagName("button"); | |
for (let i = 0; i < dd.length; i++) { | |
let d = dd[i]; | |
if (d.innerText == "Move to trash") { | |
setTimeout( _ => trigger( d, 'click' ), 300); | |
break; | |
} | |
} | |
} | |
function fSelect() { | |
console.log("fSelect()"); | |
let dd = document.getElementsByTagName("div"); | |
let clickedCount = 0; | |
for (let i = 0; i < dd.length; i++) { | |
let d = dd[i]; | |
if (d.role == "checkbox" && (d.ariaLabel && d.ariaLabel.indexOf("Select") < 0) && clickedCount < 1000) { | |
clickedCount++; | |
setTimeout( _ => trigger( d, 'click' ), 5 * clickedCount); | |
} | |
} | |
} | |
function mainLoop(count) { | |
console.clear(); | |
console.log("mainLoop()", count); | |
if (count++ > 10) { | |
// Reload is needed after few batch deletes | |
console.log("mainLoop() - Reloading Page.."); | |
window.top.location.reload(); | |
} | |
setTimeout(function() { fSelect(); }, 5 ); | |
setTimeout(function() { fDelete(); }, 7 * 1000); | |
setTimeout(function() { fDeleteConfirm(); }, 10 * 1000); | |
setTimeout(function() { | |
console.log("call mainLoop()"); | |
mainLoop(count++) | |
}, 15 * 1000); | |
} | |
setTimeout(function() { mainLoop(0); }, 30 * 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment