本帖最后由 whisky7 于 2020-12-3 23:39 编辑
Autojs小白不请自来,不习惯注释,请见谅!以下为淘宝欢乐造红包的脚本,需下载Autojs使用,源码借鉴了某大佬的随机睡眠函数和曲线滑动函数,其它均为原创,最好下载老版本的淘宝防止检测,新版本目前暂时也还未被检测到,代码如下:
更新:1.修正打卡失败问题;2.增加视频浏览睡眠时间,以避免网络或手机卡顿造成的浏览未完成问题。
[JavaScript] 纯文本查看 复制代码 auto.waitFor();
console.show();
var width=device.width;
var height=device.height;
var COIN=0;
var float=1.25;
setScreenMetrics(width,height);
function music(file_path){
media.playMusic(file_path);
sleep(media.getMusicDuration());
}
function random(min, max) {
return Math.round(Math.random() * (max - min)) + min;
}
function ramdomByFloat(number) {
return random(number, number * float);
}
function randomSleep(time) {
sleep(ramdomByFloat(time));
}
function accomplishment(){
var index=0;
var a=text("去完成").findOnce(index);
while(a){
if(a.parent().findOne(textContains("好友")))break;
if(a.parent().findOne(textContains("施肥")))index++;
if(a.parent().findOne(textContains("心愿")))index++;
else
{
var coinNum=a.parent().findOne(textMatches(/×\d+/));
coinNum=/\d+/.exec(coinNum.text())[0]-0;
a.click();
toastLog(/\d+:\d+:\d+/.exec(Date())[0]+' 正在完成...');
randomSleep(3000);
var secCount=0;
while(!textContains("完成").exists() && !descContains("完成").exists()){
if(secCount>20)break;
if(! textContains("主播").exists()){randomSwipe();randomSleep(500);}
else randomSleep(2500);
secCount++;
}
COIN+=coinNum;
toastLog(/\d+:\d+:\d+/.exec(Date())[0]+' 去完成任务成功!获得欢乐币:'+coinNum);
back();
textContains("累计任务奖励").waitFor();
randomSleep(2000);
}
a=text("去完成").findOnce(index);
}
}
/**
* 随机滑动
*/
function randomSwipe() {
smlMove(ramdomByFloat(width / 2), ramdomByFloat(height / 1.5), ramdomByFloat(width / 2), ramdomByFloat(height / 4), ramdomByFloat(800));
}
/**
* 范围随机数生成
* @param min
* @param max
*/
function random(min, max) {
return Math.round(Math.random() * (max - min)) + min;
}
/**
* 根据float生成随机数
* @param number
*/
function ramdomByFloat(number) {
return random(number, number * float);
}
/**
* 仿真随机带曲线滑动
* @param qx 起点x轴坐标
* @param qy 起点y轴坐标
* @param zx 终点x轴坐标
* @param zy 终点y轴坐标
* @param time 滑动时间,毫秒
*/
function smlMove(qx, qy, zx, zy, time) {
var xxy = [time];
var point = [];
var dx0 = {
"x": qx,
"y": qy
};
var dx1 = {
"x": random(qx - 100, qx + 100),
"y": random(qy, qy + 50)
};
var dx2 = {
"x": random(zx - 100, zx + 100),
"y": random(zy, zy + 50),
};
var dx3 = {
"x": zx,
"y": zy
};
for (var i = 0; i < 4; i++) {
eval("point.push(dx" + i + ")");
};
for (let i = 0; i < 1; i += 0.08) {
xxyy = [parseInt(bezierCurves(point, i).x), parseInt(bezierCurves(point, i).y)];
xxy.push(xxyy);
}
gesture.apply(null, xxy);
};
function bezierCurves(cp, t) {
cx = 3.0 * (cp[1].x - cp[0].x);
bx = 3.0 * (cp[2].x - cp[1].x) - cx;
ax = cp[3].x - cp[0].x - cx - bx;
cy = 3.0 * (cp[1].y - cp[0].y);
by = 3.0 * (cp[2].y - cp[1].y) - cy;
ay = cp[3].y - cp[0].y - cy - by;
tSquared = t * t;
tCubed = tSquared * t;
result = {
"x": 0,
"y": 0
};
result.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
result.y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
return result;
};
function doubleTwelve(){
COIN=0;
while(true){
try{
toastLog(/\d+:\d+:\d+/.exec(Date())[0]+' 请自行前往欢乐造红包任务中心并打开任务栏...');
text("累计任务奖励").waitFor();
toastLog(/\d+:\d+:\d+/.exec(Date())[0]+" 正在执行任务...");
var signUp=text('去打卡').findOne(2000);
if(signUp){
signUp.click();
toastLog(/\d+:\d+:\d+/.exec(Date())[0]+' 签到成功!');
}
accomplishment();
var bonus=text("立即领取").findOne(2000);
while(bonus){
bonus.click();
log(/\d+:\d+:\d+/.exec(Date())[0]+' 领取奖励成功!');
randomSleep(1000);
var bonus=text("立即领取").findOne(2000);
}
toastLog(/\d+:\d+:\d+/.exec(Date())[0]+' 欢乐造红包任务完成!获得总欢乐币:'+COIN);
break;
//music('/storage/emulated/0/脚本/success.wav');
}
catch(err){
log(err.message);
//music('/storage/emulated/0/脚本/failure.mp3')
}
}
}
doubleTwelve();
希望有什么问题可以提出来,我才能一边改进一边学习。 |