基于Auto.js编写的自动健康打卡JavaScript脚本,我自己用了一年多了,挺方便,分享交流一下。
建议食用方式:建个快捷方式放桌面,点一下就打卡,算是方便点。
这个脚本基于UI控件,我在小米和华为手机上测试脚本都能使用,其他手机未测试
环境准备
1.auto.js软件
2.使用完美校园app打卡
/*
ui显示有延迟,所以使用ui相关点击的函数的时候,不同手机可以适当延长等待时间
*/
function init() {
"auto"
auto.waitFor() //启用无障碍服务,启用后脚本继续运行
if (!requestScreenCapture()) {
toast("请求截图权限失败,退出脚本")
exit()
}
console.setSize(100, 100)
console.setPosition(0, 900)
//console.show()
}
function startApp() {
var appName = "完美校园";
launchApp(appName);
//launch("com.newcapec.mobile.ncp")
}
function jumpAd() {
var ja = text("跳过").findOne(3000)
if (ja != null) {
console.log("找到启动广告")
click(ja.bounds().centerX(), ja.bounds().centerY())
}
}
function jumpRootTip() {
var jrt = text("完美校园安全检测结果").depth(6).findOne(2000)
if (jrt != null) {
console.log("找到root提示,并自动点击确定")
click("确定")
} else {
console.log("未找到安全提示,退出脚本")
}
}
function healthMark() {
var text1 = text("健康打卡").findOne(6000)
if (text1 == null) {
console.warn("未打开健康打卡页面,退出脚本")
exit()
}
click(text1.bounds().centerX(), text1.bounds().centerY())
var hw = text("今日体温(午间)---(早间提交温度时,午间温度请先填“0”)").depth(14).findOne(6000)
if (hw == null) {
console.warn("未找到午间文本,退出脚本")
exit()
}
var bd = hw.parent().parent().child(1).findOne(depth(15).className("android.widget.EditText")).setText("0")
var tj = text("提交信息").depth(13).findOne(3000)
if (tj == null) {
console.warn("未找到提交按钮,退出脚本")
exit()
}
tj.click()
var text2 = text("确认提交").depth(14).findOne(3000)
if (text2 == null) {
console.warn("未找到提交按钮2,退出脚本")
exit()
}
text2.click()
console.info("打卡成功")
toast("打卡成功")
sleep(500)
//console.hide()
}
function doMarks(child) {
jumpAd()
//jumpRootTip() //跳过root提示
toast("进入软件")
sleep(1000)//等待手机动画时间,增加时间可以增加脚本稳定性
healthMark()
}
var name = '__main__' //程序开始的地方
if (1) {
init()
startApp()
doMarks()
}
总结
代码算是简洁直观,就不多解释了,要是出现提示未找到健康打卡文本的情况,可以适当增加延时函数的延时时间。
|