Deleting Multiple Courses from Garmin Connect - updated

I found this post helpful but the scripts did not work anymore.

This worked for me after komoot spammed my garmin account.

(() => {
    const clickInterval = setInterval(() => {
        const firstButton = document.querySelector('button.CourseListItem_deleteButtonItem__qvPP2[title="Delete"]');

        if (firstButton) {
            firstButton.click();
            console.log("First button clicked.");

            setTimeout(() => {
                const secondButton = Array.from(document.querySelectorAll('button.Button_btnDanger__137s7.Button_btnMedium__Icah-'))
                    .find(btn => btn.textContent.trim() === "Delete");
                if (secondButton) {
                    secondButton.click();
                    console.log("Second button clicked.");
                } else {
                    console.warn("Second button not found.");
                }
            }, 500);

        } else {
            console.warn("No more buttons found, stopping loop.");
            clearInterval(clickInterval);
        }
    }, 1500);  // Wait 1.5 seconds before each iteration
})();