-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.min.js
1 lines (1 loc) · 2.24 KB
/
script.min.js
1
moment.relativeTimeThreshold("s",60),moment.relativeTimeThreshold("ss",2);var nexttask={title:"Day is over - go play! 🎉",start:moment(2400,"hhmm")};function updateClock(){var t=moment(),o=6*t.seconds(),i=6*t.minutes()+o/60,n=t.hours()%12/12*360+90+i/12;if($("#clock-hour").css("transform",`rotate(${n}deg)`),$("#clock-minute").css("transform",`rotate(${i}deg)`),$("#clock-second").css("transform",`rotate(${o}deg)`),$("#digital-hour").text(("0"+t.hours()).slice(-2)),$("#digital-minute").text(("0"+t.minutes()).slice(-2)),$("#digital-second").text(("0"+t.seconds()).slice(-2)),(0==t.seconds()||nexttask.start.diff(t)<6e4)&&$("#info").text("Starts in "+nexttask.start.toNow(!0)),t.isSameOrAfter(nexttask.start)){if("Notification"in window){n="Start "+nexttask.title;try{new Notification("What Work When",{body:n,icon:"apple-touch-icon.png"}),window.navigator.vibrate(500)}catch(t){alert(n)}}location.reload()}}function secUpdate(){updateClock(),setTimeout(secUpdate,1e3)}function requestPermission(){"Notification"in window?Notification.requestPermission().then(function(t){console.info("Local Notifications: "+t)}):console.warn("Local Notifications not supported!"),$("#activate-notifications").hide()}fetch("schedule.json",{priority:"high"}).then(t=>{if(t.ok)return t.json();throw new Error("HTTP error, status = "+t.status)}).then(a=>{var s=a.day.end,r="";$.each(a.tasks,function(t,o){if(!/\d{4}/.test(o.start))return console.error(`Task ${t} can only be 4 digits. "${o.start}" is not allowed`),!1;if(parseInt(o.start)<0||2400<parseInt(o.start))return console.error(`Task ${t} is not a valid 24 hour time. "${o.start}" is not allowed`),!1;var i=o.start,n=moment(i,"hhmm"),e=s,t=(a.tasks[t+1]&&(e=a.tasks[t+1].start),r=moment().isBetween(n,moment(e,"hhmm"))?"now":"now"==r?"soon":"later",$("#tasks li:first-child").clone());$(".name",t).text(o.title),$(".stime",t).text(i),$(".etime",t).text(e),"soon"===r&&((nexttask=o).start=n,t.append(`<span id="info">Starts in ${nexttask.start.fromNow(!0)}</span>`)),t.addClass(r).appendTo("#tasks ol")}),$("#instructions,#tasks li:first-child").remove(),secUpdate()}),requestPermission(),"?ref=webappmanifest"===window.location.search&&"Notification"in window&&$("#activate-notifications").show().on("click",function(){return requestPermission(),!1});