Created
April 30, 2025 18:49
-
-
Save landonepps/505e0e6ba0d3b128256d6b169c8a6868 to your computer and use it in GitHub Desktop.
Subscribe & Save Canceller Userscript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Amazon Subscribe & Save Canceller | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Add a button to cancel all Amazon Subscribe & Save subscriptions | |
// @author - | |
// @match https://www.amazon.com/auto-deliveries/* | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
function addCancelButton() { | |
const button = document.createElement('button'); | |
button.textContent = 'Cancel All Subscriptions'; | |
button.style.position = 'fixed'; | |
button.style.top = '10px'; | |
button.style.right = '10px'; | |
button.style.zIndex = '10000'; | |
button.style.padding = '10px'; | |
button.style.backgroundColor = '#d00'; | |
button.style.color = 'white'; | |
button.style.border = 'none'; | |
button.style.borderRadius = '5px'; | |
button.style.cursor = 'pointer'; | |
button.addEventListener('click', async () => { | |
const subscriptionElements = [...document.querySelectorAll('[data-subscription-id]')]; | |
await Promise.all(subscriptionElements.map(el => el.getAttribute('data-subscription-id')).map(async (subscriptionId) => { | |
try { | |
const res = await fetch(`https://www.amazon.com/auto-deliveries/ajax/cancelSubscription?deviceType=desktop&deviceContext=web&subscriptionId=${subscriptionId}`); | |
const cancelPanel = await res.text(); | |
const div = document.createElement('div'); | |
div.innerHTML = cancelPanel; | |
document.body.appendChild(div); | |
const form = div.querySelector("form[name='cancelForm']"); | |
if (form) { | |
const formData = new FormData(form); | |
const formEntries = Object.fromEntries(formData.entries()); | |
await fetch(form.action, { | |
method: form.method, | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded', | |
}, | |
body: new URLSearchParams(formEntries) | |
}); | |
} | |
div.remove(); | |
} catch (e) { | |
console.error(`Error cancelling subscription ${subscriptionId}:`, e); | |
} | |
})); | |
alert('Done processing all subscriptions.'); | |
}); | |
document.body.appendChild(button); | |
} | |
window.addEventListener('load', addCancelButton); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment