diff --git a/src/routes/train/+page.svelte b/src/routes/train/+page.svelte index c338a6c..16eb73f 100644 --- a/src/routes/train/+page.svelte +++ b/src/routes/train/+page.svelte @@ -4,29 +4,45 @@ import { onMount } from 'svelte' - const title = "Timetable Results" + let title = "Timetable Results" + let id = "" + let data = []; async function getHeadcode() { return new URLSearchParams(window.location.search).get('headcode'); } onMount(async () => { - const headcode = await getHeadcode(); - document.getElementById('headcode').textContent = headcode; - const data = await fetch(`https://owlboard.info/api/v1/train/headcode/today/${headcode}`) - document.getElementById('data_raw').textContent = await data.text(); + id = await getHeadcode() || ""; + data = await fetchData(id); }) - - - - OwlBoard {title} - + async function fetchData(id = "") { + const date = 'now'; + const searchType = 'headcode' + const url = `https://owlboard.info/api/v2/timetable/train/${date}/${searchType}/${id}` + const res = await fetch(url); + return await res.json(); + } -
+ -

Headcode:

+ + OwlBoard {title} + -

+
-