Amazon Subscription Canceler

Cancel all subscriptions with one button click

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Amazon Subscription Canceler
// @namespace    elias.eu.org
// @version      1.0
// @description  Cancel all subscriptions with one button click
// @author       eliasbenb
// @license      MIT
// @match        https://www.amazon.com/auto-deliveries/subscriptionList
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Create a button
    let button = document.createElement('button');
    button.innerHTML = 'Cancel Subscriptions';
    button.style.position = 'fixed';
    button.style.top = '163px';
    button.style.right = '10px';
    button.style.zIndex = '1000';
    button.style.padding = '10px';
    button.style.backgroundColor = '#ff9900';
    button.style.color = '#fff';
    button.style.border = 'none';
    button.style.borderRadius = '5px';
    button.style.cursor = 'pointer';

    // Append the button to the body
    document.body.appendChild(button);

    // Function to cancel subscriptions
    function cancelSubscriptions() {
        let baseUrl = "https://www.amazon.com/auto-deliveries/ajax/cancelSubscriptionAction?actionType=cancelSubscription&canceledNextDeliveryDate=1730880000000&subscriptionId=";
        let spans = document.querySelectorAll('span[data-action="edit-link-subscription-tablet"]');
        let subscriptionIds = [...spans].map(span => {
            let data = span.getAttribute('data-edit-link-subscription-tablet');
            let match = data.match(/subscriptionId=([^&"]+)/);
            return match ? match[1] : null;
        }).filter(id => id);
        console.log(`Found ${subscriptionIds.length} subscription IDs.`);

        function openNextUrl(index) {
            if (index >= subscriptionIds.length) {
                console.log('All URLs have been opened.');
                return;
            }
            let id = subscriptionIds[index];
            let url = baseUrl + id;
            console.log(`Opening URL: ${url}`);
            let newWindow = window.open(url, '_blank');
            setTimeout(() => {
                openNextUrl(index + 1);
            }, 1000);
        }

        openNextUrl(0);
    }

    // Add click event listener to the button
    button.addEventListener('click', cancelSubscriptions);
})();