Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

处理了很多else, 非常不好看,能跑就行, #13

Open
Chankin026 opened this issue May 13, 2022 · 0 comments
Open

处理了很多else, 非常不好看,能跑就行, #13

Chankin026 opened this issue May 13, 2022 · 0 comments

Comments

@Chankin026
Copy link

Chankin026 commented May 13, 2022

处理了很多else, 非常不好看,能跑就行(不懂语法)
需要在购物车页面开启,可能会出现无法识别的情况( 最好配合上下滑动的功能可解决),

const musicNotify = () => {
	const m = '/storage/emulated/0/Download/SnapTube Audio/Like A Dino_(MP3_320K).mp3'
	media.playMusic(m);
	sleep(media.getMusicDuration());
}
const to_mall_cart = () => {
	shopping_cart_btn=id('img_shopping_cart').findOne()
	if(shopping_cart_btn){
		shopping_cart_btn.parent().click() //btn上一级控件可点击
		console.log('已进入购物车')
	}else{
		console.log('未找到购物车按钮,退出')
		exit;
	}
}

const pay = () =>{
	if(textStartsWith('确认并支付').exists()){
		console.log("确认并支付")
		text("确认并支付").findOne().parent().click()
		console.log("确认并支付结束")
		musicNotify()
		back();
	}
	if(textStartsWith('立即支付').exists()){
		console.log("确认并支付")
		textStartsWith('立即支付').findOne().parent().click()
		iKnowExist = textStartsWith('我知道了').exists()
		if(iKnowExist){
			textStartsWith('我知道了').findOne().parent().click()
			pay()
		}
		sorryexist = textStartsWith('抱歉').exists()
		if(sorryexist){
			console.log('抱歉')
			textStartsWith('抱歉').findOne().parent().click()
			if(textStartsWith('我知道了').exists()){
				textStartsWith('我知道了').findOne().parent().click()
			}
		}
		selectall = text('全选').exists()
		if(selectall){
			sleep(50)
			console.log("pay select all")
			submit_order(0)
		}else{
			console.log("pay notify")
			musicNotify()
		}
	}
}

const selectTime = (countT,status) =>{
	console.log("进入选择时间")
	//选择送达时间
	textStartsWith('送达时间').findOne().parent().click()
	var selectedTime=null;
	hourClock_unfilterd=textContains(':00').find()
	hourClock=hourClock_unfilterd.filter(item => item.clickable&&item.checkable&&enabled)
	if(hourClock.length>0){
		selectedTime=hourClock[hourClock.length-1]
	}else{
		quarClock_unfilterd=textContains(':15').find()
		quarClock=quarClock_unfilterd.filter(item => item.clickable&&item.checkable&&enabled)
		if(quarClock.length>0){
			selectedTime=quarClock[hourClock.length-1]
		}else{
			halfClock_unfilterd=textContains(':30').find()
			halfClock=halfClock_unfilterd.filter(item => item.clickable&&item.checkable&&enabled)
			if(halfClock.length>0){
				selectedTime=halfClock[hourClock.length-1]
			}else{
				clock_last_unfilterd=textContains(':45').find()
				clock_last=clock_last_unfilterd.filter(item => item.clickable&&item.checkable&&enabled)
				if(clock_last.length>0){
					selectedTime=clock_last[hourClock.length-1]
				}
			}
		}
	}
	if(selectedTime!=null){
		selectedTime.parent().click()
		sleep(50) 
		status=true
		pay()
	}else{
		countT=countT+1;
		if(countT>18000){
			console.log('抢菜选择时间失败')
			exit;
		}
		sleep(50)
		selectTime(countT,false)

	}
}




const submit_order = (count) => {
	console.show();
	console.log('抢菜第'+count+'次尝试')
	if(textStartsWith('立即支付').exists()){
		console.log("SUBMIT 确认并支付")
		textStartsWith('立即支付').findOne().parent().click()
	}
	//美团买菜 结算按钮无id
	submit_findone=textStartsWith('结算(').exists()

	console.log("开始:" +submit_findone)
	if((!submit_findone) && !text('放弃机会').exists()){
		if(textStartsWith('我知道了').exists()){
			console.log('配送运力已约满')
			sleep(100)
			t1 = textStartsWith('我知道了').exists();
			if(textStartsWith('我知道了')){
				console.log("t1")
				textStartsWith('我知道了').findOne().parent().click()
			}else{
				console.log("t1不存在")
			}
	
		}else if (textStartsWith('放弃机会').exists()){
			console.log('跳过加购')
			textStartsWith('放弃机会').findOne().parent().click()
			selectTime(0,false)
		}else{
			console.log('未找到结算按钮,退出')
		}
		
	}else{
		existFindOne = textStartsWith('结算(').findOne().parent()
		if(submit_findone && textStartsWith('结算(').exists()){
			console.log("结算存在")
			existFindOne.click() //结算按钮点击
		}else{
			console.log("结算按钮不存在, 进行继续")
		}
	}
	sleep(600)

	if(text('返回购物车').exists()){
		text('返回购物车').findOne().parent().click()
	}

	console.log('我知道开始' + count)
	iKnowExist = textStartsWith('我知道了').exists()
	console.log(iKnowExist)
	if(iKnowExist){
		console.log('配送运力已约满')
		textStartsWith('我知道了').findOne().parent().click()
	}else{
		if(textStartsWith('放弃机会').exists()){
			console.log('跳过加购')
			textStartsWith('放弃机会').findOne().parent().click()
		}
		if(textStartsWith('送达时间').exists()){
			console.log('送达时间')
			selectTime(0,false)
		}


	}
	console.log('我知道结束' + count)
	sleep(100)
	count=count+1;
	if(count>18000){
		console.log('抢菜失败')
		exit;
	}
	submit_order(count)
}



const start = () =>{
	console.show();
	console.log('开始抢菜')
    kill_app('美团买菜')
    console.log("关闭 美团买菜")
	const appName = "美团买菜";
	launchApp(appName);
	sleep(600);  
	auto.waitFor()
	//跳过开屏广告
	btn_skip=id('btn_skip').findOne()
	if(btn_skip){
		btn_skip.click()
		console.log('已跳过开屏广告')
	}
	console.log('开始抢菜')
	sleep(600);  
	//跳过后加载首页会有一段时间再加载出购物车


	to_mall_cart()
	sleep(3000) //等待购物车加载完成
	submit_order(0)
}



function kill_app(packageName) {
    var name = getPackageName(packageName);
	console.log(name);
    if (!name) {
        if (getAppName(packageName)) {
            name = packageName;
        } else {
            return false;
        }
    }
    app.openAppSetting(name);
    text(app.getAppName(name)).waitFor();
    let is_sure = textMatches(/(结束运行|.*orce.*)/).findOne();
    if (is_sure.enabled()) {
		if(textMatches(/(结束运行|.*orce.*)/).exists()){
			console.log(textMatches(/(结束运行|.*orce.*)/).find().length);
			console.log(textMatches(/(结束运行|.*orce.*)/).findOne());
		}else{
			console.log("不存在")
		}
		
		textMatches(/(结束运行|.*orce.*)/).findOne().click();
        buttons=textMatches(/(.*强.*|.*停.*|.*结.*|.*行.*|确定|是|OK)/).find()
        if(buttons.length>0){
            buttons[buttons.length-1].parent().click()
			console.log("buttons length  结束")
        }else{
			console.log("结束按钮不存在")
			if(id("button3")){
				id("button3").findOne().click();
				sleep(100)
				console.log("button3  结束")
			}
		}
        if(id("button1")){
			id("button1").findOne().click();
			console.log("button1  结束")
		}
		
        console.log(app.getAppName(name) + "应用已被关闭");
        sleep(700);
        back();
    } else {
        console.log(app.getAppName(name) + "可能不在后台运行");
        back();
    }
}

//start();
 submit_order();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant