1 line
4.6 KiB
JavaScript
1 line
4.6 KiB
JavaScript
"use strict";!function(){var e=0,t=0,o={gbp:0,usd:0},n={gbp:0,usd:0};MicroEvent.mixin(this);var r=this,s=function(e,t){return new Date(e.getTime()+24*t*60*60*1e3)},a=function(e,t){var o=void 0,n=void 0;return o=e.getTime(),n=t.getTime(),(n-o)/864e5},i=function(){navigator.geolocation.getCurrentPosition(l)};this.bind("displayWeather",function(e){$("#weather").html(e.currently.summary+" "+e.currently.temperature+"°c <em>"+e.daily.summary+"</em>")});var l=function(e){var t=e.coords.latitude,o=e.coords.longitude;$.ajax({type:"GET",url:"https://api.forecast.io/forecast/9ad2a41d420f3cf4960571bb886f710c/"+t.toString()+","+o.toString()+"?units=uk2",data:"",dataType:"jsonp",timeout:1e4,context:$("body"),contentType:"application/json",headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(e){r.trigger("displayWeather",e)},error:function(e,t){}})},c=function(r,s){var a=void 0,i=void 0,l=$("#btc");0!==e?(l.removeClass(),r>e?l.addClass("up"):r<e&&l.addClass("down")):(o.gbp=r,o.usd=s,n.gbp=r,n.usd=s),e=r,t=s,r<o.gbp&&(o.gbp=r),s<o.usd&&(o.usd=s),n.gbp<r&&(n.gbp=r),n.usd<s&&(n.usd=s),i=3.49524333*r,a="High: $"+parseFloat(n.usd.toFixed(2))+" / Low $"+parseFloat(o.usd.toFixed(2)),l.html("$"+parseFloat(s.toFixed(2))+" / £"+parseFloat(r.toFixed(2))+" (£"+parseFloat(i.toFixed(2))+")"),l.prop("title",a)};this.bind("updateFX",function(e){$("#fx").html("£1 = $"+parseFloat(e.gpbe.toFixed(2))+" = "+parseFloat(e.sekex.toFixed(2))+" SEK")});var d=function(){$.ajax({type:"GET",url:"/btc",data:"",dataType:"json",timeout:1e4,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(e){c(e.bpi.GBP.rate_float,e.bpi.USD.rate_float)},error:function(e,t){}})};this.bind("getBTC",function(){d()});var u=function(){$.ajax({type:"GET",url:"/fx",data:"",dataType:"json",timeout:1e4,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(e){var t=1/e.rates.GBP,o=t*e.rates.SEK,n={usd:1,gbp:e.rates.GBP,sek:e.rates.SEK,gpbe:t,sekex:o};r.trigger("updateFX",n)},error:function(e,t){}})};this.bind("getFX",function(){u()});var p=function(e,t){var o="/getnexttraintimes?from="+t+"&to="+e,n=t+e;$.ajax({type:"GET",url:o,data:"",dataType:"json",timeout:1e4,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(e){g(n,e)},error:function(e,t){}})},g=function(e,t){var o=$("#"+e),n=void 0,r=void 0;n="On Time"==t.eta?t.eta:t.sta,r="On Time"==t.eta?"delayed":"ontime",o.html(n),o.removeClass("delayed").removeClass("ontime").addClass(r)},T=function(e){var t=$("#trainResults"),o=new EJS({url:"/template/trains.ejs"}).render(e);t.empty(),t.append(o),t.toggle()},f=function(e,t){var o="/gettrains?from="+e+"&to="+t;$.ajax({type:"GET",url:o,data:"",dataType:"json",timeout:1e4,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(e){T(e)},error:function(e,t){}})},w=function(e){var t=$("#passwordOut"),o=new EJS({url:"/template/password.ejs"}).render(e);t.empty(),t.append(o),t.show()},h=function(e,t){$.ajax({type:"GET",url:"/generate",data:"",dataType:"json",timeout:1e4,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(e){w(e)},error:function(e,t){}})};!function(){var e=new Date,t=new Date,o=new Date,n=new Date;t.setFullYear(2013,9,24),s(t,1001),o.setFullYear(2017,6,5),n.setFullYear(2013,7,25),$("#one").hide(),$("#two").text("Ends: "+Math.ceil(a(e,o))+" days / "+Math.ceil(a(e,o)/7)+" weeks"),$("#three").hide()}(),i(),r.trigger("getBTC"),r.trigger("getFX"),p("dbe","glq"),p("glq","dbe"),_fastTimer=setInterval(function(){r.trigger("getBTC"),p("dbe","glq"),p("glq","dbe")},6e4),setInterval(function(){r.trigger("getFX"),i()},9e5),$("#dbeglq").on("click",function(){r.trigger("getTrains","dbe","glq")}),$("#glqdbe").on("click",function(){r.trigger("getTrains","glq","dbe")}),$("#newPassword").on("click",function(){h()}),this.bind("getTrains",function(e,t){f(e,t)}),document.title="Slack"}();var popitout=function(e){var t=window.open(e,"name","height=600,width=570");return window.focus&&t.focus(),!1},popitoutSmall=function(e){var t=window.open(e,"name","height=400,width=520");return window.focus&&t.focus(),!1}; |