forked from snailuncle/autojs-webview-communication
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
84 lines (69 loc) · 1.76 KB
/
index.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
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
"ui";
/**
* 作者: 家
* QQ: 203118908
* 功能: autojs和webview的交互
*/
importClass(android.webkit.WebChromeClient)
ui.layout(
<linear w="*" h="*">
<webview id="webview" h="*" w="*" />
</linear>
)
let webview = ui.webview
let set = webview.getSettings()
set.setAllowFileAccessFromFileURLs(false)
set.setAllowUniversalAccessFromFileURLs(false)
set.setSupportZoom(false)
set.setJavaScriptEnabled(true)
function 打开app (appName) {
app.launchApp(appName)
}
var 获取单选框选项 = function (selected) {
}
var webcc = new JavaAdapter(WebChromeClient, {
onConsoleMessage: function (consoleMessage) {
toastLog(consoleMessage.message())
try {
var obj = JSON.parse(consoleMessage.message())
if (obj.command === '打开app') {
app.launchApp(obj.param)
}
} catch (e) {
console.log('JSON解析consoleMessage错误')
}
},
onReceivedTitle: function (view, title) {
if (title != null) {
toastLog(title)
} else {
toastLog('title is null')
}
}
})
webview.setWebChromeClient(webcc)
htmlFilePath = "./webView.html"
htmlFilePath = files.path(htmlFilePath)
webview.loadUrl("file://" + htmlFilePath)
// autojs 改变网页
function 改变网页中的时间 () {
webview.evaluateJavascript(";" + getDate.toString() + ";getDate();", function (s) {
console.log(s)
})
}
function getDate () {
//获取当前时间
var date = new Date();
//格式化为本地时间格式
var date1 = date.toLocaleString();
//获取div
var div1 = document.getElementById("dateTime");
//将时间写入div
div1.innerHTML = date1;
return date1
}
setInterval(
function () {
改变网页中的时间()
}, 1000
)