Created
September 22, 2025 12:02
-
-
Save rakeshtembhurne/201aec24f7a21ca1fc306dfb70471a46 to your computer and use it in GitHub Desktop.
Pinnacle Timesheet Auto Approval Script
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
| (async function automate() { | |
| let processed = 0; | |
| const maxTest = 10; | |
| while (true) { | |
| const buttons = document.querySelectorAll(".MuiTableCell-root.MuiTableCell-body.MuiTableCell-alignCenter.MuiTableCell-sizeMedium"); | |
| console.log(`Found ${buttons.length} buttons.`); | |
| if (buttons.length === 0) break; | |
| const button = buttons[0]; | |
| console.log('Button element:', button); | |
| console.log('Button innerHTML:', button.innerHTML); // Log structure inside the cell | |
| console.log('Button children:', Array.from(button.children).map(child => child.tagName + (child.className ? ' ' + child.className : ''))); // Log child tags and classes | |
| // Try clicking the td first | |
| button.click(); // Use native click() method | |
| console.log('Native click() on td dispatched.'); | |
| // If that fails, try clicking the first child if it's a button-like element | |
| const possibleButton = button.querySelector('button, .MuiButtonBase-root, [role="button"]') || button.firstElementChild; | |
| if (possibleButton && possibleButton !== button) { | |
| console.log('Found possible inner button:', possibleButton); | |
| possibleButton.click(); | |
| console.log('Clicked inner element.'); | |
| } | |
| let preWaitMenus = document.querySelectorAll('.MuiMenuItem-root'); | |
| console.log(`Menu items before wait: ${preWaitMenus.length}`); | |
| await new Promise(resolve => setTimeout(resolve, 3000)); | |
| const menuItems = document.querySelectorAll('.MuiMenuItem-root'); | |
| console.log(`Menu items after wait: ${menuItems.length}`); | |
| console.log('Menu items texts:', Array.from(menuItems).map(item => item.textContent.trim())); | |
| if (menuItems.length < 2) { | |
| console.log("Not enough menu items found, stopping."); | |
| alert('Debug: Menu still not open. Check console for button structure and manually inspect.'); | |
| break; | |
| } | |
| menuItems[1].click(); // Click the second option (Approve) | |
| await new Promise(resolve => setTimeout(resolve, 500)); // Wait for confirmation dialog to appear | |
| // Find and click the "Yes" button | |
| const yesButton = Array.from(document.querySelectorAll('button')).find(btn => btn.textContent.trim() === 'Yes'); | |
| if (yesButton) { | |
| console.log('Found Yes button, clicking it.'); | |
| yesButton.click(); | |
| } else { | |
| console.log('Yes button not found, stopping.'); | |
| break; | |
| } | |
| await new Promise(resolve => setTimeout(resolve, 2000)); // Wait for dialog to close and row to disappear | |
| processed++; | |
| if (processed >= maxTest) { | |
| console.log(`Test complete: processed ${processed} items.`); | |
| break; | |
| } | |
| console.log(`Processed ${processed}/${maxTest} items.`); | |
| } | |
| console.log("Automation done."); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment