Created
July 26, 2024 07:42
-
-
Save aonurdemir/fd852b6650924eb183e618241f20f427 to your computer and use it in GitHub Desktop.
Spark Master Refresher
This file contains 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
// Add the progress output div to the top of the body | |
const progressOutputDiv = document.createElement('div'); | |
progressOutputDiv.id = 'progress-output'; | |
document.body.insertBefore(progressOutputDiv, document.body.firstChild); | |
// Add CSS to position the output div to the right | |
const style = document.createElement('style'); | |
style.innerHTML = ` | |
#progress-output { | |
margin-left: auto; | |
width: 600px; | |
padding: 10px; | |
box-shadow: -2px 0 5px rgba(0,0,0,0.1); | |
} | |
`; | |
document.head.appendChild(style); | |
async function fetchAndParseHTML(url) { | |
try { | |
const response = await fetch(url); | |
const htmlText = await response.text(); | |
const parser = new DOMParser(); | |
const doc = parser.parseFromString(htmlText, 'text/html'); | |
return doc; | |
} catch (error) { | |
console.error('Error fetching and parsing HTML:', error); | |
} | |
} | |
function extractProgressValues(doc) { | |
const container = doc.querySelector('.aggregated-activeJobs.collapsible-table'); | |
if (container) { | |
const rows = container.querySelectorAll('.progress-cell .progress span'); | |
let output = ''; | |
rows.forEach((row, index) => { | |
let progressValue = row.textContent.trim(); | |
progressValue = progressValue.replace(/\n/g, '').trim(); | |
output += `Progress Value [${index}]: ${progressValue}<br>`; | |
}); | |
document.getElementById('progress-output').innerHTML = output; | |
} else { | |
document.getElementById('progress-output').innerHTML = 'DONE'; | |
} | |
} | |
async function fetchProgressValuesFromURL() { | |
const url = 'your_jobs_page_url_here'; // Use the provided URL | |
const doc = await fetchAndParseHTML(url); | |
if (doc) { | |
extractProgressValues(doc); | |
} | |
} | |
setInterval(fetchProgressValuesFromURL, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment