Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <script src="https://code.jquery.com/jquery-3.4.1.min.js" crossorigin="anonymous"></script>
- <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
- <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.js" integrity="sha256-9LeEGfQ5kyFt9Jn2EfwXqdBII40MS8iOC2YRF4T/T14=" crossorigin="anonymous"></script>
- <!-- <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDP4JXFaBcJFAq9hCJkCbBAKfmhYC3flX0" async defer></script> -->
- <link rel="stylesheet" href=styles.css>
- </head>
- <body>
- <div id="dom-target" style="display: none;">
- <?php
- $output = $_GET['station_code'];
- echo htmlspecialchars($output);
- ?>
- </div>
- <div id="dom-targetlat" style="display: none;">
- <?php
- $output = $_GET['lat'];
- echo htmlspecialchars($output);
- ?>
- </div>
- <div id="dom-targetlon" style="display: none;">
- <?php
- $output = $_GET['lon'];
- echo htmlspecialchars($output);
- ?>
- </div>
- <!-- Navbar Content -->
- <nav class="navbar navbar-expand-lg navbar-light bg-light" id="nav">
- <a class="navbar-brand" href="index.html">Untitled Train Tracker</a>
- <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
- <span class="navbar-toggler-icon"></span>
- </button>
- <div class="collapse navbar-collapse" id="navbarTogglerDemo02">
- <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
- <li class="nav-item">
- <a class="nav-link" href="#">About <span class="sr-only">(current)</span></a>
- </li>
- <li class="nav-item">
- <a class="nav-link" href="#">Acknowledgements</a>
- </li>
- </ul>
- </nav>
- <!-- -->
- <div class="alert alert-danger">
- <strong>COVID-19: DO NOT TRAVEL!</strong>
- </div>
- <div class="container-fluid">
- <div class="row row justify-content-around">
- <div class="menucontainer col-xs-12 col-md-5 col-lg-7">
- <h1 id="name"></h1>
- <h5><b><i>Departures</i></b></h5>
- <div class="table-responsive">
- <table class="table table-striped" id="datatable">
- <thead>
- <th>Operator</th>
- <th>Departure Time</th>
- <th>Destination</th>
- <th>Platform</th>
- <th>Status</th>
- <th></th>
- </thead>
- <tbody></tbody>
- </table>
- </div>
- <p id="info"></p>
- </div>
- <div class="menucontainer col-xs-12 col-md-5 col-lg-4">
- <h1>Station Information</h1>
- <h5><b><i>Location</i></b></h5>
- <div class="embed-responsive"id="map"></div><br/>
- <h5><b><i>Popularity</i></b></h5>
- </div>
- </div>
- </div>
- <script>
- var divlat = document.getElementById("dom-targetlat");
- var str = divlat.textContent;
- lat = str.replace(/\s/g, '');
- var divlon = document.getElementById("dom-targetlon");
- var str = divlon.textContent;
- lon = str.replace(/\s/g, '');
- var map;
- function initMap() {
- map = new google.maps.Map(document.getElementById('map'), {
- center: {lat: parseFloat(lat), lng: parseFloat(lon)},
- zoom: 12
- });
- var marker = new google.maps.Marker({
- // The below line is equivalent to writing:
- // position: new google.maps.LatLng(-34.397, 150.644)
- position: {lat: parseFloat(lat), lng: parseFloat(lon)},
- map: map
- });
- }
- </script>
- <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDP4JXFaBcJFAq9hCJkCbBAKfmhYC3flX0&callback=initMap"
- async defer></script>
- </script>
- <script>
- var div = document.getElementById("dom-target");
- var str = div.textContent;
- code = str.replace(/\s/g, '');
- var today = new Date();
- var ihours = today.getHours();
- if(ihours >= 0 && ihours<= 9) {
- var hours = "0" + ihours;
- }else {
- var hours = ihours;
- }
- var iminutes = today.getMinutes();
- if(iminutes >= 0 && iminutes<= 9) {
- var minutes = "0" + iminutes;
- }else {
- var minutes = iminutes;
- }
- // console.log(div, code, hours, minutes);
- // $.ajax({
- // type: 'POST',
- // url: "https://cors-anywhere.herokuapp.com/http://api.rtt.io/api/v1/",
- // data: {},
- // crossDomain: true,
- // beforeSend: function(xhr) {
- // xhr.setRequestHeader('Authorization', 'Basic ' + btoa(unescape(encodeURIComponent('rttapi_lukassio' + ':' + 'a404b35ede9c1e3bf4e4ab8533389923a0249a97'))))
- // }
- // });
- $(function(){
- $.ajax({
- // https://transportapi.com/v3/uk/train/station/dbc
- // url: "https://transportapi.com/v3/uk/train/station/" + code + "/timetable.json?app_id=5dcb6872&app_key=353fd663e7e4c4ee2a3eaf95fdc5cd7d&train_status=passenger",
- url: "https://cors-anywhere.herokuapp.com/http://api.rtt.io/api/v1/json/search/" + code,
- type: "get",
- dataType: "json",
- crossDomain: true,
- beforeSend: function(xhr) {
- xhr.setRequestHeader('Authorization', 'Basic ' + btoa(unescape(encodeURIComponent('rttapi_lukassio' + ':' + 'a404b35ede9c1e3bf4e4ab8533389923a0249a97'))))
- },
- success: function(data) {
- console.log(data);
- function isMobileDevice() {
- return (typeof window.orientation !== "undefined") || (navigator.userAgent.indexOf('IEMobile') !== -1);
- };
- console.log(isMobileDevice());
- function removeElement(elementId) {
- // Removes an element from the document
- var element = document.getElementById(elementId);
- element.parentNode.removeChild(element);
- }
- // if(isMobileDevice() == true) {
- // $("#datatable").empty();
- // console.log("pollen");
- // }
- for(var i=0; i<data.services.length; i++) {
- var row = $("<tr>");
- var departureTimeGbtt= data.services[i].locationDetail.gbttBookedDeparture;
- var departureTime = departureTimeGbtt.slice(0, 2) + ":" + departureTimeGbtt.slice(2);
- var destinationName= data.services[i].locationDetail.destination[0].description;
- var platformNumber = data.services[i].locationDetail.platform;
- var serviceStatus;
- // var moreurl = data.departures.all[i].service_timetable.id;
- var uid = data.services[i].serviceUid;
- var operator = data.services[i].atocName;
- var operator_code = data.services[i].atocCode;
- if(operator_code == "VT"){
- operator = "Avanti West Coast";
- }
- if (data.services[i].locationDetail.origin[0].description === data.location.name) {
- serviceStatus = "Starts Here";
- }
- if(serviceStatus == "LATE"){
- row.addClass("table-warning");
- serviceStatus = "Late";
- }
- if(serviceStatus == "CANCELLED") {
- row.addClass("table-danger");
- serviceStatus = "Cancelled";
- }
- if(serviceStatus == "EARLY") {
- row.addClass("table-success");
- serviceStatus = "Early";
- }
- if(serviceStatus == "ON TIME") {
- serviceStatus = "On Time";
- }
- if(serviceStatus == undefined) {
- serviceStatus = "Check More Info";
- }
- console.log(uid)
- if(isMobileDevice() == false) {
- if(platformNumber == null)
- {
- row.append("<td>" + operator + "</td>");
- row.append("<td>" + departureTime + "</td>");
- row.append("<td>" + destinationName + "</td>");
- row.append("<td>" + "n/a" + "</td>")
- row.append("<td>" + serviceStatus + "</td>");
- row.append("<td><a href='"+ "station.html?uid=" + uid + "'>More Info</a></td>");
- document.getElementById("info").innerHTML = "Platorm information is currently only available at larger stations"
- }
- else {
- row.append("<td>" + operator + "</td>");
- row.append("<td>" + departureTime + "</td>");
- row.append("<td>" + destinationName + "</td>");
- row.append("<td>" + platformNumber + "</td>");
- row.append("<td>" + serviceStatus + "</td>");
- row.append("<td><a href='"+ "station.html?uid=" + uid + "'>More Info</a>");
- }
- }else if (isMobileDevice() ==true) {
- if(platformNumber == null){
- row.append("<td>" + departureTime + " " + destinationName + "</td>")
- row.append("<td> P:N/A " + serviceStatus + " " + " <a href='"+ "station.html?uid=" + uid + "'>More Info</a></td>")
- }else{
- row.append("<td>" + departureTime + " " + destinationName + "</td>")
- row.append("<td> P:" + platformNumber + " " + serviceStatus + " <a href='"+ "station.html?uid=" + uid + "'>More Info</a></td>")
- }
- }
- $("#datatable tbody").append(row);
- }
- if (data.services === undefined || data.services.length == 0) {
- document.getElementById("info").innerHTML = "No Services Found! <br/> Due to the ongoing Coronavirus (COVID-19) Outbreak, many services are expected to be delayed, altered or revised. With Most Services ending earlier than usual. Check with your Operator for further information.";
- $("#datatable").remove();
- }
- document.getElementById("name").innerHTML = data.location.name
- document.title = data.location.name + " (" + data.station_code + ") Departures";
- },
- // error: function() {
- // window.location.href ="derailed.html";
- // }
- }
- );
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement