Skip to content

Instantly share code, notes, and snippets.

@effofxprime
Forked from MichaelLawton/deleteAmazonSavedItems.js
Last active December 13, 2020 20:02
Show Gist options
  • Save effofxprime/dd8a08d6299d147bdd87cba0ef547830 to your computer and use it in GitHub Desktop.
Save effofxprime/dd8a08d6299d147bdd87cba0ef547830 to your computer and use it in GitHub Desktop.
How to use: First go to your cart on amazon. Bring up the developer console: CTRL+SHIFT+J for chrome. Copy and paste the code into the developer console and press enter. You do not need to stay on the page for it to work. Check back in a few to see if it has completed. ... PROFIT!
/*
* 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.
* Original script by: https://gist.github.com/MichaelLawton
*
* For my purposes, I updated this script so it would continuously keep deleting my saved for later items.
* I had over 500 and the original would only remove a handful before stopping.
* While this runs, you do not need to stay on the window/page for it to work.
*/
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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment