-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
110 lines (99 loc) · 3.46 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>肥豬電腦遙控器</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css"
/>
<link rel="stylesheet" href="style.css" />
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script>
<style>
* {
-moz-user-select: none;
-webkit-user-select: none;
}
body {
display: flex;
flex-direction: column;
align-items: center;
touch-action: manipulation;
}
h2 {
margin-top: 15px !important;
}
.main.ui {
width: 100% !important;
}
.main.ui > div {
display: flex;
margin-bottom: 5px;
}
button {
height: 35vh;
flex: 1;
margin: 0 0.15em !important;
}
i {
transform: scale(5);
}
</style>
</head>
<body>
<h2>肥豬電腦遙控器</h2>
<div class="main ui container">
<div>
<button id="left" class="ui icon button">
<i class="icon backward"></i>
</button>
<button id="space" class="ui icon button">
<i class="icon pause" style="display: none;"></i>
<i class="icon play"></i>
</button>
<button id="right" class="ui icon button">
<i class="icon forward"></i>
</button>
</div>
<div>
<button id="volume_down" class="ui icon button">
<i class="icon volume down"></i>
</button>
<button id="volume_up" class="ui icon button">
<i class="icon volume up"></i>
</button>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.5.5/rxjs.umd.js"></script>
<script>
const $space = $('#space')
const $left = $('#left')
const $right = $('#right')
const $volDown = $('#volume_down')
const $volUp = $('#volume_up')
const { fromEvent, timer } = rxjs
const { merge, takeUntil, switchMap } = rxjs.operators
const interval = 350
$space.click(() => {
axios.post('/api/space').catch((err) => alert(err))
$('#space > i').toggle()
})
$volDown.click(() => axios.post('/api/volume_down').catch((err) => alert(err)))
$volUp.click(() => axios.post('/api/volume_up').catch((err) => alert(err)))
const leftDown = fromEvent($left, 'mousedown').pipe(merge(fromEvent($left, 'touchstart')))
const leftUp = fromEvent($left, 'mouseup').pipe(merge(fromEvent($left, 'touchend')))
const rightDown = fromEvent($right, 'mousedown').pipe(merge(fromEvent($right, 'touchstart')))
const rightUp = fromEvent($right, 'mouseup').pipe(merge(fromEvent($right, 'touchend')))
rightDown
.pipe(switchMap(() => timer(0, interval).pipe(takeUntil(rightUp))))
.subscribe(() => axios.post('/api/right').catch((err) => alert(err)))
leftDown
.pipe(switchMap(() => timer(0, interval).pipe(takeUntil(leftUp))))
.subscribe(() => axios.post('/api/left').catch((err) => alert(err)))
</script>
</body>
</html>