// ==UserScript== // @name:en Cloudflare DNS replacer // @name Cloudflare DNS replacer // @version 1 // @grant none // @description Can be used to batch replace IP adresses in the Cloudflare DNS panel. // @match https://dash.cloudflare.com/*/*/dns // @namespace https://greasyfork.org/users/218405 // @downloadURL none // ==/UserScript== // a function that loads jQuery and calls a callback function when jQuery has finished loading function addJQuery(callback) { var script = document.createElement("script"); script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"); script.addEventListener('load', function() { var script = document.createElement("script"); script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();"; document.body.appendChild(script); }, false); document.body.appendChild(script); } // the guts of this userscript function main() { async function delay(ms) { return new Promise((resolve, reject) => { setTimeout(resolve, ms); }); } jQ(function() { (async function() { while (jQ("[data-testid='dns-table-add-record-button']").length === 0) { console.log("Waiting for cloudflare DNS to load...") await delay(1000); } const $button = jQ(""); $button.click(async function() { const IPs = { search: prompt("Enter search IP"), replace: prompt("Enter replacement") } const nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set; let dnsRows = jQ("[data-testid='dns-table-row']").toArray(); for (let dnsRow of dnsRows) { const $dnsRow = jQ(dnsRow); $dnsRow.click(); await delay(1000); const $openRow = $dnsRow.next(); const $dnsInput = $openRow.find(`input[value='${IPs.search}']`) if ($dnsInput.length) { nativeInputValueSetter.call($dnsInput.get(0), IPs.replace); var ev = new Event('input', { bubbles: true }); $dnsInput.get(0).dispatchEvent(ev); await delay(1000); let saveButton = $openRow.find("[data-testid='dns-record-form-save-button']"); jQ(saveButton).click(); await delay(1000); } } }); jQ("[data-testid='dns-table-add-record-button']").parent().prepend($button); })(); }) } // load jQuery and execute the main function addJQuery(main);