Android autojs钉钉自动打卡脚本
导读
下载地址: autojs软件下载 自动打卡脚本 密码:FULI
源代码
const clickBtn = (btn, x, y) => {
click(btn.bounds().centerX() + (x || 0), btn.bounds().centerY() + (y || 0));
};
//有锁屏密码的设置用
// if (!device.isScreenOn()) {
// device.wakeUp();
// sleep(1000);
// swipe(device.width / 2, device.height * 0.95, device.width / 2, device.height * 0.2, 400);
// sleep(1000);
// var password = '123123'; //这里输入你手机的密码
// for (var i = 0; i < password.length; i++) {
// var p = text(password[i].toString()).findOne().bounds();
// click(p.centerX(), p.centerY());
// sleep(200);
// }
// sleep(1000);
// }
const waitForText = (txt, callback) => {
var param = false;
if (!txt) return param;
var count = 0;
var start = true;
var findText = (txt) => {
if (!txt) return false;
var classNames = ['android.view.View', 'android.widget.TextView'];
var currentName = classNames.find((el) => {
return className(el).text(txt).find().length > 0;
});
if (typeof txt == 'string') return currentName;
else {
if (currentName)
return txt.find((el) => {
return className(currentName).text(el).find().length > 0;
});
else return false;
}
};
while (start) {
if (findText(txt)) {
start = false;
param = true;
callback && callback(param);
} else {
if (count > 180) {
//长时间未找到退出程序
start = false;
callback && callback(param);
}
}
count++;
sleep(1000);
}
sleep(1000);
return param;
};
const lockInEndMessage = (message) => {
//这里可以做扩展,将打卡结果发送给自己
toast(message);
};
var error_count = 0;
const clockIn = () => {
var currentDate = new Date();
var hour = currentDate.getHours();
var minite = currentDate.getMinutes();
home();
sleep(1000);
app.launchPackage('com.alibaba.android.rimet');
sleep(1000);
waitForText('工作台');
sleep(1000);
var widget = className('android.widget.TextView').text('工作台').findOne();
clickBtn(widget, 0, -20);
waitForText('考勤打卡');
var widgetKQ = className('android.view.View').text('考勤打卡').findOne();
clickBtn(widgetKQ, 0, -50);
var lockBtnFn = (text) => {
sleep(2000);
var lockOutBtn = className('android.view.View').text(text).findOne();
clickBtn(lockOutBtn);
};
if (hour > 12) {
waitForText('下班打卡', (res) => {
if (!res) {
if (error_count >= 3) {
lockInEndMessage('下班打卡失败!');
exit();
}
error_count++;
back();
sleep(2000);
clockIn();
}
});
lockBtnFn('下班打卡');
} else {
waitForText('上班打卡', (res) => {
if (!res) {
if (error_count >= 3) {
lockInEndMessage('上班打卡失败!');
exit();
}
error_count++;
back();
sleep(2000);
clockIn();
}
});
lockBtnFn('上班打卡');
}
sleep(3000);
back();
sleep(1000);
home();
lockInEndMessage('打卡成功!,时间:' + hour + ':' + minite);
};
clockIn();复制代码