-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
139 lines (128 loc) Β· 5.48 KB
/
index.html
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#246">
<title>Playground</title>
<style>
body {
margin: 1em;
font-size: 24px;
font-family: sans-serif;
background-color: #246;
color: #fff;
/*overscroll-behavior: none;*/
}
header {
float: right;
}
section, header div {
display: flex;
flex-direction: column;
}
button {
cursor: pointer;
background-color: white;
color: #246;
outline: none;
border: 1px solid currentColor;
border-radius: 2em;
font-size: 1em;
padding: .25em;
margin: 1em;
width: 12ch;
}
</style>
</head>
<body>
<header>
<div>
<svg viewBox="10 9 161 23" width="200" fill="#fff" id="logo">
<desc>Nemodata Logo</desc>
<path d="M15.3 31.7V19h.1l8.7 12.6h4.5V9.8h-5.3v12.6H23L14.5 10H10v21.8h5.3zm31.8 0v-4.3H37v-4.5h9.2v-4.3H37v-4.5h10V9.8H31.9v21.9H47zm8.4 0V18.2h.2l5.2 13.3h3.3l5.3-13.2h.1v13.4h5.2V9.8h-6.6l-5.5 13.6h-.3L57 9.8h-6.5v21.9h5.1zm32.7.3c5.9 0 10.5-4 10.5-11.2 0-7.3-4.6-11.3-10.5-11.3-5.8 0-10.4 4-10.4 11.3 0 7.1 4.6 11.2 10.4 11.2zm0-4.7c-3.1 0-5-2.3-5-6.5s1.9-6.6 5-6.6c3.2 0 5 2.3 5 6.6s-1.8 6.5-5 6.5zm19.5 4.4c6.6 0 10.3-4.1 10.3-11 0-6.8-3.7-10.9-10-10.9h-6.7v21.9h6.4zm-.1-1.8h-4.3V11.6h4.7c5.3 0 8 3.5 8 9.1 0 5.7-2.8 9.2-8.4 9.2zm14.2 1.8l2.4-6.6h9.1l2.4 6.6h2l-7.9-21.9h-2.1l-8 21.9h2.1zm10.9-8.4h-7.9l3.9-10.9h.1l3.9 10.9zm13.8 8.4v-20h7V9.7h-15.9v1.8h7v20h2zm8.9 0l2.3-6.6h9.2l2.3 6.6h2.1l-8-21.9h-2l-8 21.9h2zm10.8-8.4h-7.8l3.8-10.9h.2l3.8 10.9z"></path>
</svg>
</div>
</header>
<section>
<button id="share">Share</button>
<button id="vibrate">Vibrate</button>
<button id="battery">Battery</button>
</section>
<div id="orientation"></div>
<div id="status"></div>
<div id="connection"></div>
<div id="output"></div>
<script>
function log(message) {
console.log(message)
const p = document.createElement('p')
p.appendChild(document.createTextNode(message))
document.querySelector('#output').appendChild(p)
}
async function share() {
if (!navigator.share) {
log('π Error: navigator.share not supported')
return
}
try {
await navigator.share({title: 'Amnon\'s Playground', text: 'fiddling around with some web dev tech', url: 'https://targumon.github.io/playground/'})
log('π Shared!')
} catch (error) {
log('π© Error sharing: ' + error)
}
}
function vibrate() {
if (!navigator.vibrate) {
log('π Error: navigator.vibrate not supported')
return
}
navigator.vibrate([250, 250, 125, 125, 125, 125, 250, 250, 250, 600, 250, 250, 250])
log('π Vibrated?')
}
function updateOnlineStatus() {
const status = document.getElementById('status')
status.style.color = navigator.onLine ? '#7d7' : '#d55'
status.innerHTML = navigator.onLine ? 'Online' : 'Offline'
}
const conn = navigator.connection || navigator.mozConnection || navigator.webkitConnection
function updateConnectionStatus() {
document.getElementById('connection').innerHTML = 'Connection: ' + conn.type + ', category: ' + conn.effectiveType + ', max dl speed: ' + conn.downlinkMax
}
conn.addEventListener('change', updateConnectionStatus)
updateConnectionStatus()
function secondsToHuman(seconds) {
const h = Math.floor(seconds / 3600)
const m = Math.floor((seconds % 3600) / 60)
return (h ? h + 'h' : '') + m + 'm'
}
function battery() {
navigator.getBattery().then(function(batt) {
log('Battery at ' + batt.level * 100 + '% ' + (batt.charging ? ('π Charging (~' + secondsToHuman(batt.chargingTime) + ' to 100%)') : ('π Not charging (~' + secondsToHuman(batt.dischargingTime) + ' left)')))
})
}
function handleVisibilityChange() {
log(document.hidden ? ' π page is hidden' : ' π΅ page is visible')
}
function updateOrientation() {
document.getElementById('orientation').innerHTML = screen.orientation.type.includes('landscape') ? 'π₯ Landscape' : 'π¦ Portrait'
}
function handleDeviceOrientation (eventData) {
document.getElementById('logo').style.transform = 'rotate(' + eventData.gamma + 'deg) rotate3d(1,0,0, ' + (eventData.beta * -1) + 'deg)'
}
function onLoad() {
document.querySelector('#share').addEventListener('click', share)
document.querySelector('#vibrate').addEventListener('click', vibrate)
document.querySelector('#battery').addEventListener('click', battery)
document.addEventListener('visibilitychange', handleVisibilityChange)
window.addEventListener('online', updateOnlineStatus)
window.addEventListener('offline', updateOnlineStatus)
updateOnlineStatus()
window.addEventListener('deviceorientation', handleDeviceOrientation)
screen.orientation.addEventListener('change', updateOrientation)
updateOrientation()
}
window.addEventListener('load', onLoad)
</script>
</body>
</html>