forked from go-rod/rod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assets.go
189 lines (175 loc) · 5.24 KB
/
assets.go
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Package assets is generated by "lib/assets/generate"
package assets
// MousePointer for rod
const MousePointer = `<?xml version="1.0" encoding="UTF-8"?>
<svg width="277px" height="401px" viewBox="0 0 277 401" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 52.6 (67491) - http://www.bohemiancoding.com/sketch -->
<title>mouse-pointer</title>
<desc>Created with Sketch.</desc>
<defs>
<polygon id="path-1" points="0 0 0 299 60 241 103 341 170 313 130 218 217 216"></polygon>
<filter x="-24.2%" y="-11.0%" width="148.4%" height="130.8%" filterUnits="objectBoundingBox" id="filter-2">
<feOffset dx="0" dy="15" in="SourceAlpha" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="15" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feColorMatrix values="0 0 0 0 0.138818027 0 0 0 0 0.138818027 0 0 0 0 0.138818027 0 0 0 0.502660779 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
</defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="mouse-pointer" transform="translate(30.000000, 15.000000)">
<g id="outside">
<use fill="black" fill-opacity="1" filter="url(#filter-2)" xlink:href="#path-1"></use>
<use fill="#FFFFFF" fill-rule="evenodd" xlink:href="#path-1"></use>
</g>
<polygon id="inside" fill="#000000" points="18 44 18 255 66 207 110 313 145 299 102 198 171 197"></polygon>
</g>
</g>
</svg>`
// Monitor for rod
const Monitor = `<html>
<head>
<title>Rod Monitor - Pages</title>
<style>
body {
margin: 0;
background: #2d2c2f;
color: white;
padding: 20px;
font-family: sans-serif;
}
a {
color: white;
padding: 1em;
margin: 0.5em 0;
font-size: 1em;
text-decoration: none;
display: block;
border-radius: 0.3em;
border: 1px solid transparent;
background: #212225;
}
a:visited {
color: #c3c3c3;
}
a:hover {
background: #25272d;
border-color: #8d8d96;
}
</style>
</head>
<body>
<h3>Choose a Page to Monitor</h3>
<div id="targets"></div>
<script>
async function update() {
const list = await (await fetch('/api/pages')).json()
let html = ''
list.forEach((el) => {
html += ` + "`" + `<a href='/page/${el.targetId}' title="${el.url}">${el.title}</a>` + "`" + `
})
window.targets.innerHTML = html
setTimeout(update, 1000)
}
update()
</script>
</body>
</html>
`
// MonitorPage for rod
const MonitorPage = `<html>
<head>
<style>
body {
margin: 0;
background: #2d2c2f;
color: #ffffff;
}
.navbar {
font-family: sans-serif;
border-bottom: 1px solid #1413158c;
display: flex;
flex-direction: row;
}
.error {
color: #ff3f3f;
background: #3e1f1f;
border-bottom: 1px solid #1413158c;
display: none;
padding: 10px;
margin: 0;
}
input {
background: transparent;
color: white;
border: none;
border: 1px solid #4f475a;
border-radius: 3px;
padding: 5px;
margin: 5px;
}
.title {
flex: 2;
}
.url {
flex: 5;
}
.rate {
flex: 1;
}
</style>
</head>
<body>
<div class="navbar">
<input
type="text"
class="title"
title="title of the remote page"
readonly
/>
<input type="text" class="url" title="url of the remote page" readonly />
<input
type="number"
class="rate"
value="0.5"
min="0"
step="0.1"
title="refresh rate (second)"
/>
</div>
<pre class="error"></pre>
<img class="screen" />
</body>
<script>
const id = location.pathname.split('/').slice(-1)[0]
const elImg = document.querySelector('.screen')
const elTitle = document.querySelector('.title')
const elUrl = document.querySelector('.url')
const elRate = document.querySelector('.rate')
const elErr = document.querySelector('.error')
document.title = ` + "`" + `Rod Monitor - ${id}` + "`" + `
async function update() {
const res = await fetch(` + "`" + `/api/page/${id}` + "`" + `)
const info = await res.json()
elTitle.value = info.title
elUrl.value = info.url
await new Promise((resolve, reject) => {
const now = new Date()
elImg.src = ` + "`" + `/screenshot/${id}?t=${now.getTime()}` + "`" + `
elImg.style.maxWidth = innerWidth + 'px'
elImg.onload = resolve
elImg.onerror = () => reject(new Error('error loading screenshots'))
})
}
async function mainLoop() {
try {
await update()
elErr.attributeStyleMap.delete('display')
} catch (err) {
elErr.style.display = 'block'
elErr.textContent = err + ''
}
setTimeout(mainLoop, parseFloat(elRate.value) * 1000)
}
mainLoop()
</script>
</html>
`