Files
Jump/jumpapp/assets/js/index.bundle.js
2022-04-20 10:21:47 +01:00

1 line
7.6 KiB
JavaScript

(()=>{"use strict";var t={729:t=>{var e=Object.prototype.hasOwnProperty,n="~";function s(){}function i(t,e,n){this.fn=t,this.context=e,this.once=n||!1}function r(t,e,s,r,o){if("function"!=typeof s)throw new TypeError("The listener must be a function");var h=new i(s,r||t,o),c=n?n+e:e;return t._events[c]?t._events[c].fn?t._events[c]=[t._events[c],h]:t._events[c].push(h):(t._events[c]=h,t._eventsCount++),t}function o(t,e){0==--t._eventsCount?t._events=new s:delete t._events[e]}function h(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),(new s).__proto__||(n=!1)),h.prototype.eventNames=function(){var t,s,i=[];if(0===this._eventsCount)return i;for(s in t=this._events)e.call(t,s)&&i.push(n?s.slice(1):s);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(t)):i},h.prototype.listeners=function(t){var e=n?n+t:t,s=this._events[e];if(!s)return[];if(s.fn)return[s.fn];for(var i=0,r=s.length,o=new Array(r);i<r;i++)o[i]=s[i].fn;return o},h.prototype.listenerCount=function(t){var e=n?n+t:t,s=this._events[e];return s?s.fn?1:s.length:0},h.prototype.emit=function(t,e,s,i,r,o){var h=n?n+t:t;if(!this._events[h])return!1;var c,a,l=this._events[h],u=arguments.length;if(l.fn){switch(l.once&&this.removeListener(t,l.fn,void 0,!0),u){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,e),!0;case 3:return l.fn.call(l.context,e,s),!0;case 4:return l.fn.call(l.context,e,s,i),!0;case 5:return l.fn.call(l.context,e,s,i,r),!0;case 6:return l.fn.call(l.context,e,s,i,r,o),!0}for(a=1,c=new Array(u-1);a<u;a++)c[a-1]=arguments[a];l.fn.apply(l.context,c)}else{var m,f=l.length;for(a=0;a<f;a++)switch(l[a].once&&this.removeListener(t,l[a].fn,void 0,!0),u){case 1:l[a].fn.call(l[a].context);break;case 2:l[a].fn.call(l[a].context,e);break;case 3:l[a].fn.call(l[a].context,e,s);break;case 4:l[a].fn.call(l[a].context,e,s,i);break;default:if(!c)for(m=1,c=new Array(u-1);m<u;m++)c[m-1]=arguments[m];l[a].fn.apply(l[a].context,c)}}return!0},h.prototype.on=function(t,e,n){return r(this,t,e,n,!1)},h.prototype.once=function(t,e,n){return r(this,t,e,n,!0)},h.prototype.removeListener=function(t,e,s,i){var r=n?n+t:t;if(!this._events[r])return this;if(!e)return o(this,r),this;var h=this._events[r];if(h.fn)h.fn!==e||i&&!h.once||s&&h.context!==s||o(this,r);else{for(var c=0,a=[],l=h.length;c<l;c++)(h[c].fn!==e||i&&!h[c].once||s&&h[c].context!==s)&&a.push(h[c]);a.length?this._events[r]=1===a.length?a[0]:a:o(this,r)}return this},h.prototype.removeAllListeners=function(t){var e;return t?(e=n?n+t:t,this._events[e]&&o(this,e)):(this._events=new s,this._eventsCount=0),this},h.prototype.off=h.prototype.removeListener,h.prototype.addListener=h.prototype.on,h.prefixed=n,h.EventEmitter=h,t.exports=h}},e={};function n(s){var i=e[s];if(void 0!==i)return i.exports;var r=e[s]={exports:{}};return t[s](r,r.exports,n),r.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var s in e)n.o(e,s)&&!n.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),(()=>{class t{constructor(t,e=!1){this.set_utc_shift(),this.contentintervalid=null,this.eventemitter=t,this.ampm=e}set_utc_shift(t=0){this.utcshift=t,this.shiftedtimestamp=(new Date).getTime()+this.utcshift,this.shifteddate=new Date(this.shiftedtimestamp)}get_formatted_time(){let t=this.shifteddate.getUTCHours();const e=String(this.shifteddate.getUTCMinutes()).padStart(2,"0");if(!this.ampm)return String(t).padStart(2,"0")+":"+e;const n=t<=12?"AM":"PM";return t=(t+11)%12+1,t+":"+e+"<span>"+n+"</span>"}get_hour(){return this.shifteddate.getUTCHours()}update_time(){this.set_utc_shift(this.utcshift),this.eventemitter.emit("clock-updated",{formatted_time:this.get_formatted_time(),hour:this.get_hour(),utcshift:this.utcshift})}run(t){this.contentintervalid&&clearInterval(this.contentintervalid),this.update_time(),this.contentintervalid=setInterval((()=>{this.update_time()}),t)}}var e=n(729),s=n.n(e);class i{constructor(t){this.hour=t,this.greetings={0:"morning",12:"afternoon",16:"evening",19:"night"}}get_greeting(){let t=Object.keys(this.greetings).reverse();for(let e of t)if(this.hour>=e)return this.greetings[e]}}class r{constructor(t){this.eventemitter=t}fetch_owm_data(t){let e="/api/weatherdata.php?token="+JUMP.token;t.length&&(e+="&lat="+t[0]+"&lon="+t[1]),fetch(e).then((t=>t.json())).then((t=>{if(t.error)console.error("JUMP ERROR: There was an issue with the OWM API... "+t.error);else if(401!==t.cod){var e="night";t.dt>t.sys.sunrise&&t.dt<t.sys.sunset&&(e="day"),this.eventemitter.emit("weather-loaded",{locationcode:t.id,locationname:t.name,temp:Math.ceil(t.main.temp)+"&deg;"+(JUMP.metrictemp?"C":"F"),description:t.weather[0].main,iconclass:"wi-owm-"+e+"-"+t.weather[0].id,timezoneshift:1e3*t.timezone})}else console.error("JUMP ERROR: The OWM API key is invalid, check config.php")}))}}(new class{constructor(){this.latlong=[],this.storage=window.localStorage,this.clockfrequency=1e4,this.weatherfrequency=3e5,this.timezoneshift=0,this.metrictemp=JUMP.metrictemp,this.greetingelm=document.querySelector(".greeting .chosen"),this.holderelm=document.querySelector(".time-weather"),this.tempelm=this.holderelm.querySelector(".weather-info .temp"),this.weatherdescelm=this.holderelm.querySelector(".weather-info .desc"),this.timeelm=this.holderelm.querySelector(".time"),this.weatherelm=this.holderelm.querySelector(".weather"),this.weathericonelm=this.holderelm.querySelector(".weather-icon"),this.clientlocationelm=document.querySelector(".useclientlocation"),this.showtagsbuttonelm=document.querySelector(".show-tags"),this.tagselectorelm=document.querySelector(".tags"),this.tagsselectorclosebuttonelm=document.querySelector(".tags .close"),(this.lastrequestedlocation=this.storage.getItem("lastrequestedlocation"))&&(this.latlong=JSON.parse(this.lastrequestedlocation)),this.eventemitter=new(s()),this.clock=new t(this.eventemitter,!!JUMP.ampmclock),this.weather=new r(this.eventemitter)}init(){this.add_event_listeners(),JUMP.owmapikey?(this.weather.fetch_owm_data(this.latlong),setInterval((()=>{this.weather.fetch_owm_data(this.latlong)}),this.weatherfrequency)):this.eventemitter.emit("show-content")}add_event_listeners(){this.eventemitter.on("weather-loaded",(t=>{this.timezoneshift=t.timezoneshift,this.weatherelm.href="https://openweathermap.org/city/"+t.locationcode,this.weathericonelm.classList.add(t.iconclass),this.clientlocationelm.innerHTML=t.locationname,this.tempelm.innerHTML=t.temp,this.weatherdescelm.innerHTML=t.description,this.clientlocationelm.classList.add("enable"),this.eventemitter.emit("show-content")})),this.eventemitter.on("clock-updated",(t=>{if(null!=this.timeelm&&(this.timeelm.innerHTML=t.formatted_time),null!=this.greetingelm){let e=new i(t.hour);this.greetingelm.innerHTML=e.get_greeting()}})),this.eventemitter.on("show-content",(()=>{this.set_clock(),this.show_content()})),this.clientlocationelm.addEventListener("click",(t=>{navigator.geolocation.getCurrentPosition((t=>{this.latlong=[t.coords.latitude,t.coords.longitude],this.storage.setItem("lastrequestedlocation",JSON.stringify(this.latlong)),this.weather.fetch_owm_data(this.latlong)}),(t=>{console.error(t.message)}),{enableHighAccuracy:!0})})),this.showtagsbuttonelm&&this.showtagsbuttonelm.addEventListener("click",(t=>{this.tagselectorelm.classList.add("enable"),t.preventDefault()})),this.tagsselectorclosebuttonelm&&this.tagsselectorclosebuttonelm.addEventListener("click",(t=>{this.tagselectorelm.classList.remove("enable")}))}show_content(){document.querySelectorAll(".hidden").forEach((function(t){t.classList.remove("hidden")}))}set_clock(){this.clock.set_utc_shift(this.timezoneshift),this.clock.run(this.clockfrequency)}}).init()})()})();