Created
June 28, 2025 13:58
-
-
Save mokkabonna/abba087706224e7daa0efb179077f017 to your computer and use it in GitHub Desktop.
Delete multiple garmin courses by name
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
const delteButtonText = 'Slett'; | |
function findAllDeleteButtons() { | |
return [...document.querySelectorAll('[title='+delteButtonText+']')]; | |
} | |
function findDialogByBodyText(text) { | |
const dialogs = document.querySelectorAll('[class*=dialogBody]'); | |
for (let dialog of dialogs) { | |
if (dialog.textContent.includes(text)) { | |
return dialog.closest('[class*=Dialog_dialogContainer]'); | |
} | |
} | |
return null; | |
} | |
async function clickAllDeleteButtonsThenConfirmTheModal(text) { | |
const deleteButtons = findAllDeleteButtons(); | |
for await (const button of deleteButtons) { | |
console.log('Clicking delete button:', button); | |
button.click(); | |
await new Promise(resolve => setTimeout(resolve, 100)); // Wait for the modal to appear | |
const modal = findDialogByBodyText(text); | |
console.log(modal) | |
if (modal) { | |
const modalButtons = [...modal.querySelectorAll('button')]; | |
const deleteButton = modalButtons.find(b => b.textContent.includes(delteButtonText)); | |
if (deleteButton) { | |
deleteButton.click(); | |
console.log('Clicked delete button in modal'); | |
await new Promise(resolve => setTimeout(resolve, 100)); // Wait for the deletion to complete | |
} else { | |
console.warn('Delete button not found in modal'); | |
} | |
} | |
} | |
} | |
// change this text to what you want deleted | |
clickAllDeleteButtonsThenConfirmTheModal('some shared name of the courses') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment