Skip to content

Instantly share code, notes, and snippets.

@MichaelLawton
Last active May 19, 2024 12:48
Show Gist options
  • Save MichaelLawton/ec73c321d62d1b4eaf0f51ca478ccd92 to your computer and use it in GitHub Desktop.
Save MichaelLawton/ec73c321d62d1b4eaf0f51ca478ccd92 to your computer and use it in GitHub Desktop.
Removes all Amazon saved for later items on the cart page. It will only remove visible items. You might want to scroll first to make more items visible. To use paste code in developer console (Ctrl+Shift+J or Cmd+Opt+J in Chrome) then press enter.
function deleteSavedItems() {
var query = document.querySelectorAll("#sc-saved-cart input[value=Delete]")
if (query.length) {
query[0].click();
}
if (query.length > 1) {
setTimeout(deleteSavedItems,100);
}
else {
console.log('Finished');
}
}
deleteSavedItems();
@avagian
Copy link

avagian commented Jul 24, 2023

If you're going to go through the saved items to review them anyway why not go through one pass on the website to add them to a wishlist first and then run this to remove everything from saved items when you're done? If you want them back in saved items again later you can easily do it from your wishlist.

For something as complicated as reading/writing from a file to modify the list - it might be better to make a chrome extension with a nice pop up UI view to select specific items/ranges of items. You can build a list of check boxes on click of the extension icon when the pop up opens and then pressing a save button actually executes the javascript on the page for matching items

Thanks, @jonathandean, for the suggestion... The problem is that some deleted/out-of-stock items don't have an "Add to cart" button. Instead, they have "See all buying options," which leads to 404 Dog pages. And I need them in my saved for later for later.. Not even sure if "add to list" would work on these items. Also, my saved-for-later is so big that I was never able to load it all. The crime time-outs and on it with a popup which probably will break the code

@MFKDGAF
Copy link

MFKDGAF commented Oct 15, 2023

Sir, thank you for this quick script! I personally had to modify it for it to work for me. I use chrome and it would just stop after a couple of items. Since I had over 500, I rewrote it to continue or wait to load more. Sharing in case it helps anyone else. :D

function deleteSavedItems() {
	/*
	* This variable finds the delete option from saved items
	*/
	var query = document.querySelectorAll('#sc-saved-cart input[value=Delete]')
	/*
	* This variable finds the amount of saved items you have
	*/
	var savedItems = document.getElementById('sc-saved-cart-list-caption-text').getAttribute('data-saved-item-quantity');
	
	//Loop until finished
	while(savedItems > 0) {
	//Check that our saved items hasn't reached zero index yet
	if (savedItems.length > 0) {
		//Check that there is a delete option for items
		if(query.length) {
			query[0].click();
		}
		//The list isn't zero but no delete option was found, so wait for the page to refresh more saved items
		else if (!query.length) {
		setTimeout(deleteSavedItems, 200);
		}
	}
	//Quickly delete the items that are present
	if (query.length > 1) {
		setTimeout(deleteSavedItems,35);
	}
	savedItems--;
	}
}
deleteSavedItems();

Confirming this still works as of October 15th, 2023.
Thank you for this. This was a life saver. Stupid ex-wife had saved over 600 items.

@marbisca
Copy link

Sir, thank you for this quick script! I personally had to modify it for it to work for me. I use chrome and it would just stop after a couple of items. Since I had over 500, I rewrote it to continue or wait to load more. Sharing in case it helps anyone else. :D

function deleteSavedItems() {
	/*
	* This variable finds the delete option from saved items
	*/
	var query = document.querySelectorAll('#sc-saved-cart input[value=Delete]')
	/*
	* This variable finds the amount of saved items you have
	*/
	var savedItems = document.getElementById('sc-saved-cart-list-caption-text').getAttribute('data-saved-item-quantity');
	
	//Loop until finished
	while(savedItems > 0) {
	//Check that our saved items hasn't reached zero index yet
	if (savedItems.length > 0) {
		//Check that there is a delete option for items
		if(query.length) {
			query[0].click();
		}
		//The list isn't zero but no delete option was found, so wait for the page to refresh more saved items
		else if (!query.length) {
		setTimeout(deleteSavedItems, 200);
		}
	}
	//Quickly delete the items that are present
	if (query.length > 1) {
		setTimeout(deleteSavedItems,35);
	}
	savedItems--;
	}
}
deleteSavedItems();

Confirming this still works as of October 15th, 2023. Thank you for this. This was a life saver. Stupid ex-wife had saved over 600 items.

I get "undefined" , Why?

@deosamox
Copy link

I've modified this to work in 2024:

function deleteSavedItems() {
    var elements = document.querySelectorAll("input[name^='submit.delete.']");

    if (elements.length > 0) {
        elements.forEach(function(element) {
            element.click();
        });
        setTimeout(deleteSavedItems, 100);
    } else {
        console.log('Finished');
    }
}

deleteSavedItems();

@corcorj
Copy link

corcorj commented Apr 3, 2024

Should you desire to move your items to a Wish List instead of deleting them for good, you can do so with a slight extension to the great script already provided by @MichaelLawton. You'll need to view the source of your Shopping Cart page to get the list/registry ID of your specific list to save them to (should look something like "#registry-XXXXXXXXXXXXX").

function moveToWishList() {
	var query = document.querySelectorAll("#sc-saved-cart input[value='Move to Wish List']")
	if (query.length) {
		query[0].click();
	}
	var query2 = document.querySelectorAll("#registry-XXXXXXXXXXXXX a")
	if (query2.length) {
		query2[0].click();
	}
	if (query.length > 1) {
		setTimeout(moveToWishList,5000);
	}
	else {
		console.log('Finished');
	}
}
moveToWishList();

THANK YOU!! @PeterSchuebel , @MichaelLawton and @kyletmiller

@xbliss
Copy link

xbliss commented May 19, 2024

Can we do/ add a similar script (direct or via Grease Monkey etc) or via an Extension to do this WishList action(s)?

https://webapps.stackexchange.com/questions/118938/amazon-wishlists-select-and-move-multiple-items-at-same-time-from-one-default

Amazon Wishlists: Select and Move multiple items at same time from One/ Default Wishlist to others?

Have collected a lot of items on Default Wishlist and would like to MOVE and organize them.

As shown below, one has to select each item one at time from a Default Wishlist to MOVE it to other ones to Organize them.

I was hoping there was some way to select multiple and have them MOVE together to another list - many at one go; I am guessing some kind "multi select" using Checkmarks or something else.

Thoughts & ideas welcome.

https://i.stack.imgur.com/JSJVt.png

enter image description here

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