-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings-APIs.html
367 lines (362 loc) · 12.3 KB
/
settings-APIs.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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" id="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<link rel="shortcut icon" href="images/Settings.png" type="image/x-icon">
<link rel="stylesheet" href="mdui-v1.0.1/css/mdui.min.css">
<script src="mdui-v1.0.1/js/mdui.min.js"></script>
<title>API 说明</title>
<style>
html {
transition-property: opacity, transform;
transition: .3s;
animation-name: slideIn;
animation-duration: .3s;
scroll-behavior: smooth;
}
@keyframes slideIn {
from {
transform: translateX(50%);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
</style>
</head>
<body class="mdui-theme-primary-blue-grey mdui-theme-accent-blue mdui-appbar-with-toolbar">
<div class="mdui-appbar mdui-appbar-fixed">
<div class="mdui-toolbar mdui-color-theme">
<a class="mdui-btn mdui-btn-icon mdui-ripple mdui-ripple-white" onclick="javascript:openPage('settings-devOptions.html');">
<i class="mdui-icon material-icons">arrow_back</i>
</a>
<a class="mdui-typo-title">API 说明</a>
</div>
</div>
<div class="mdui-typo mdui-center" style="padding: 16px;max-width: 640px;">
<h3>API 说明</h3>
<p>嵌入在 Webdroid 内的网页可调用以下 API。</p>
<blockquote>
Contents<br>
<a href="#postToast">发送 Toast</a><br>
<a href="#postNotification">发送通知</a><br>
<a href="#postScript">执行 JavaScript 脚本</a><br>
<a href="#jumpApp">应用跳转</a><br>
<a href="#addApp">添加应用</a><br>
<a href="#removeApp">移除应用</a>
</blockquote>
<h5 id="postToast">发送 Toast</h5>
<p>加入以下 JavaScript 脚本来使用:</p>
<pre>
//接入 API:发送 Toast
function postToast(message) {
var postData = {
"type": "toast",
"message": message
};
window.parent.postMessage(JSON.stringify(postData), "*");
}
</pre>
<p>参数:</p>
<div class="mdui-table-fluid">
<table class="mdui-table">
<thead>
<tr>
<th>参数名</th>
<th>类型</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>message</code></td>
<td><code>string</code></td>
<td>Toast 中的消息。</td>
</tr>
</tbody>
</table>
</div>
<br>
<h5 id="postNotification">发送通知</h5>
<p>加入以下 JavaScript 脚本来使用:</p>
<pre>
//接入 API:发送通知
function postNotification(icon, title, content, clickFunc) {
var clickFuncStr = clickFunc.toString();
var postData = {
"type": "notification",
"icon": icon,
"title": title,
"content": content,
"clickFunc": clickFuncStr
};
window.parent.postMessage(JSON.stringify(postData), "*");
}
</pre>
<p>参数:</p>
<div class="mdui-table-fluid">
<table class="mdui-table">
<thead>
<tr>
<th>参数名</th>
<th>类型</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>icon</code></td>
<td><code>string</code></td>
<td>通知图标,详见<a href="https://www.mdui.org/docs/material_icon">MDUI 开发文档</a>。</td>
</tr>
<tr>
<td><code>title</code></td>
<td><code>string</code></td>
<td>通知标题。</td>
</tr>
<tr>
<td><code>content</code></td>
<td><code>string</code></td>
<td>通知内容。</td>
</tr>
<tr>
<td><code>clickFunc</code></td>
<td><code>function</code></td>
<td>通知回调,当通知被点击时执行。</td>
</tr>
</tbody>
</table>
</div>
<br>
<h5 id="postScript">执行 JavaScript 脚本</h5>
<p>加入以下 JavaScript 脚本来使用:</p>
<pre>
//接入 API:执行 JavaScript 脚本
function postScript(script) {
var scriptStr = script.toString();
var postData = {
"type": "JavaScript",
"script": scriptStr
};
window.parent.postMessage(JSON.stringify(postData), "*");
}
</pre>
<p>参数:</p>
<div class="mdui-table-fluid">
<table class="mdui-table">
<thead>
<tr>
<th>参数名</th>
<th>类型</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>script</code></td>
<td><code>function</code></td>
<td>要执行的 JavaScript 脚本。</td>
</tr>
</tbody>
</table>
</div>
<br>
<h5 id="jumpApp">应用跳转</h5>
<p>加入以下 JavaScript 脚本来使用:</p>
<pre>
//接入 API:应用跳转
function jumpApp(url, color1, color2, textColor1, textColor2) {
var postData = {
"type": "jumpApp",
"url": url,
"color1": color1,
"color2": color2,
"textColor1": textColor1,
"textColor2": textColor2
};
window.parent.postMessage(JSON.stringify(postData), "*");
}
</pre>
<p>参数:</p>
<div class="mdui-table-fluid">
<table class="mdui-table">
<thead>
<tr>
<th>参数名</th>
<th>类型</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>url</code></td>
<td><code>string</code></td>
<td>应用 URL。</td>
</tr>
<tr>
<td><code>color1</code></td>
<td><code>string</code></td>
<td>应用状态栏背景色。</td>
</tr>
<tr>
<td><code>color2</code></td>
<td><code>string</code></td>
<td>应用导航栏背景色。</td>
</tr>
<tr>
<td><code>textColor1</code></td>
<td><code>string</code></td>
<td>应用状态栏文本色。</td>
</tr>
<tr>
<td><code>textColor2</code></td>
<td><code>string</code></td>
<td>应用导航栏文本色。</td>
</tr>
</tbody>
</table>
</div>
<br>
<h5 id="addApp">添加应用</h5>
<p>加入以下 JavaScript 脚本来使用:</p>
<pre>
//接入 API:添加应用
function addApp(icon, name, url, color1, color2, textColor1, textColor2) {
var postData = {
"type": "addApp",
"icon": icon,
"name": name,
"url": url,
"color1": color1,
"color2": color2,
"textColor1": textColor1,
"textColor2": textColor2
};
window.parent.postMessage(JSON.stringify(postData), "*");
}
</pre>
<p>参数:</p>
<div class="mdui-table-fluid">
<table class="mdui-table">
<thead>
<tr>
<th>参数名</th>
<th>类型</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>icon</code></td>
<td><code>string</code></td>
<td>应用图标 URL。</td>
</tr>
<tr>
<td><code>name</code></td>
<td><code>string</code></td>
<td>应用名称。</td>
</tr>
<tr>
<td><code>url</code></td>
<td><code>string</code></td>
<td>应用 URL。</td>
</tr>
<tr>
<td><code>color1</code></td>
<td><code>string</code></td>
<td>应用状态栏背景色。</td>
</tr>
<tr>
<td><code>color2</code></td>
<td><code>string</code></td>
<td>应用导航栏背景色。</td>
</tr>
<tr>
<td><code>textColor1</code></td>
<td><code>string</code></td>
<td>应用状态栏文本色。</td>
</tr>
<tr>
<td><code>textColor2</code></td>
<td><code>string</code></td>
<td>应用导航栏文本色。</td>
</tr>
</tbody>
</table>
</div>
<br>
<h5 id="removeApp">移除应用</h5>
<p>加入以下 JavaScript 脚本来使用:</p>
<pre>
//接入 API:移除应用
function removeApp(index) {
var postData = {
"type": "removeApp",
"index": index
};
window.parent.postMessage(JSON.stringify(postData), "*");
}
</pre>
<p>参数:</p>
<div class="mdui-table-fluid">
<table class="mdui-table">
<thead>
<tr>
<th>参数名</th>
<th>类型</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>index</code></td>
<td><code>number</code></td>
<td>要移除的应用序号。</td>
</tr>
</tbody>
</table>
</div>
</div>
<script>
//函数:页面跳转
function openPage(url) {
document.documentElement.style.transform = "translateX(-50%)";
document.documentElement.style.opacity = 0;
window.setTimeout(function() {
location.href = url;
}, 300);
}
//获取深色主题设置
if (localStorage.getItem("darkTheme") == "true") {
document.body.classList.add("mdui-theme-layout-dark");
postScript(function() {
gebi("statusBar").style.background = "#212121";
});
} else {
postScript(function() {
gebi("statusBar").style.background = "#455A64";
});
}
//接入 API:发送 Toast
function postToast(message) {
var postData = {
"type": "toast",
"message": message
};
window.parent.postMessage(JSON.stringify(postData), "/");
}
//接入 API:执行 JavaScript 脚本
function postScript(script) {
var scriptStr = script.toString();
var postData = {
"type": "JavaScript",
"script": scriptStr
};
window.parent.postMessage(JSON.stringify(postData), "/");
}
</script>
</body>
</html>