-
Notifications
You must be signed in to change notification settings - Fork 3
/
notify.htm
75 lines (63 loc) · 4.09 KB
/
notify.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!doctype html>
<html lang="en">
<head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="icon" type="image/png" href="favicon.png" /><title>MiBandNotify</title></head>
<body>
<header>
<h1>
<span class="h1-left">MiBand</span>
<a href="https://github.com/dj0001/miband3-selfie">
<span class="h1-right">Notify</span>
</a>
</h1>
<button id="scanBtn" class="btn-scan">Scan</button>
</header>
<main style="display: none;"><pre id="output"></pre></main>
<button id="shot">►</button>
<br><input type='time' value='00:15' id='cd'> hh:min <button id="pp">▷</button>
<br><progress value=0 id='pr'></progress><ol reversed></ol>
<script>
var but=document.querySelector('#shot')
but.onclick=function(){showNotification('mibandButtonPressed')}
if(navigator.serviceWorker) navigator.serviceWorker.register('sw_notify.js');
function showNotification(tx) {
if(typeof(Notification) != "undefined") Notification.requestPermission(function(result) {
if (result === 'granted') {
navigator.serviceWorker.ready.then(function(registration) {
registration.showNotification('Miband', {
body: tx, //+' Warnungen!'
icon: 'favicon.png', //icons/warn.png
vibrate: [200, 100, 200, 100, 200, 100, 200],
tag: 'vibration-sample'
});
});
}
});
}
if(typeof(Notification) != "undefined") Notification.requestPermission();
var ls=location.search.slice(1); var i=0, gl, glb, gll, r=4 //pomodori
pp.onclick=function(){ if(pp.textContent=='\u25B7') //countdown
{var tmp=cd.value.split(':');t1=Date.now()+1000*((tmp[2]||0)*1+tmp[1]*60+tmp[0]*3600); t0=Date.now(); if(isNaN(ls)) {t1=new Date();t1.setHours(tmp[0],tmp[1])} // alarmclock
if(!gl) {gl=t1-t0;localStorage.cd=cd.value}; if(cd.value=='00:00') localStorage.removeItem("cd")
t=setInterval(function(){
document.title=cd.value=new Date(ls&&!isNaN(ls)?Date.now()+t1-2*t0:t1-Date.now()).toJSON().slice(11,ls=='00'?21:19);
if(isNaN(ls)) if(cd.value=='01:00:00'||cd.value=='00:30:00') document.querySelector('#scanBtn').dispatchEvent(event) //smart alarm
if(cd.value=='00:00:00') {showNotification('timer'+(i%8+1)); audio.paused?audio.play():audio.pause();if(!ls){t1=Date.now()+(!((i+1)%(r*2-1))? gll||glb||gl : i%2?gl:glb||gl);t0=Date.now();i++};document.querySelector('.h1-right').dispatchEvent(event);wakeLockRequest.cancel()};
pr.value=(Date.now()-t0)/(t1-t0)
}, ls=='00'?100:1000);
pp.textContent='\u2759\u2759'}
else {clearInterval(t); pp.textContent='\u25B7'} }
if(!ls) cd.value=localStorage.cd||'00:15'
else if(ls.match(/^\d?\d%20\d?\d/)) {var tmp=ls.split('%20');ls='';cd.value='00:'+('0'+tmp[0]).slice(-2);glb=tmp[1]*60000;gll=tmp[2]*60000;r=tmp[3]||r} //?45 15 ,scheme in min
var audio=new Audio(); audio.src = isNaN(ls)? ls:'https://upload.wikimedia.org/wikipedia/commons/b/bc/Alarmclock-mechanical.ogg' //?...ogg alarmclock
if(ls=='00') cd.value='00:00' //?00 stopwatch
else if(ls&&!isNaN(ls)) {cd.value=new Date(Date.now()+ls*3600000).toJSON().slice(11,19);pp.click()} //?tz e.g.?-1 worldclock
pp.oncontextmenu=function(e){e.preventDefault();if(ls) document.querySelector('ol').insertAdjacentHTML('afterbegin', '<li>'+cd.value+'</li>'); else glb=new Date('1970-01-01T'+cd.value+':00.000Z').getTime()} //longtouch set break
var event=new Event('contextmenu'), p0 //smartalarm
var mutationObserver = new MutationObserver(function() {const tmp=output.textContent.match(/.*\n$/)[0]; if(tmp.match(/\d+;/)) {if(!p0) p0=tmp.split(';')[1]; else if(tmp.split(';')[1]>p0) document.querySelector('.h1-right').dispatchEvent(event)} });
mutationObserver.observe(output, {childList: true});
if(ls.match('Metronome')) {var bpm=100;audio.playbackRate=bpm/96;audio.loop=true} //?https://upload.wikimedia.org/wikipedia/commons/c/c6/Sound_Classic_Metronome_96.ogg
navigator.getWakeLock("system").then(function(wakeLock) { var request = wakeLock.createRequest(); console.log(wakeLock.active); }); //screen, flag
</script>
<script src="webapp.bundle.js"></script>
</body>
</html>