-
Notifications
You must be signed in to change notification settings - Fork 0
/
wake_lock.html
53 lines (47 loc) · 1.11 KB
/
wake_lock.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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, user-scalable=no">
<meta name='mobile-web-app-capable' content='yes'>
<title>Wake Lock Test Page</title>
<style>
#log {
border: 1px solid black;
background: rgba(182, 182, 182, 0.5);
}
</style>
</head>
<script>
function log(str) {
document.getElementById('log').innerHTML += '<div>' + str + '</div>';
}
function isInScreenInterface(str) {
return (str in window.screen);
}
function isAPIPresent() {
return isInScreenInterface('keepAwake');
}
addEventListener('load', function() {
var hasAPI = isAPIPresent();
if (!hasAPI) {
log('Wake Lock API not found.');
return;
}
log('Wake Lock API found.');
});
</script>
<body>
<div>colinblundell.github.com</div>
<button type='button' onclick='block();'>Block sleep</button><br>
<button type='button' onclick='unblock();'>Unblock sleep</button><br>
<div id='log'></div>
<script>
function block() {
screen.keepAwake = true;
}
function unblock() {
screen.keepAwake = false;
}
</script>
</body>
</html>