Created
August 4, 2024 16:27
-
-
Save dirad/56bff7b4d0b26991f9b43530f735ef66 to your computer and use it in GitHub Desktop.
Digital ocean billing receipts downloader
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
function waitForElementAndClick(parentElement) { | |
const observer = new MutationObserver((mutations) => { | |
mutations.forEach((mutation) => { | |
mutation.addedNodes.forEach((node) => { | |
if (node.nodeName === 'div') { | |
node.click(); | |
console.log(node); | |
observer.disconnect(); | |
} | |
}); | |
}); | |
}); | |
// console.log(parentElement); | |
let observi = parentElement.querySelector(' [role=menuitem]'); | |
observer.observe(parentElement, { childList: true }); | |
} | |
function processElements(elements, index = 0) { | |
if (index >= elements.length) return; | |
let dropdown = elements[index].querySelector("[role=button]") | |
dropdown.click(); | |
// waitForElementAndClick(elements[index]); | |
setTimeout(() => { | |
let inner_btn = elements[index].querySelector('[role=menuitem] div div'); | |
console.log(inner_btn); | |
inner_btn.click(); | |
}, 200); | |
setTimeout(() => { | |
// if (confirm('Continue to the next element?')) { | |
processElements(elements, index + 1); | |
// } else { | |
// console.log('Process stopped by user.'); | |
// } | |
}, 1000); | |
} | |
// Ususally the count starts with a recipt, then invoice, and repeats. | |
const elements = document.querySelectorAll('div[data-testid="billing-history-entry-row"]:nth-child(2n) '); | |
processElements(elements); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment