Skip to content

Commit

Permalink
custom latlong
Browse files Browse the repository at this point in the history
  • Loading branch information
garbados committed Jan 10, 2025
1 parent c907490 commit adba42e
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions src/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const HEADER = ['h1', TITLE]

const title = x => [
'section',
['hgroup', HEADER, x]
['hgroup', HEADER, ['p', x]]
]

const heading = x => [
Expand Down Expand Up @@ -57,42 +57,56 @@ class WitchClock extends HTMLElement {
}

loading () {
this.innerHTML = alchemize(title(['p', '... is loading!']))
}

async handlePermissionClick () {
this.loading()
const timeout = setTimeout(() => this.generalError({ message: 'Timeout' }), 10000)
try {
const { coords } = await getCurrentPosition()
this.beginTicking(coords)
} catch (e) {
this.userDeniedPermission(e)
}
clearTimeout(timeout)
this.innerHTML = alchemize(title('... is loading!'))
}

async askForPermission () {
this.innerHTML = alchemize([
...title(['p', '... needs your permission!']),
...title('... needs your permission!'),
GEOLOCATION_ASK.map(p),
['input#geo-permission', { type: 'button', value: 'OK!' }]
])
this.enterCustomLatlong()
const node = document.getElementById('geo-permission')
node.addEventListener('click', this.handlePermissionClick.bind(this))
node.addEventListener('click', async () => {
this.loading()
const timeout = setTimeout(() => this.generalError({ message: 'Timeout' }), 10000)
try {
const { coords } = await getCurrentPosition()
this.beginTicking(coords)
} catch (e) {
this.userDeniedPermission(e)
}
clearTimeout(timeout)
})
}

enterCustomLatlong () {
this.innerHTML += alchemize([
['p', 'Or, you can enter a custom latitude and longitude.'],
['input#geo-latitude', { type: 'number', value: 0 }],
['input#geo-longitude', { type: 'number', value: 0 }],
['input#geo-custom', { type: 'button', value: 'OK!' }]
])
const node = document.getElementById('geo-custom')
node.addEventListener('click', () => {
const latitude = document.getElementById('geo-latitude').value
const longitude = document.getElementById('geo-longitude').value
this.beginTicking({ latitude, longitude })
})
}

async userDeniedPermission (error) {
this.innerHTML = alchemize([
...title(['p', '... could not obtain your permission!']),
...title('... could not obtain your permission!'),
['p', error.message]
])
}

async generalError (error) {
console.trace(error)
this.innerHTML = alchemize([
...title(['p', '... encountered an unknown problem!']),
...title('... encountered an unknown problem!'),
['p', error.message]
])
}
Expand All @@ -101,18 +115,21 @@ class WitchClock extends HTMLElement {
if (this.task) clearInterval(this.task)
let date = new Date()
let witchy = await witchify(date, latitude, longitude)
let trying = false // CONCURRENCY
console.log(witchy) // i left this here for you freaky console fuckers
const refresh = async () => {
date = new Date()
if (comesafter(date, witchy.day.next)) {
if (comesafter(date, witchy.day.next) && !trying) {
trying = true
witchy = await witchify(date, latitude, longitude)
trying = false
} else {
witchy.time = timeinfo(date, witchy.day)
witchy.now = date
}
const holidays = explainHolidays(witchy)
this.innerHTML = alchemize([
...title(['p', 'A lunisolar calendar.']),
...title('A lunisolar calendar.'),
['ul',
['li', explainSeason(witchy)],
['li', explainPhase(witchy)],
Expand Down

0 comments on commit adba42e

Please sign in to comment.