Skip to content

Instantly share code, notes, and snippets.

@MichaelLawton
Last active April 24, 2024 19:06
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();
@ember-parr
Copy link

This is a thing of beauty.

@el1502
Copy link

el1502 commented Jun 15, 2020

Hi, thanks for sharing, it works fine with Amazon... Does anyone have the same solution for Walmart save later lists?. I appreciate it.

@woodspixie
Copy link

Hi all,
Worked wonderfully at first, then stopped suddenly; error message: ERR_CONNECTION_REFUSED
Any ideas to fix, please?
Have tried restarting and updating Chrome, tried another browser, entered a “clear all” message; nothing has worked thus far. Cheers~

@woodspixie
Copy link

Never mind, I worked it out; my basket was empty! It had the same items in it as before, but the title had changed to “your items”. I just didn’t notice the change. Will leave posted in case it happens to anyone else :)

@md4450
Copy link

md4450 commented Sep 21, 2020

Thanks, Saved me a lot of time and now hopefully no more notifications for stuff I put on there 7 years ago.

@ronaldisaac
Copy link

Thanks, Saved me a lot of time, as i was hitting remove again and agains. Thanks a lot for posting it out here.

@effofxprime
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();

@sg2446p
Copy link

sg2446p commented Dec 8, 2020

@kyletmiller gave us a version to move items to wishlist instead of deleting them for good. In it he says "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")". I view the source of my shopping cart by pressing Ctl+Shift+C. However, I cannot see anything that starts with "#registry". Can anyone tell me what I'm missing? Also, I'm a newbie, so I do not know how to search within what is displayed on the console. How do I do that? Thank you!

@sg2446p
Copy link

sg2446p commented Dec 8, 2020

The version provided by @effofxprime waits for more items to load. I'm a newbie, with tons of items, but I'd like to combine his version with the idea that @kyletmiller gave us which instead of deleting them, will move them to wishlist. I'm not at all skilled with coding this. Can someone provide me a combo of the two? Namely, @effofxprime version, but modified to move them all to wishlist instead of deleting. Thank you!

@effofxprime
Copy link

@sg2446p Hey man, I've been busy the last few days but had you in mind to write this up sooner! I haven't tried this yet, you'll have to be my guinea pig. ;)
Thank you @kyletmiller for the original, I updated it to how I modified the original.
effofxprime/moveToWishList@7b470f5

@sg2446p
Copy link

sg2446p commented Dec 15, 2020 via email

@PMQdev
Copy link

PMQdev commented Apr 27, 2021

this is a script to MOVE all items in the cart to SAVED for later

basically like clicking "save for later" till there is no more

function saveActiveItems() {
var query = document.querySelectorAll("#activeCartViewForm input[value='Save for later']")
console.log('started');

if (query.length) {
console.log('query.length = ' + query.length);
query[0].click();
}
if (query.length > 1) {
console.log('query.length = ' + query.length);
setTimeout(saveActiveItems,100);
}
else {
console.log('Finished');
}
}

saveActiveItems();

Hey could you make a script to move an item via id to save for later? that would really help me x

@briantrease
Copy link

briantrease commented Jun 6, 2021

Awesome: This script works great! Thank you @kyletmiller and @MichaelLawton

Challenge: I'd like to SELECT which items from my "Saved for later" that I will delete (or move to a wishlist).

Idea: Who can modify this script so that it first scrapes all the sc-saved-cart items to a text file? Then I can go edit that list, by deleting all the items I do NOT want to take action on. Then I would run a second script that pulls from my edited text file to delete (or move) ONLY the items listed in the text file.

I would do this myself, but I don't know how to write/read output to a text file.

Approach: The approach would be similar to the initial script, but instead of doing
query[0].click();
in the first if-loop,
just write the
aria-label
value as a new line in a text file.

Hint, here is what the source code looks like for an item currently in my "Saved for later":

<input name="submit.move-to-wishlist.S83021b45-474b-4f41-bd42-7427470b9789"
     value="Move to Wish List"
     data-action="move-to-wishlist"
     aria-label="Move to Wish List The Quick Fix: Why Fad Psychology Can&amp;#39;t Cure Our Social Ills"
     type="button"
     class="a-color-link"/>

(The second if-loop is not needed in this first script, because its action will instead be completed by a second script to be run later.)

When the first script is complete, the text file can then be edited however I wish.

THEN, I run a second script, which runs as a loop that goes through the whole text file, line by line, where ...

instead of querying on
input[value='Move to Wish List']
it queries on
input[aria-label='xxxxxxxxxxxxxxxx']

where 'xxxxxxxxxxxxxxxx'
is a line from the text file

For example:
document.querySelectorAll("#sc-saved-cart input[aria-label='Move to Wish List The Quick Fix: Why Fad Psychology Can&amp;#39;t Cure Our Social Ills']")

Seems like it should work? Thanks!

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();

Thanks for sharing, @MichaelLawton!

@syberknight
Copy link

A big THANKS also to @MichaelLawton and @kyletmiller for the "moveToWishList" option @ https://gist.github.com/MichaelLawton/ec73c321d62d1b4eaf0f51ca478ccd92#gistcomment-3005931

worked great for me after i changed the 5000 "setTimeout" to 10000 (to give my items more time to load).
i very much appreciate the generosity & time you folks give to the community.

@dzg
Copy link

dzg commented Jul 30, 2021

Here's a script (adapted from this) to save all cart item in "Save for Later": https://gist.github.com/dzg/0cfe22c496355f20ab6ff24dd00848f3

@vlussenburg
Copy link

vlussenburg commented Oct 8, 2021

Adding another one to the fold (might work for Amazon Fresh too)

I use Share-a-Cart for weekly groceries and specific recipes and often I end up with a cart I don't actually want to buy, for example, when I share the entire cart with my partner and they order it instead of me.

Emptying a 50+ item cart is a PITA

So:

function deleteWholeFoodsCart() {
	var query = document.querySelectorAll("#sc-expanded-cart-localmarket input[value='Delete']")
	if (query.length) {
		query[0].click();
	}
	if (query.length > 1) {
		setTimeout(deleteWholeFoodsCart, 500);
	}
	else {
		console.log('Finished');
	}
}
deleteWholeFoodsCart();

https://gist.github.com/vlussenburg/f92a983c13884302a919a0dd905e3a0c

Thanks for everyone's contributions!

@spurin
Copy link

spurin commented Dec 12, 2021

Thanks for sharing, still works well today (albeit, it needs some copy/paste between page refreshes but other than that, it's great)

@rachelmstanley
Copy link

Hey all..these scripts worked beautifully right up until now. Not sure exactly when they stopped working. However, now, anytime I run the move to wishlist or delete whole foods cart scripts, I get 'undefined' error. Thoughts? Anyone else having this issue and have a solution?

Copy link

ghost commented Jul 26, 2022

thank you

@allegrabottlik
Copy link

@rachelmstanley Hey all..these scripts worked beautifully right up until now. Not sure exactly when they stopped working. However, now, anytime I run the move to wishlist or delete whole foods cart scripts, I get 'undefined' error. Thoughts? Anyone else having this issue and have a solution?

I am also having this issue. I believe it has to do with the new checkboxes to the left of items in the cart to select or deselect them. Haven't had a chance to find a workaround - anyone else taking a look at this?

I have a gist forked from this one to save items from cart into a wishlist and it is broken in the same way.

@jnima2022
Copy link

best one yet, delete save for later items. doesn't stop when page reloading more item. Working well in 2023

@MuhammadSaad7
Copy link

Thank you :)

@avagian
Copy link

avagian commented Jul 18, 2023

Awesome: This script works great! Thank you @kyletmiller and @MichaelLawton

Challenge: I'd like to SELECT which items from my "Saved for later" that I will delete (or move to a wishlist).

Idea: Who can modify this script so that it first scrapes all the sc-saved-cart items to a text file? Then I can go edit that list, by deleting all the items I do NOT want to take action on. Then I would run a second script that pulls from my edited text file to delete (or move) ONLY the items listed in the text file.

I would do this myself, but I don't know how to write/read output to a text file.

Hi @briantrease
Any luck with a selective delete/save to the list?
What if there will be a checkbox near every loaded item allowing for selective bulk action? It's better than txt, since you can see the picture.
We'll load the whole list by pressing "Page Down" and waiting multiple times; it loads as much as we need, select the items we want to delete/move and press a single button.
Is it too complicated to write?

@jonathandean
Copy link

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

@avagian
Copy link

avagian commented Jul 24, 2023

Thanks @MichaelLawton and @mhujsak
Amazon has changed a little bit, here is the modified "Add to list" instead of "Move to Wish List" Version
you can get XXXXXXXXXXXX from your list URL as well https://www.amazon.com/hz/wishlist/ls/XXXXXXXXXXXX
I'll load it all and will leave it overnight. But if 10000 is very slow for you, modify it to a lower number.
p.s. deleteSavedItems workes fine without any mod

function moveToWishList() {
	var query = document.querySelectorAll("#sc-saved-cart input[value='Add to list']")
	if (query.length) {
		query[0].click();
	}
	var query2 = document.querySelectorAll("#cldd-list-name-XXXXXXXXXXXX")
	if (query2.length) {
		query2[0].click();
	}
	if (query.length > 1) {
		setTimeout(moveToWishList,10000);
	}
	else {
		console.log('Finished');
	}
}
moveToWishList();

@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

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