Skip to content

Instantly share code, notes, and snippets.

@Invincibear
Last active July 2, 2024 18:11
Show Gist options
  • Select an option

  • Save Invincibear/14b0a282225d1b5f6adc301d18e0dc17 to your computer and use it in GitHub Desktop.

Select an option

Save Invincibear/14b0a282225d1b5f6adc301d18e0dc17 to your computer and use it in GitHub Desktop.
let foundAppointment = false
const parseCalendar = () => {
const calendarCells = document.querySelector('app-calendar').querySelectorAll('td')
calendarCells.forEach(cell => {
const hasBlankSpan = cell.querySelector('span.blank') !== null
const hasFullSpan = cell.querySelector('span.scheduleFull') !== null
const availablilityLink = cell.querySelector('a.dayDetails.available')
if (availablilityLink) {
const date = parseInt(availablilityLink.innerText, 10)
const dateWorksForUs = ![4, 5, 6, 7].includes(date) // We're unavailable on these dates
if (!foundAppointment && !hasBlankSpan && !hasFullSpan && dateWorksForUs) {
foundAppointment = true
alert(`Available appointment found on the ${availablilityLink.innerText} of this month`)
}
}
})
}
let refresher = () => {
let refreshIntervalInMinutes = 1
let monthChangeDelayInSeconds = 1
setTimeout(() => {
// Load the next month
setTimeout(() => {
document.querySelector('a.dhs-cal-pagination.right').click()
}, 1 * 1000)
// After $monthChangeDelayInSeconds to load data, return to previous month
setTimeout(() => {
document.querySelector('a.dhs-cal-pagination.left').click()
}, monthChangeDelayInSeconds * 1000)
// After 2 * $monthChangeDelayInSeconds, parse the month's calendar for for availablilities
setTimeout(() => {
parseCalendar()
}, monthChangeDelayInSeconds * 2 * 1000)
// If no desired availabilities were found, try again in $refreshIntervalInMinutes
if (!foundAppointment) refresher()
},
refreshIntervalInMinutes * 60 * 1000)
}
refresher()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment