Skip to content

Instantly share code, notes, and snippets.

@valueforvalue
Created April 4, 2026 23:00
Show Gist options
  • Select an option

  • Save valueforvalue/2adaf42b793821b0b9e0ac32da3eb122 to your computer and use it in GitHub Desktop.

Select an option

Save valueforvalue/2adaf42b793821b0b9e0ac32da3eb122 to your computer and use it in GitHub Desktop.
Delete all Amazon Cart and Saved for Later items
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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment