Skip to content

Instantly share code, notes, and snippets.

@dirad
Created August 4, 2024 16:27
Show Gist options
  • Save dirad/56bff7b4d0b26991f9b43530f735ef66 to your computer and use it in GitHub Desktop.
Save dirad/56bff7b4d0b26991f9b43530f735ef66 to your computer and use it in GitHub Desktop.
Digital ocean billing receipts downloader
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