我直接贴代码:
var myApp ={};
myApp.runApps = [
{
"name":"快手极速版",
"packageName":"com.kuaishou.nebula"
}
]
myApp.appName = "快手极速版";
myApp.currentRunNum = 0;//当前运行数量
myApp.maxRunNum = 3;//运行次数
myApp.minRunTime = 15;//分钟
myApp.maxRunTime = 25;//最大运行时间
myApp.ocr={};
myApp.ocr.rwtb =null;
myApp.ocr.tx = null;
myApp.ocr.tq = null;
//快手极速版
var ksjsb = {};
ksjsb.homeActivity = "com.yxcorp.gifshow.HomeActivity";
ksjsb.packAgeName = "com.kuaishou.nebula";
ksjsb.startTime = 0;
//时间差 ,返回分钟
function timeDeffToSecond(start,end){
var c = end.getTime()-start.getTime();
return c/(60*1000);
}
//关闭app
function closeApp(packageName) {
var name = getPackageName(packageName);
if(!name){
if(getAppName(packageName)){
name = packageName;
}else{
return false;
}
}
app.openAppSetting(name);
text(app.getAppName(name)).waitFor();
let is_sure = textMatches(/(.*强.*|.*停.*|.*结.*|.*行.*)/).findOne();
if (is_sure.enabled()) {
textMatches(/(.*强.*|.*停.*|.*结.*|.*行.*)/).findOne().click();
textMatches(/(.*确.*|.*定.*)/).findOne().click();
log(app.getAppName(name) + "应用已被关闭");
sleep(1000);
back();
} else {
log(app.getAppName(name) + "应用不能被正常关闭或不在后台运行");
back();
}
}
//判断是否root
function whetherRoot() {
threads.start(function () {
log('判断是否root')
try {
click(2000, 2000)
是否root = false
log('未root')
} catch (error) {
是否root = true
log(error)
log('已root')
}
})
}
/**
* 点击
* @param {*} x
* @param {*} y
*/
function onClick(x, y) {
if (是否root == true) {
Tap(x, y)
} else {
click(x, y)
}
}
/**
* 控件查找并点击
* @param {控件查找类型} way
* @param {查找字符} str
* @param { 查找时间} sleepTime
*/
function clickNode(way, str, sleepTime) {
if (!sleepTime) {
sleepTime = 1000
}
let result = false //点击结果
let object;
if (way == "text") {
object = text(str).findOne(sleepTime);
} else if (way == "desc") {
object = desc(str).findOne(sleepTime);
} else if (way == "id") {
object = id(str).findOne(sleepTime);
} else if (way == "className") {
object = className(str).findOne(sleepTime);
} else {
log("Error:clickNode-way参数不正确")
}
if (object != null) {
if (object.clickable()) {
result = object.click();
result && sleep(sleepTime);
// if (result) {
// sleep(sleepTime);
// }
} else {
//log("Error:clickNode-组件不可点击")
let x = object.bounds().centerX();
let y = object.bounds().centerY();
log(str)
if (x > 0 && y > 0) {
result = click(parseInt(x), parseInt(y));
} else {
log("Error:clickNodeR-中心点坐标不在可视区")
}
result && sleep(sleepTime);
}
} else {
// log("Error:clickNode-组件不存在/没找到")
}
return result;
};
//签到
function qd(){
if(text("立即签到").exists()){
var b = text("立即签到").findOne().bounds();
if(b.centerX()>0&&b.centerY()>0){
onClick(b.centerX(),b.centerY());
sleep(random(3000,5000));
}
}
}
//打开任务页面
function openRW(){
log(currentActivity());
log("打开任务页面");
if(className("android.widget.ImageView").id("red_packet").exists()){
var b = className("android.widget.ImageView").id("red_packet").findOne().bounds();
if(b.centerX()>0&&b.centerY()>0){
log("点击成功1");
click(b.centerX(),b.centerY());
ui.run(function(){
toastLog("等待打开页面");
})
sleep(random(10000,15000) );
}
}else {
var img = captureScreen();
if(img){
if (myApp.ocr.rwtb==null){
myApp.ocr.rwtb = images.read("./res/ksjsb_rw1.png");
}
log("图片查找");
log( myApp.ocr.rwtb);
//截图并找图
p = findImage(img, myApp.ocr.rwtb);
log(p);
if(p){
log("点击成功");
click(p.x,p.y);
ui.run(function(){
toastLog("等待打开页面");
})
sleep(random(10000,15000) );
}else{
log("未找到开始生产按钮");
}
}else{
log("截图失败");
}
}
}
//提现
function openTX(){
// waitForActivity("com.yxcorp.gifshow.webview.KwaiWebViewActivit
var img = captureScreen();
images.save(img, "/sdcard/qt.png");
log(img);
if(img){
var p = findColor(img,"#ffea95",{ threshold: 0.8});
log(p);
log("查找提现");
if(p){
click(p.x,p.y)
console.log("打开提现页面");
sleep(random(10000,15000) );
}else{
if (myApp.ocr.tx==null){
myApp.ocr.tx = images.read("./res/ksjsb_jb.png");
}
//截图并找图
p = findImage(img, myApp.ocr.tx,{ threshold: 0.9});
log(p);
if(p){
click(p.x,p.y)
console.log("打开提现页面");
sleep(random(10000,15000) );
}else{
log("未找到开始生产按钮");
}
}
}else{
log("截图失败");
}
}
//提现申请
function txSQ(){
log("申请提取:"+text("预计10分钟内到账").exists());
log(text("提取").exists());
if(text("预计10分钟内到账").exists()){
var b = text("预计10分钟内到账").findOne().bounds();
log(b);
if(b.centerX()>0&&b.centerY()>0){
onClick(b.centerX(),b.centerY()-50);
return true;
}
}else{
var img = captureScreen();
images.save(img, "/sdcard/qt.png");
log(img);
if(img){
if (myApp.ocr.tq==null){
myApp.ocr.tq = images.read("./res/ksjsb_tq.png");
}
//截图并找图
p = findImage(img, myApp.ocr.tq,{ threshold: 0.9});
log(p);
if(p){
click(p.x,p.y)
console.log("打开提现页面");
return true;
}else{
log("未找到按钮");
}
}else{
log("截图失败");
}
}
return false;
}
//确认提现
function qrTX(){
if(text("立即提现").exists()){
var b = text("立即提现").findOne().bounds();
if(b.centerX()>0&&b.centerY()>0){
onClick(b.centerX(),b.centerY());
sleep(random(10000,15000));
log("頁面:"+id("pay_title_tv").exists());
log("頁面1:"+text("微信").exists());
if(txSQ){
sleep(random(10000,15000) );
return true;
}
}
}
return false;
}
//开始提现
function startTX(){
log("提现10:"+text("10元").exists());
if(text("10元").exists()){
var b = text("10元").findOne().bounds();
if(b.centerX()>0&&b.centerY()>0){
onClick(b.centerX(),b.centerY());
sleep(1000);
if(qrTX()){
back();
sleep(1000);
back();
sleep(1000);
back();
sleep(1000);
back();
sleep(1000);
return true;
}
}
}
log("提现3:"+text("3元").exists());
if(text("3元").exists()){
var b = text("3元").findOne().bounds();
if(b.centerX()>0&&b.centerY()>0){
onClick(b.centerX(),b.centerY());
sleep(1000);
if(qrTX()){
back();
sleep(1000);
back();
sleep(1000);
back();
sleep(1000);
back();
sleep(1000);
return true;
}
}
}
if(text("0.3元").exists()){
var b = text("0.3元").findOne().bounds();
if(b.centerX()>0&&b.centerY()>0){
onClick(b.centerX(),b.centerY());
sleep(1000);
if(qrTX()){
back();
sleep(1000);
back();
sleep(1000);
back();
sleep(1000);
back();
sleep(1000);
return true;
}
}
}
back();
sleep(1000);
back();
sleep(1000);
back();
sleep(1000);
back();
sleep(1000);
}
//提现
function onTX(){
log("我的收益:"+text("去提现").exists());
if(text("去提现").exists()){
var b = text("去提现").findOne().bounds();
log(b);
if(b.centerX()>0 && b.centerY()>0){
click(b.centerX(),b.centerY());
sleep(random(10000,15000) );
startTX();
}
}
}
//开始运行
myApp.start = function (runNum){
if(runNum>myApp.maxRunNum){
return;
}
//myApp.runApps = runApps;
sleep(3000);
ksjsb.startTime = new Date();
sleep(3000);
if(launchApp(myApp.appName)){
waitForActivity(ksjsb.homeActivity);
whetherRoot();
log("---->"+runNum);
log("height:"+device.height);
if(runNum==1){
sleep(random(5000, 10000));
openRW();
qd();
back();
sleep(1000);
back();
// openTX();
// onTX();
}
while(true){
sleep(random(8000, 16000));
swipe(random(300,400),device.height-random(200, 300),random(400, 700),random(100, 200),random(500,800));
log("-------->时间:"+timeDeffToSecond( ksjsb.startTime,new Date()))
if(timeDeffToSecond( ksjsb.startTime,new Date())>(random(myApp.minRunTime,myApp.maxRunTime))){
return;
}
}
// closeApp(myApp.appName);
}
}
module.exports = myApp;
感兴趣的一起交流,想要脚本的加我Q:1334254803;有什么好的项目也可以找我,代码仅供学习使用,任何犯罪行为自己负责;