Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
function solve() { let info=document.getElementById("info"); let nextStopId="depot"; let departBtn=document.getElementById("depart"); let arrivebtn=document.getElementById("arrive"); let curentStopName="Depot"; function fetchNext(nextStopId){ var requestOptions = { method: 'GET', redirect: 'follow' }; fetch(`http://localhost:3030/jsonstore/bus/schedule/${nextStopId}`, requestOptions) .then(response => response.text()) .then(r =>JSON.parse(r)) .then(r=>update(r)) .catch(error => kill()); } function depart() { fetchNext(nextStopId); departBtn.disabled=true; arrivebtn.disabled=false; } function arrive() { info.textContent=`Arriving at ${curentStopName}` departBtn.disabled=false; arrivebtn.disabled=true; } function update(obj){ info.textContent=`Next stop ${obj.name}`; curentStopName=obj.name; nextStopId=obj.next; } function kill(){ departBtn.disabled=true; arrivebtn.disabled=true; info.textContent="Error" } return { depart, arrive }; } let result = solve();
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)