Useful script to bulk delete all incorrectly imported DNS records

I had a problem a few others reported about it this forums; after adding my site an INFINITE amount of DNS records was detected by Cloudflare due to a wildcard.
(an example forum post: Bulk delete DNS record?)
So Cloudflare detected (a.domain, b.domain… zzzzzz.domain…) and they were all imported (well, at least truncated to a maximum of 200)
Manually deleting all of them is way too much work, so I created a little javascript to paste in my console which loops through all of them and deletes them. I’m sharing it here for others who face this problem.

Open op your JS console (F12) paste the code below and press enter, then just let it run for a while.

(() => {
    const deleteTopRecord = () => {
        setTimeout(() => {
            var tabs = document.querySelectorAll("[tabindex]");
            if (tabs.length) {
                var modal = tabs[tabs.length - 1];
                var btns = modal.querySelectorAll("button");
                if (btns.length) {
                    btns[btns.length - 1].click();
                setTimeout(deleteTopRecord, 500);
            } else {
                setTimeout(deleteTopRecord, 100);
        }, 300);

It will probably not work anymore once Cloudflare updates their website to another version and the HTML DOM will be reordered, but I hope that at some point they will add either a bulk delete or fix the wildcard import

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.