Skip to content

Instantly share code, notes, and snippets.

@xbb
Created November 19, 2022 01:57
Show Gist options
  • Save xbb/6c83a4d238de83e9b671581e79dae2f9 to your computer and use it in GitHub Desktop.
Save xbb/6c83a4d238de83e9b671581e79dae2f9 to your computer and use it in GitHub Desktop.
Amazon save for later cleaner: removes all the saved for later items from your cart page, read usage below

Amazon save for later cleaner

The scripts deletes one item at a time, waiting for its node removal and 1 second.

It will wait for new items to load in the page, so there is no need to preload the whole list.

Actually, if you preload the whole list before, it will make things slower and worse because every delete request contains all your displayed item list…

Usage:

  • Drop the content of cleaner.js in the browser console while in the cart page

  • Execute cleaner.startDelete()

  • If needed, stop the script with cleaner.stopDelete() or reload the page

cleaner = (() => {
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const waitNodeRemoval = (target) => {
return new Promise((resolve) => {
if (!document.documentElement.contains(target)) {
resolve();
return;
}
const observer = new MutationObserver(function(mutations) {
for (const mut of mutations) {
for (const node of mut.removedNodes) {
if (node === target || node.contains(target)) {
observer.disconnect();
resolve();
return;
}
}
}
});
observer.observe(document.documentElement, {
childList: true,
subtree: true
});
});
};
let stop;
const startDelete = async () => {
let savedCount = document.getElementById('sc-saved-cart-list-caption-text').getAttribute('data-saved-item-quantity');
stop = false;
while (!stop && savedCount > 0) {
const item = document.querySelector("[id^=sc-saved] input[data-action=delete]");
if (item) {
const removePromise = waitNodeRemoval(item);
item.click();
await removePromise;
savedCount--;
}
await delay(1000);
}
};
const stopDelete = () => {
stop = true;
};
return {
stopDelete,
startDelete
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment