Skip to content

Commit

Permalink
20220604提交
Browse files Browse the repository at this point in the history
  • Loading branch information
czj2369 committed Jun 4, 2022
1 parent dca93a4 commit a4ede69
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 118 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

# 更新

2022年6月4日

1.[JD]更新一波,修复部分任务无法进行的问题,屏蔽任务“去玩下单返现金” “品牌墙”(太忙了,导致没时间更新),依旧存在部分BUG

2022年5月24日

1.[JD]一大晚上看到催更的了,第一版,将就用吧,JD改了很多东西,去年那版用不了了
Expand Down
264 changes: 146 additions & 118 deletions auto_20220618/jd/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,35 @@
* JD618
*
* Author: czj
* Date: 2022/05/24
* Versions: 1.0.0
* Date: 2022/06/04
* Versions: 1.1.0
* Github: https://github.com/czj2369/jd_tb_auto
*/
const sleepTime = 500;
const speed = 2;

// 点击之后返回的任务
const BACK_LIST = ['浏览并关注可得', '逛店可得', '成功浏览可得1000金币', '浏览可得2000', '浏览可得3000'];
const BACK_LIST = ['浏览并关注可得', '逛店可得', '成功浏览可得1000金币', '浏览可得2000', '浏览可得3000', '获得7000金币', '去组队可得6000'];
// 去完成按钮
const NEED_FININSH_TASK_LIST = [/去.+\)/, /领点点券.+\)/, /签到领.+\)/, /逛众筹.+\)/];
// 需要做的任务
const FINISHED_TASK = ['您所访问的页面不存在', '全部完成啦', /获得\w+金币/, '已浏览', '已达上限'];

// 判断停留时间
var JUDGE_TIME = 0;
// 当前浏览的按钮位置
var currentTask = 0;
// 操作记录数,每操作五次返回刷新界面一次
var operCount = 0;
// 定时器
var interval;

var taskCount = null;

init();

function init() {
start();

console.log("项目地址:https://github.com/czj2369/jd_tb_auto");
console.log("音量上键结束脚本运行")
// 子线程开启计时
threads.start(function () {
if (interval == null) {
Expand All @@ -47,6 +51,8 @@ function init() {
viewTask();

recoverApp();

refreshUI();
}


Expand All @@ -63,140 +69,146 @@ function start() {

// 进入活动中心 JD这里需要手动进入下活动中心,故没有写代码
function enterActivity() {

sleep(sleepTime * speed);
if (!textContains("做任务 赚金币").exists()) {
sleep(sleepTime * speed * 2);
var p = text("抽奖").findOne().parent().parent().parent().parent();

if (null != p.children()[5]) {
var bounds = p.children()[5].bounds();
if (click(bounds.centerX(), bounds.centerY())) {
sleep(sleepTime * speed);
console.log("进入活动界面");
}
}

}
}

/**
* 去浏览任务
*/
function viewTask() {
NEED_FININSH_TASK_LIST.forEach(item => {
var taskCount = textMatches(item).find();
for (var i = 0; i <= taskCount.length; i++) {
sleep(sleepTime * speed);
goTask(taskCount[i]);
if (taskCount == null || textContains("做任务 赚金币").exists()) {
taskCount = textMatches(item).find();
for (var i = 0; i < taskCount.length; i++) {
sleep(sleepTime * speed);
var par = taskCount[i];
if (par != null && par.parent() != null && par.parent().childCount() >= 3) {
par = par.parent();
// 获取去完成按钮
var button = par.children()[3];
if (par.children()[2] != null) {
sleep(sleepTime);
var buttonText = par.children()[2].text();
goTask(button, buttonText);
}

}
}
}
});
}

function goTask(parent) {
var par = parent;

// 找到去完成按钮
if (par != null && par.parent() != null && par.parent().childCount() >= 3) {
par = par.parent();
// 先判断需要执行几次这个任务
var finshAndCount = par.children()[1].text().split('(')[1].split(')')[0].split('/');
var execCount = finshAndCount[1];
var currentFininshNum = finshAndCount[0];
// 获取去完成按钮
var button = par.children()[3];
while (currentFininshNum < execCount && par.children()[2] != null) {
sleep(sleepTime);
var buttonText = par.children()[2].text();
button.click();
// 点击任务 重置计时
JUDGE_TIME = 0;
/**
* 执行任务
* @param {*} button 任务界面的完成按钮
* @param {*} par 完成按钮的父类控件
* @returns
*/
function goTask(button, buttonText) {
log("正在进行任务: " + buttonText);
while (true) {

log("正在进行任务: " + buttonText + ",目前进度(" + currentFininshNum + "/" + execCount + ")");
sleep(sleepTime * speed * 4);
while (true) {
if (buttonText.indexOf("参与下单返现金") >= 0 || buttonText.indexOf("浏览5个品牌墙") >= 0) {
break;
}
button.click();
JUDGE_TIME = 0;

sleep(sleepTime * speed * 4);
if (textContains("确认授权").exists() || textContains("会员卡详情").exists()) {
if (!textContains("做任务 赚金币").exists() && back()) {
sleep(sleepTime * speed);
break;
}
}

if (textContains("确认授权").exists() || buttonText.indexOf("成功入会") >= 0) {
while (!textContains("做任务 赚金币").exists() && back()) {
sleep(sleepTime * speed);
currentFininshNum = execCount;
}
break;
}

var isViewAndFollow = false;
for (i = 0; i < BACK_LIST.length; i++) {
if (buttonText.indexOf(BACK_LIST[i]) >= 0) {
isViewAndFollow = true;
break;
}
}
var isViewAndFollow = false;
for (i = 0; i < BACK_LIST.length; i++) {
if (buttonText.indexOf(BACK_LIST[i]) >= 0) {
isViewAndFollow = true;
break;
}
}

if (isViewAndFollow) {
while (!textContains("做任务 赚金币").exists() && back()) {
sleep(sleepTime * speed);
}
currentFininshNum++;
sleep(sleepTime * speed);
break;
}
if (isViewAndFollow) {
viewAndFollow();
break;
}

if (textContains("当前页点击浏览").exists() && textStartsWith("¥").find().length > 0) {
var product = textStartsWith("¥").find()[0].parent().parent().parent().childCount();
if (product >= 4) {
log("进入浏览任务")
for (var i = 0; i <= 3; i++) {
if (textStartsWith("¥").find()[i].parent().parent().children()[4].click()) {
sleep(sleepTime * speed);
log("加购并返回");
while (!textContains("当前页点击浏览").exists() && back()) {
sleep(sleepTime * speed * 2);
}
}
}
if (back()) {
sleep(sleepTime * speed);
currentFininshNum++;
break;
if (textContains("当前页点击浏览").exists() && textStartsWith("¥").find().length > 0) {
var product = textStartsWith("¥").find()[0].parent().parent().parent().childCount();
if (product >= 4) {
log("进入浏览任务")
for (var i = 0; i <= 3; i++) {
if (textStartsWith("¥").find()[i].parent().parent().children()[4].click()) {
sleep(sleepTime * speed);
log("加购并返回");
while (!textContains("当前页点击浏览").exists() && back()) {
sleep(sleepTime * speed * 2);
}
}
}
viewAndFollow();
break;
}
}

if (isFinshed(FINISHED_TASK)) {
while (!textContains("做任务 赚金币").exists() && back()) {
sleep(sleepTime * speed);
currentFininshNum = execCount;
}
break;
}
if (isFinshed(FINISHED_TASK)) {
viewAndFollow();
break;
}

if (buttonText.indexOf("去参与小程序") >= 0) {
while (!textContains("做任务 赚金币").exists() && back()) {
launchPackage("com.jingdong.app.mall")
sleep(sleepTime * speed);
currentFininshNum++;
break;
}
}
if (buttonText.indexOf("去参与小程序") >= 0) {
sleep(sleepTime * speed);
launchPackage("com.jingdong.app.mall")
sleep(sleepTime * speed);
break;
}

if (textContains("当前页浏览加购").exists() && textStartsWith("¥").find().length > 0) {
addMarketCar();
while (!textContains("做任务 赚金币").exists() && back()) {
sleep(sleepTime * speed);
currentFininshNum = execCount;
break;
}
}
if (textContains("当前页浏览加购").exists() && textStartsWith("¥").find().length > 0) {
addMarketCar();
viewAndFollow();
break;
}

if (textContains("品牌种草城").exists()) {
for (var j = 0; j < 4; j++) {
if (textContains("喜欢").exists() && textContains("喜欢").click()) {
while(!textContains("喜欢").click() && back()) {
sleep(sleepTime * speed);
}

}
if (textContains("品牌种草城").exists()) {
for (var j = 0; j < 4; j++) {
if (textContains("喜欢").exists() && textContains("喜欢").click()) {
sleep(sleepTime * speed);
while (!textContains("喜欢").click() && back()) {
sleep(sleepTime * speed);
}
currentFininshNum++;
break;
}

if (JUDGE_TIME > 30) {
currentFininshNum = execCount;
JUDGE_TIME = 0;
break;
}
}

break;
}
if (buttonText.indexOf("点击首页浮层") >= 0) {
break;
}
if (JUDGE_TIME > 30) {
break;
}

}

while (!textContains("做任务 赚金币").exists() && back()) {
sleep(sleepTime * speed);
}
log("任务结束: " + buttonText);
}

// 判断是不是完成任务
Expand Down Expand Up @@ -231,9 +243,10 @@ function addMarketCar() {

// 返回
function viewAndFollow() {
sleep(1000);
back();
sleep(1000);
if (back()) {
sleep(sleepTime * speed);
JUDGE_TIME = 0;
}
}

// 递归遍历控件是否包含忽略的关键词
Expand All @@ -250,7 +263,22 @@ function recursionControl(parentControl) {
return retFlag;
}

function addJudgeTime() {
/**
* 刷新活动界面
*/
function refreshUI() {
if (textContains("做任务 赚金币").findOne().parent().children()[1].click()) {
sleep(sleepTime * speed * 4);
var p = text("抽奖").findOne().parent().parent().parent().parent();

if (null != p.children()[5]) {
var bounds = p.children()[5].bounds();
click(bounds.centerX(), bounds.centerY());
sleep(sleepTime * speed);
console.log("刷新界面");
}

}

}

Expand All @@ -267,9 +295,9 @@ function recoverApp() {
}
/**
* JD618
*
*
* Author: czj
* Date: 2022/05/24
* Versions: 1.0.0
* Date: 2022/06/04
* Versions: 1.1.0
* Github: https://github.com/czj2369/jd_tb_auto
*/

0 comments on commit a4ede69

Please sign in to comment.