Skip to content

Instantly share code, notes, and snippets.

@Lampe2020
Created September 29, 2024 17:21
Show Gist options
  • Save Lampe2020/30ab6eaed0cba71b222cf860d3faf824 to your computer and use it in GitHub Desktop.
Save Lampe2020/30ab6eaed0cba71b222cf860d3faf824 to your computer and use it in GitHub Desktop.
"Select all" function for Google Photos

GooglePhotoSelectAll

A (semi-)simple script/bookmarklet to select all photos and videos on the Google Photo desktop website.
To run it as a bookmarklet, bookmark the Google Photos website and edit the bookmark URL to the long line in GooglePhotosSelectAll.bookmarklet-url.js. Otherwise you can also run the contents of GooglePhotosSelectAll.js in your browser console.

Incase this stops working

It looks to me as if the class names for the scroll container are random, so they may change at any point. If that happens, try to find the scrollable container (the outermost element around the images in the markup that has an absurd vertical size, indicating that it is scrollable because of all the images) and add its ID in your copy of the script to the list of IDs the script tries to get at the beginning.

javascript:var l2GPhotoSelectAllInterruptFlag=false;var l2GPhotoSelectAllScrollBox=document.querySelector('.C3Tghf,.T5QJEc,.THsa9b');setInterval(()=>{if(!l2GPhotoSelectAllInterruptFlag){document.querySelectorAll('.ckGgle[aria-checked=false]').forEach((elmnt)=>{elmnt.scrollIntoView();elmnt.click();console.log(`Selecting the image labelled ${elmnt?.ariaLabel}`);});}},(1000/(Number(prompt('Enter how many times per second you want the script to fire.\nThe slower the page loads for you the lower you should set this.\nShould the script get stuck before the bottom, just scroll down a bit until it picks up again. If you needed to do so and are unsure if the script missed any images, run it again on a slower setting until it runs all the way to the bottom without manual scrolling.','1'))||1)));console.log(`l2GPhotoSelectAllScrollBox:`,l2GPhotoSelectAllScrollBox);alert('The script is going to start now. When it reaches the bottom, please run the following command in the console to stop the script:\n\nl2GPhotoSelectAllInterruptFlag = true;')
var l2GPhotoSelectAllInterruptFlag = false;
var l2GPhotoSelectAllScrollBox = document.querySelector('.C3Tghf,.T5QJEc,.THsa9b'); // Get the scroll box, with any of the three classes
setInterval(()=>{
if (!l2GPhotoSelectAllInterruptFlag) {
document.querySelectorAll('.ckGgle[aria-checked=false]').forEach((elmnt)=>{
elmnt.scrollIntoView(); // Scroll to the element to make the elements below visible
elmnt.click(); // Select all images that are selectable and not selected yet
console.log(`Selecting the image labelled ${elmnt?.ariaLabel}`);
});
}
}, (1000 / (Number(prompt('Enter how many times per second you want the script to fire.\nThe slower the page loads for you the lower you should set this.\nShould the script get stuck before the bottom, just scroll down a bit until it picks up again. If you needed to do so and are unsure if the script missed any images, run it again on a slower setting until it runs all the way to the bottom without manual scrolling.', '1'))||1))); // Run the routine n times per second
console.log(`l2GPhotoSelectAllScrollBox:`, l2GPhotoSelectAllScrollBox);
alert('The script is going to start now. When it reaches the bottom, please run the following command in the console to stop the script:\n\nl2GPhotoSelectAllInterruptFlag = true;');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment