Created
November 9, 2022 17:12
-
-
Save Macrofig/22d31ef87ddebfa7d96caaf0d2584740 to your computer and use it in GitHub Desktop.
For some reason, when moving a website to Cloudflare, there were over a hundred DNS entries. This script goes through the UI and deletes them all. **Super rough draft.**
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 generateDeleteEntries = () => { | |
| const isDialogOpen = () => Boolean(document.querySelector("[role='dialog']")) | |
| const isDeleteVisible = () => Boolean(document.querySelector("[data-testid='dns-record-form-delete-button']")) | |
| const awaitHandler = (predicate, cb, count = 0) => () => { | |
| if (predicate()) { | |
| console.log('done waiting!!') | |
| cb(); | |
| } else { | |
| if (count > 5) { | |
| console.log('UH OH, it took too long!') | |
| } | |
| console.log('waiting...') | |
| count = count + 1; | |
| setTimeout(awaitHandler(predicate, cb, count), 500) | |
| } | |
| } | |
| const awaitThing = (predicate) => { | |
| return (new Promise((resolve) => { | |
| setTimeout(awaitHandler(predicate, resolve), 500) | |
| })) | |
| } | |
| // const getDeletes = () => [...document.querySelectorAll("table tr td span a span")].filter((node) => node.textContent === 'Delete') | |
| const getDeletes = () => [...document.querySelectorAll('[data-testid="dns-table-row-edit-link"] span:first-of-type')].filter((node) => node.textContent === 'Edit') | |
| const deleteDns = async () => { | |
| // get list of records | |
| const records = getDeletes(); | |
| while (records.length > 0) { | |
| const currentRecord = records.pop(); | |
| currentRecord.click(); | |
| console.log('Open slide out') | |
| await awaitThing(isDeleteVisible); | |
| document.querySelector("[data-testid='dns-record-form-delete-button']").click() | |
| await awaitThing(isDialogOpen); | |
| console.log('Commiting delete of: ', document.querySelector("[role='dialog'] h3").textContent) | |
| document.querySelector("[data-testid='dns-delete-modal-confirm-button']").click(); | |
| await awaitThing(() => !isDeleteVisible()); | |
| console.log(`Deleted, ${records.length} records to go.`) | |
| } | |
| console.log("YEAAA! All done!") | |
| } | |
| return deleteDns; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment