-
Notifications
You must be signed in to change notification settings - Fork 0
/
webview_demo.js
57 lines (53 loc) · 1.59 KB
/
webview_demo.js
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
// webview_demo.js
// only run in `Scriptable` app
// ----- just open url by system browser
Safari.open("https://bing.com")
Safari.openInApp("https://bing.com", true)
// ----- webview render
let htmlStr = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ShowTime</title>
<style type="text/css">
body {
background-color: #f1f1f1;
}
p {
font-size: 14px;
font-family: "Heiti SC";
text-align: center;
}
</style>
</head>
<body>
<p>now time is: <span id="timeBox"></span></p>
<script type="text/javascript">
let timeBox = document.getElementById("timeBox");
function showTime() {
let date = new Date();
let year = date.getFullYear(),
month = date.getMonth() + 1,
day = date.getDate(),
hour = date.getHours(),
minute = date.getMinutes(),
second = date.getSeconds();
let timeStr = year + '-' + normalize(month) + '-' + normalize(day) + ' ' + normalize(hour) + ':' + normalize(minute) + ':' + normalize(second);
timeBox.innerHTML = timeStr;
}
function normalize(timeNumber) {
return timeNumber < 10 ? ("0" + timeNumber) : timeNumber;
}
setInterval(showTime, 1000);
</script>
</body>
</html>
`
WebView.loadHTML(htmlStr)
let jsStr = `Math.PI`
let webview = new WebView()
let pi = await webview.evaluateJavaScript(jsStr)
console.log("pi ≈ " + pi)