Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 9.57 KB | None | 0 0
  1. <html>
  2. <head>
  3.     <meta charset="UTF-8">
  4.     <meta name="viewport" content="width=device-width, initial-scale=1">
  5.     <script src="https://code.jquery.com/jquery-3.4.1.min.js"  crossorigin="anonymous"></script>
  6.   <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
  7.     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
  8.     <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
  9.   <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.js" integrity="sha256-9LeEGfQ5kyFt9Jn2EfwXqdBII40MS8iOC2YRF4T/T14=" crossorigin="anonymous"></script>
  10.     <!-- <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDP4JXFaBcJFAq9hCJkCbBAKfmhYC3flX0" async defer></script> -->
  11.     <link rel="stylesheet" href=styles.css>
  12. </head>
  13. <body>
  14.     <div id="dom-target" style="display: none;">
  15.     <?php
  16.        $output = $_GET['station_code'];
  17.        echo htmlspecialchars($output);
  18.    ?>
  19. </div>
  20. <div id="dom-targetlat" style="display: none;">
  21.     <?php
  22.             $output = $_GET['lat'];
  23.             echo htmlspecialchars($output);
  24.     ?>
  25. </div>
  26. <div id="dom-targetlon" style="display: none;">
  27.     <?php
  28.             $output = $_GET['lon'];
  29.             echo htmlspecialchars($output);
  30.     ?>
  31. </div>
  32. <!-- Navbar Content -->
  33. <nav class="navbar navbar-expand-lg navbar-light bg-light" id="nav">
  34.   <a class="navbar-brand" href="index.html">Untitled Train Tracker</a>
  35.   <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
  36.     <span class="navbar-toggler-icon"></span>
  37.   </button>
  38.  
  39.   <div class="collapse navbar-collapse" id="navbarTogglerDemo02">
  40.     <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
  41.       <li class="nav-item">
  42.         <a class="nav-link" href="#">About <span class="sr-only">(current)</span></a>
  43.       </li>
  44.       <li class="nav-item">
  45.         <a class="nav-link" href="#">Acknowledgements</a>
  46.       </li>
  47.     </ul>
  48. </nav>
  49. <!-- -->
  50. <div class="alert alert-danger">
  51.     <strong>COVID-19: DO NOT TRAVEL!</strong>
  52. </div>
  53.     <div class="container-fluid">
  54. <div class="row row justify-content-around">
  55.     <div class="menucontainer col-xs-12 col-md-5 col-lg-7">
  56. <h1 id="name"></h1>
  57. <h5><b><i>Departures</i></b></h5>
  58. <div class="table-responsive">
  59. <table class="table table-striped" id="datatable">
  60.   <thead>
  61.         <th>Operator</th>
  62.     <th>Departure Time</th>
  63.     <th>Destination</th>
  64.         <th>Platform</th>
  65.         <th>Status</th>
  66.         <th></th>
  67.   </thead>
  68.   <tbody></tbody>
  69. </table>
  70. </div>
  71. <p id="info"></p>
  72. </div>
  73. <div class="menucontainer col-xs-12 col-md-5 col-lg-4">
  74.     <h1>Station Information</h1>
  75.     <h5><b><i>Location</i></b></h5>
  76. <div class="embed-responsive"id="map"></div><br/>
  77.  
  78. <h5><b><i>Popularity</i></b></h5>
  79. </div>
  80. </div>
  81. </div>
  82. <script>
  83.             var divlat = document.getElementById("dom-targetlat");
  84.             var str = divlat.textContent;
  85.             lat = str.replace(/\s/g, '');
  86.             var divlon = document.getElementById("dom-targetlon");
  87.             var str = divlon.textContent;
  88.             lon = str.replace(/\s/g, '');
  89.             var map;
  90.       function initMap() {
  91.         map = new google.maps.Map(document.getElementById('map'), {
  92.           center: {lat: parseFloat(lat), lng: parseFloat(lon)},
  93.           zoom: 12
  94.         });
  95.                 var marker = new google.maps.Marker({
  96.     // The below line is equivalent to writing:
  97.     // position: new google.maps.LatLng(-34.397, 150.644)
  98.     position: {lat: parseFloat(lat), lng: parseFloat(lon)},
  99.     map: map
  100. });
  101.       }
  102.     </script>
  103.     <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDP4JXFaBcJFAq9hCJkCbBAKfmhYC3flX0&callback=initMap"
  104.    async defer></script>
  105. </script>
  106.  
  107. <script>
  108. var div = document.getElementById("dom-target");
  109. var str = div.textContent;
  110. code = str.replace(/\s/g, '');
  111.  
  112. var today = new Date();
  113. var ihours = today.getHours();
  114. if(ihours >= 0 && ihours<= 9) {
  115.     var hours = "0" + ihours;
  116. }else {
  117.     var hours = ihours;
  118. }
  119. var iminutes = today.getMinutes();
  120. if(iminutes >= 0 && iminutes<= 9) {
  121.     var minutes = "0" + iminutes;
  122. }else {
  123.     var minutes = iminutes;
  124. }
  125.  
  126.  
  127. // console.log(div, code, hours, minutes);
  128. // $.ajax({
  129. //   type: 'POST',
  130. //   url: "https://cors-anywhere.herokuapp.com/http://api.rtt.io/api/v1/",
  131. //   data: {},
  132. //   crossDomain: true,
  133. //   beforeSend: function(xhr) {
  134. //     xhr.setRequestHeader('Authorization', 'Basic ' + btoa(unescape(encodeURIComponent('rttapi_lukassio' + ':' +  'a404b35ede9c1e3bf4e4ab8533389923a0249a97'))))
  135. //   }
  136. // });
  137.  
  138.   $(function(){
  139.     $.ajax({
  140.             // https://transportapi.com/v3/uk/train/station/dbc
  141.         // url: "https://transportapi.com/v3/uk/train/station/" + code + "/timetable.json?app_id=5dcb6872&app_key=353fd663e7e4c4ee2a3eaf95fdc5cd7d&train_status=passenger",
  142.         url: "https://cors-anywhere.herokuapp.com/http://api.rtt.io/api/v1/json/search/" + code,
  143.         type: "get",
  144.    dataType: "json",
  145.         crossDomain: true,
  146.         beforeSend: function(xhr) {
  147.             xhr.setRequestHeader('Authorization', 'Basic ' + btoa(unescape(encodeURIComponent('rttapi_lukassio' + ':' +  'a404b35ede9c1e3bf4e4ab8533389923a0249a97'))))
  148.     },
  149.    success: function(data) {
  150.        console.log(data);
  151.  
  152.                 function isMobileDevice() {
  153.             return (typeof window.orientation !== "undefined") || (navigator.userAgent.indexOf('IEMobile') !== -1);
  154.             };
  155.             console.log(isMobileDevice());
  156.  
  157.             function removeElement(elementId) {
  158.                 // Removes an element from the document
  159.                 var element = document.getElementById(elementId);
  160.                 element.parentNode.removeChild(element);
  161.             }
  162.             // if(isMobileDevice() == true) {
  163.             //  $("#datatable").empty();
  164.             //  console.log("pollen");
  165.             // }
  166.  
  167.       for(var i=0; i<data.services.length; i++) {
  168.  
  169.      var row = $("<tr>");
  170.  
  171.       var departureTimeGbtt= data.services[i].locationDetail.gbttBookedDeparture;
  172.             var departureTime = departureTimeGbtt.slice(0, 2) + ":" + departureTimeGbtt.slice(2);
  173.       var destinationName= data.services[i].locationDetail.destination[0].description;
  174.             var platformNumber = data.services[i].locationDetail.platform;
  175.             var serviceStatus;
  176.             // var moreurl = data.departures.all[i].service_timetable.id;
  177.             var uid = data.services[i].serviceUid;
  178.             var operator = data.services[i].atocName;
  179.             var operator_code = data.services[i].atocCode;
  180.  
  181.             if(operator_code == "VT"){
  182.             operator = "Avanti West Coast";
  183.             }
  184.  
  185.             if (data.services[i].locationDetail.origin[0].description === data.location.name) {
  186.                 serviceStatus = "Starts Here";
  187.             }
  188.             if(serviceStatus == "LATE"){
  189.                 row.addClass("table-warning");
  190.                 serviceStatus = "Late";
  191.             }
  192.             if(serviceStatus == "CANCELLED") {
  193.                 row.addClass("table-danger");
  194.                 serviceStatus = "Cancelled";
  195.             }
  196.             if(serviceStatus == "EARLY") {
  197.                 row.addClass("table-success");
  198.                 serviceStatus = "Early";
  199.             }
  200.             if(serviceStatus == "ON TIME") {
  201.                 serviceStatus = "On Time";
  202.             }
  203.             if(serviceStatus == undefined) {
  204.                 serviceStatus = "Check More Info";
  205.             }
  206.  
  207.             console.log(uid)
  208.  
  209.             if(isMobileDevice() == false) {
  210.  
  211.                 if(platformNumber == null)
  212.                 {
  213.                             row.append("<td>" + operator + "</td>");
  214.                             row.append("<td>" + departureTime + "</td>");
  215.                       row.append("<td>" + destinationName + "</td>");
  216.                           row.append("<td>" + "n/a" + "</td>")
  217.                             row.append("<td>" + serviceStatus + "</td>");
  218.                             row.append("<td><a href='"+ "station.html?uid=" + uid + "'>More Info</a></td>");
  219.                         document.getElementById("info").innerHTML = "Platorm information is currently only available at larger stations"
  220.                     }
  221.                             else {
  222.                                 row.append("<td>" + operator + "</td>");
  223.  
  224.                                 row.append("<td>" + departureTime + "</td>");
  225.                                 row.append("<td>" + destinationName + "</td>");
  226.                                         row.append("<td>" + platformNumber + "</td>");
  227.                                         row.append("<td>" + serviceStatus + "</td>");
  228.                                         row.append("<td><a href='"+ "station.html?uid=" + uid + "'>More Info</a>");
  229.  
  230.                                                                             }
  231.                                                                         }else if (isMobileDevice() ==true) {
  232.                                                                             if(platformNumber == null){
  233.                                                                             row.append("<td>" + departureTime + " " + destinationName + "</td>")
  234.                                                                             row.append("<td> P:N/A " + serviceStatus + "&emsp;" + " <a href='"+ "station.html?uid=" + uid + "'>More Info</a></td>")
  235.  
  236.                                                                         }else{
  237.                                                                             row.append("<td>" + departureTime + " " + destinationName + "</td>")
  238.                                                                             row.append("<td> P:" + platformNumber + " " + serviceStatus + " <a href='"+ "station.html?uid=" + uid + "'>More Info</a></td>")
  239.                                                                         }
  240.                                                                     }
  241.     $("#datatable tbody").append(row);
  242.       }
  243.  
  244.             if (data.services === undefined || data.services.length == 0) {
  245. 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.";
  246. $("#datatable").remove();
  247. }
  248. document.getElementById("name").innerHTML = data.location.name
  249. document.title = data.location.name + " (" + data.station_code + ") Departures";
  250.  
  251. },
  252. // error: function() {
  253. //  window.location.href ="derailed.html";
  254. // }
  255.         }
  256. );
  257.  
  258.   });
  259. </script>
  260. </body>
  261. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement