Skip to content

Instantly share code, notes, and snippets.

@MichaelLawton
Last active April 4, 2026 22:58
Show Gist options
  • Select an option

  • Save MichaelLawton/ec73c321d62d1b4eaf0f51ca478ccd92 to your computer and use it in GitHub Desktop.

Select an option

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();
@deosamox
Copy link
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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

@debughercules
Copy link
Copy Markdown

Addition to above solution

Working Chrome 08-2024

Just zoom out Chrome window to 25% (or minimum)

Paste this in the dev console

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');
    }
}

var intervalId = window.setInterval(function(){
  deleteSavedItems();
}, 5000);

Later you can close the tab or you can paste the following code to stop the loop

clearInterval(intervalId)

@mittingphx
Copy link
Copy Markdown

I got a little frustrated last night with some of the query limit errors and having to restart the script (my soon to be ex-wife had over 750 items saved), so I rewrote the script, though I think the setInterval in the above script would have handled it just fine.

https://github.com/mittingphx/WebsiteAutomation

@mittingphx
Copy link
Copy Markdown

Looks like others also added similar checks to restart the script automatically when you get the quota limit errors. Here's a link to the version that I wrote last night which worked well the first time without any further intervention (super fun to watch the count go down in real time). Fingers cross it continues to work, works great in Oct 2024. https://github.com/mittingphx/WebsiteAutomation

@bcostaaa01
Copy link
Copy Markdown

None of the above worked for me unfortunately, but after some iteration, I was able to get it to work for me:

async function deleteAllSavedItems() {
  while (true) {
    const deleteButtons = document.querySelectorAll('input[data-action="delete-saved"]');
    if (deleteButtons.length === 0) {
      console.log("No more saved items to delete.");
      break;
    }

    deleteButtons[0].click();
    console.log("Deleted one saved item, remaining:", deleteButtons.length - 1);

    await new Promise(resolve => setTimeout(resolve, 2000));
  }
}

deleteAllSavedItems();

Maybe Amazon updated their HTML, so the other approaches didn't work.

@valueforvalue
Copy link
Copy Markdown

valueforvalue commented Apr 4, 2026

function deleteAllAmazonItems() {
    // This query looks for Delete buttons in BOTH the active cart and saved items
    // based on the specific selectors in your page source
    var query = document.querySelectorAll("#sc-active-cart input[value=Delete], #sc-saved-cart input[value=Delete], input[data-action='delete-active']");
    
    if (query.length > 0) {
        console.log('Items remaining: ' + query.length);
        query[0].click();
        
        // Wait 1 second for Amazon to update the UI, then run again
        setTimeout(deleteAllAmazonItems, 1000);
    } else {
        // If no buttons are found, try scrolling once to see if more lazy-load
        window.scrollTo(0, document.body.scrollHeight);
        
        setTimeout(function() {
            var retryQuery = document.querySelectorAll("#sc-active-cart input[value=Delete], #sc-saved-cart input[value=Delete], input[data-action='delete-active']");
            if (retryQuery.length > 0) {
                deleteAllAmazonItems();
            } else {
                console.log('Finished :) All items cleared.');
            }
        }, 2000);
    }
}

deleteAllAmazonItems();

Was able to get this to work, it is a little slow but was able to delete over 500 items without issue.

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