"ui";
var myApp ={};
myApp.isRun = false;
myApp.homeActivity = "io.dcloud.PandoraEntryActivity";
myApp.appName = "宇博聚流";
myApp.dyAppPackage = "com.ss.android.ugc.aweme";
myApp.wxHomeActivty = "com.tencent.mm.ui.LauncherUI";
myApp.startXXTime = 0;
myApp.endXXTime = 0;
myApp.taskMinTime = 2;//可接的最少結束任務分鐘
myApp.taskEarlyEnd = 2;//默認兩分鐘
myApp.dzX = device.width-50;
myApp.dzY = device.height/2-50;
myApp.xqTPX = 200;
myApp.xqTPY = 350;
//tabs 資料
var tabs_data = {
//tabs 背景
bg: "#ffffff",
selectColor: {
//當前頁面選中顏色
on: "#00ffff",
//當前頁面未選中顏色
off: "#999999"
},
//圖示大小
srcSize: 18,
//字體大小
textSize: 12,
//影片縮放比例 未加入影片效果
zoom: 1.2,
//是否顯示指示器小橫條
tabs_h: true,
//tabs 按鈕資料
data: [
["設定", "@drawable/ic_settings_black_48dp"],
["通用設定", "@drawable/ic_settings_black_48dp"],
["日志", "@drawable/ic_assignment_black_48dp"],
],
}
//tabs按鈕 布局視圖資訊
var tabs_view = []
//tabs按鈕 當前選中按鈕
var selectView = 0;
//自定義控制元件 tabs按鈕
var Tabs_btn_layout = function () {
//繼承ui.Widget
util.extend(Tabs_btn_layout, ui.Widget);
function Tabs_btn_layout() {
//呼叫父類建構式
ui.Widget.call(this);
//自定義屬性data ,定義控制元件的每個引數 傳入值為整數
this.defineAttr("data", (view, attr, value, defineSetter) => {
//獲取當前控制元件的引數值 tabs_data.data[value] 賦值到arr陣列
arr = tabs_data.data[value]
//設定 _text控制元件文本
view._text.setText(arr[0])
//設定 _src控制元件圖片
view._src.attr("src", arr[1])
//把當前控制元件資訊集合到tabs_view陣列里面
tabs_view[tabs_view.length] = view
//如果當前控制元件為初始值 則設定控制元件顏色為選中顏色 selectView==value==0
if (value == selectView) {
view._src.attr("tint", tabs_data.selectColor.on)
view._text.setTextColor(colors.parseColor(tabs_data.selectColor.on))
}
});
}
Tabs_btn_layout.prototype.render = function () {
return (
//1.0.0-1 修改 w="*" 引數 螢屏方向發生變化時 寬度自適配
<vertical id="_bg" w="*" bg="{{tabs_data.bg}}" padding="0 10" gravity="center" >
<img w="{{tabs_data.srcSize}}" h="{{tabs_data.srcSize}}" id="_src" tint="{{tabs_data.selectColor.off}}" />
<text w="auto" id="_text" textSize="{{tabs_data.textSize}}" textColor="{{tabs_data.selectColor.off}}" />
</vertical>
)
}
ui.registerWidget("tabs_btn-layout", Tabs_btn_layout);
return Tabs_btn_layout;
}()
//自定義控制元件 tabs
var Tabs_layout = function () {
util.extend(Tabs_layout, ui.Widget);
function Tabs_layout() {
ui.Widget.call(this);
this.defineAttr("data", (view, attr, value, defineSetter) => {
//遍歷 tabs_data.data陣列
for (var i = 0; i < tabs_data.data.length; i++) {
time = i
//1.0.0-1 增加 layout_weight="1"引數 螢屏方向發生變化時 寬度自適配
ui.inflate(<tabs_btn-layout data="{{time}}" layout_weight="1" />, view._tabs, true)
}
//根據tabs_h值設定 _color顏色
tabs_data.tabs_h ? _color = tabs_data.selectColor.on : _color = "#00000000";
view.tabs.selectedTabIndicatorColor = colors.parseColor(_color);//設定tabs指示器顏色
});
}
Tabs_layout.prototype.render = function () {
return (
<card w="*" h="auto" cardElevation="5" foreground="?selectableItemBackground">
<horizontal id="_tabs" />
<tabs id="tabs" />
</card>
)
}
ui.registerWidget("tabs-layout", Tabs_layout);
return Tabs_layout;
}()
ui.layout(
<frame>
<vertical>
<appbar w="*" h="auto">
<toolbar id="toolbar" title="{{tabs_data.data[0][0]}}" />
</appbar>
<viewpager w="*" id="viewpager" layout_alignParentBottom="true" >
<frame >
<vertical>
<Switch id="rootSwith" text="無障礙服務:" checked="{{auto.service != null}}" w="auto" textStyle="bold" />
<horizontal> <text text="休息時間:"/> <input id="startXXTime" text="{{myApp.startXXTime}}"/><text text="~"/> <input id="endXXTime" text="{{myApp.endXXTime}}"/><text text="(設定0~0表示不休息)"/> </horizontal>
<horizontal> <text text="可接的最少(幾分鐘)結束任務時間:"/> <input id="taskMinTime" text="{{myApp.taskMinTime}}"/><text text="(結束任務時間太小有可能沒完成任務就結束了)"/> </horizontal>
<horizontal> <text text="任務提前幾分鐘結束"/> <input id="taskEarlyEnd" text="{{myApp.taskEarlyEnd}}"/><text text="(必須小于接收任務時間)"/> </horizontal>
<horizontal> <text text="任務點贊位置:"/> <input id="dzX" text="{{myApp.dzX}}"/><text text=","/> <input id="dzY" text="{{myApp.dzY}}"/><text text="(默認不行自己設定)"/> </horizontal>
<horizontal> <text text="選取圖片位置:"/> <input id="xqTPX" text="{{myApp.xqTPX}}"/><text text=","/> <input id="xqTPY" text="{{myApp.xqTPY}}"/><text text="(微信打開相冊第一張圖片的位置)"/> </horizontal>
<button id="startRun" text="啟動" />
<text text="QQ群: 856728443 " />
<text text="本程式僅供參考學使用,如若非法使用概不負責"/>
</vertical>
</frame>
<frame >
<vertical>
</vertical>
</frame>
<frame>
<vertical>
<text text="日志" />
<com.stardust.autojs.core.console.ConsoleView id="console" layout_weight="1" />
<text h="50px" w="*" />
</vertical>
</frame>
</viewpager>.
</vertical>
<tabs-layout data="" layout_gravity="bottom" />
</frame>
)
ui.tabs.setupWithViewPager(ui.viewpager);//系結ViewPager到指示器
//頁面更改偵聽器
ui.viewpager.setOnPageChangeListener({
//已選定頁面發生改變時觸發
onPageSelected: function (index) {
// log("上次選中" + tabs_view[selectView]._text.text())
//設定selectView上次頁面 圖案和字體顏色為未選中顏色 tabs_data.selectColor.off
tabs_view[selectView]._src.attr("tint", tabs_data.selectColor.off)
tabs_view[selectView]._text.setTextColor(colors.parseColor(tabs_data.selectColor.off))
//設定當前頁面 圖案和字體顏色為選中顏色 tabs_data.selectColor.on
tabs_view[index]._src.attr("tint", tabs_data.selectColor.on)
tabs_view[index]._text.setTextColor(colors.parseColor(tabs_data.selectColor.on))
//更改標題 title 內容
ui.toolbar.setTitle(tabs_view[index]._text.text())
//設定當前頁面為 index
selectView = index
}
})
ui.console.setConsole(runtime.console);
// 設定控制臺字體顏色
let c = new android.util.SparseArray();
let Log = android.util.Log;
c.put(Log.VERBOSE, new java.lang.Integer(colors.parseColor("#dfc0c0c0")));
c.put(Log.DEBUG, new java.lang.Integer(colors.parseColor("#cc000000")));
c.put(Log.INFO, new java.lang.Integer(colors.parseColor("#ff64dd17")));
c.put(Log.WARN, new java.lang.Integer(colors.parseColor("#ff2962ff")));
c.put(Log.ERROR, new java.lang.Integer(colors.parseColor("#ffd50000")));
c.put(Log.ASSERT, new java.lang.Integer(colors.parseColor("#ffff534e")));
ui.console.setColors(c);
/* 禁止回傳鍵退出腳本 */
ui.emitter.on('back_pressed', function (event) {
event.consumed = true;
});
//無障礙監聽
ui.rootSwith.on("check", function (checked) {
// 用戶勾選無障礙服務的選項時,跳轉到頁面讓用戶去開啟
if (checked && auto.service == null) {
app.startActivity({
action: "android.settings.ACCESSIBILITY_SETTINGS"
});
}
if (!checked && auto.service != null) {
auto.service.disableSelf();
}
})
// 當用戶回到本界面時,resume事件會被觸發
ui.emitter.on("resume", function () {
// 此時根據無障礙服務的開啟情況,同步開關的狀態
ui.rootSwith.checked = auto.service != null;
});
threads.start(function(){
//請求截圖
if (!requestScreenCapture()) {
ui.run(function(){
toastLog("請求截圖失敗!");
})
exit();
}
// 屏蔽音量鍵調節聲音
events.setKeyInterceptionEnabled("volume_up", true);
//啟用按鍵監聽
events.observeKey();
//監聽音量鍵按下
events.onKeyDown("volume_up", () => {
log('按音量鍵停止');
toastLog("停止腳本");
myApp.isRuning = false;
mainThreads.interrupt();
// exit(); //停止、退出腳本
});
})
var mainThreads = null;
ui.startRun.on("click",function(){
// myApp.minHBTime = ui.minHBTime.getText();
//myApp.maxHBTime = ui.maxHBTime.getText();
threads.start(function(){
let fy= floaty.rawWindow(<vertical alpha="0.6">
<card w="*" h="32" bg="#333333" gravity="center_vertical"><vertical h="auto" padding="15 0 10 0">
<text id="qNum" text="搶 0 次" textColor="#FFFFFF"/>
</vertical>
<View bg="#F44336" w="5" h="*"/></card>
<card w="*" h="32" bg="#333333" gravity="center_vertical">
<vertical h="auto" padding="15 0 10 0">
<text id="qCNum" text="成 0 次" textColor="#FFFFFF"/>
</vertical>
<View bg="#4CAF50" w="5" h="*"/></card>
<card w="*" h="32" bg="#00aa00" gravity="center_vertical"><vertical h="auto" padding="15 0 10 0">
<text id="hq" text="獲取" textColor="#FFFFFF" />
</vertical>
<View bg="#F44336" w="5" h="*"/></card>
</vertical>);
fy.setPosition(0,700);
setInterval(()=>{}, 1000);
fy.hq.click(()=>{
myApp.isRun = !myApp.isRun;
myApp.startXXTime = parseInt( ui.startXXTime.getText());
myApp.endXXTime = parseInt(ui.endXXTime.getText());
myApp.taskEarlyEnd = parseInt(ui.taskEarlyEnd.getText());
myApp.taskMinTime = parseInt(ui.taskMinTime.getText());
myApp.dzX = parseInt(ui.dzX.getText());
myApp.dzY = parseInt(ui.dzY.getText());
if(myApp.isRun){
fy.hq.setText("暫停");
ui.run(function(){
toastLog("開始執行腳本");
})
mainThreads = threads.start(function(){
start(fy);
})
}
else{
fy.hq.setText("開始");
mainThreads.interrupt();
ui.run(function(){
toastLog("暫停執行腳本");
})
}
})
})
})
//時間差 ,回傳分鐘
function timeDeffToSecond(start,end){
var c = end.getTime()-start.getTime();
return c/(60*1000);
}
function openHome(){
if(text("首頁").exists()){
let b = text("首頁").findOne().bounds();
if(b.centerX()>0&&b.centerY()>0){
click(b.centerX(),b.centerY());
log("打開首頁");
return true;
}
}
return false;
}
function sx(){
log("--->"+text("極速任務串列").visibleToUser().exists());
let headTabY = 350;
if(text(myApp.appName).exists()){
if(text(myApp.appName).findOne().bounds().centerY()>0){
headTabY = text(myApp.appName).findOne().bounds().bottom+100;
}
}
while(true){
if(text("極速任務串列").visibleToUser().exists()){
let b = text("極速任務串列").findOne().bounds();
if(b.centerY()>0&&b.centerY()>=(device.height/4)){
log("不用下來");
break;
}
}
swipe(200,headTabY,230,device.height*0.66,500);
sleep(1000);
}
log("重繪"+headTabY);
swipe(200,headTabY,230,device.height*0.66,1000);
ui.run(function(){
toastLog("重繪串列");
})
}
//關注直播
function gzZB(){
if(text("關注").exists()){
let b = text("關注").findOne().bounds();
if(b.centerX()>0&&b.centerY()>0){
click(b.centerX(),b.centerY());
return true;
}
}else if(id("bsy").exists()){
let b = id("bsy").findOne().bounds();
if(b.centerX()>0&&b.centerY()>0){
click(b.centerX(),b.centerY());
return true;
}
}
return false;
}
//是否關注
function isGZ(){
if(text("關注").visibleToUser().exists()){
let b = text("關注").findOne().bounds();
if(b.centerX()>0&&b.centerY()>0&&b.centerY()<400){
return false;
}
}
return true;
}
function showWXMainPage(){
//tab 首頁圖示
if(className("android.widget.ImageView").id("cnh").exists()){
let btn = className("android.widget.ImageView").id("cnh").findOne().bounds();
click(btn.centerX(),btn.centerY());
}else if(className("android.widget.TextView").id("cns").exists()){
let btn = className("android.widget.TextView").id("cns").findOne().bounds();
click(btn.centerX(),btn.centerY());
}else if(className("android.widget.ImageView").text("微信").exists()){
let btn = className("android.widget.TextView").text("微信").findOne().bounds();
click(btn.centerX(),btn.centerY());
}
}
function isWJCSZS(){
var state = 0;
swipe(300,300,400,600,1000);
if(className("android.view.View").id("e3x").exists()){
className("android.view.View").id("e3x").find().forEach(function(currentValue,index){
if(currentValue.getText()=="檔案傳輸助手"){
state = 1;
}
})
return state;
}else if(text("檔案傳輸助手").exists()){
return 0;
}
return -1;
}
//進入檔案傳輸助手
function onWJCSZS(){
if(className("android.view.View").id("e3x").exists()){
className("android.view.View").id("e3x").find().forEach(function(currentValue,index){
if(currentValue.getText()=="檔案傳輸助手"){
log("點擊檔案傳輸助手");
click(currentValue.bounds().centerX(),currentValue.bounds().centerY());
sleep(1000);
}
})
}else if(text("檔案傳輸助手").exists()){
let btn = text("檔案傳輸助手").findOne().bounds();
log("點擊檔案傳輸助手");
click(btn.centerX(),btn.centerY());
sleep(1000);
}
}
function fsTP(){
waitForActivity(myApp.wxHomeActivty);
showWXMainPage();
if(isWJCSZS()>0){
onWJCSZS();
if(id("aks").exists()){
let b = id("aks").findOne().bounds();
if(b.centerX()>0&&b.centerY()>0){
click(b.centerX(),b.centerY());
sleep(2000);
if(text("相冊").exists()){
let bxc = text("相冊").findOne().bounds();
if(bxc.centerX()>0&&bxc.centerY()>0){
click(bxc.centerX(),bxc.centerY());
sleep(2000);
click(myApp.xqTPX,myApp.xqTPY);
sleep(1000);
if(textStartsWith("發送").visibleToUser().exists()){
let fsb = textStartsWith("發送").findOne().bounds();
if(fsb.centerX()>0&&fsb.centerY()>0){
click(fsb.centerX(),fsb.centerY());
sleep(2000);
back();
back();
}
}
}
}
}
}
}else{
log("請把檔案傳輸助手置頂");
ui.run(function(){
toastLog("請把檔案傳輸助手置頂");
})
}
}
//結束任務
function endTask(){
ui.run(function(){
toastLog("結束任務,開始分享抖音碼");
})
if(desc("更多").visibleToUser().exists()){
let b = desc("更多").findOne().bounds();
if(b.centerX()>0&&b.centerY()>0){
click(b.centerX(),b.centerY());
sleep(1500);
if(text("分享").visibleToUser().exists()){
let bf = text("分享").findOne().bounds();
if(bf.centerX()>0&&bf.centerY()>0){
click(bf.centerX(),bf.centerY());
sleep(2000);
if(text("抖音碼").visibleToUser().exists()){
let bm = text("抖音碼").findOne().bounds();
if(bm.centerX()>0&&bm.centerY()>0){
click(bm.centerX(),bm.centerY());
sleep(2000);
for(let i = 0;i<30;i++){
if(text("分享到").visibleToUser().exists()){
if(text("微信好友").visibleToUser().exists()){
let bzf = text("微信好友").findOne().bounds();
if(bzf.centerX()>0&&bzf.centerY()>0){
click(bzf.centerX(),bzf.centerY());
sleep(2000);
if(text("去微信好友分享").visibleToUser().exists()){
let fxb = text("去微信好友分享").findOne().bounds();
if(fxb.centerX()>0&&fxb.centerY()>0){
click(fxb.centerX(),fxb.centerY());
ui.run(function(){
toastLog("分享到微信");
})
sleep(5000);
}
}
}
}
}
}
}
}
}
}
}
}
}
//任務中
function taskRuning(endTime){
let startTime = new Date();
let endT = endTime - myApp.taskEarlyEnd;
if(endT<=0){
console.error("腦殼有包包,你接的時候小于你提前結束的時間!!你看個什么?");
}
while(timeDeffToSecond(startTime,new Date())<= endT){
sleep(random(2000,10000));
for(var i=0;i<4;i++){
click(myApp.dzX,myApp.dzY);
sleep(random(300,550));
}
}
}
function openZB(){
sleep(5000);
//waitForPackage(myApp.dyAppPackage);
log(currentPackage());
if(currentPackage()==myApp.dyAppPackage){
log("---------");
sleep(2000);
if(text("去看看").exists()){
let b = text("去看看").findOne().bounds();
if(b.centerX()>0&&b.centerY()>0){
click(b.centerX(),b.centerY());
sleep(2000);
}
}else if(text("打開看看").exists()){
let b = text("打開看看").findOne().bounds();
if(b.centerX()>0&&b.centerY()>0){
click(b.centerX(),b.centerY());
sleep(2000);
}
}
//已關注
if(isGZ()){
log("已經關注");
ui.run(function(){
toastLog("已經關注");
});
//點擊頭像
if(id("c75").exists()){
ui.run(function(){
toastLog("點擊頭像");
});
let bh = id("c75").findOne().bounds();
if(bh.centerX()>0&&bh.centerY()>0){
click(bh.centerX(),bh.centerY());
sleep(1000);
if(text("已關注").exists()){
let by = text("已關注").findOne().bounds();
if(by.centerX()>0&&by.centerY()>0){
click(by.centerX(),by.centerY());
}
}else{
click(100, device.height-150);
}
sleep(random(1500,2000));
if( textStartsWith("確定不再關注此人").exists()){
if(text("確定").exists()){
let bq= text("確定").findOne().bounds();
if(bq.centerX()>0&&bq.centerY()>0){
click(bq.centerX(),bq.centerY());
sleep(1000);
click(device.width-50,(device.height/2-50));
click(1000);
if(!gzZB()){
sleep(1000);
gzZB()
}
}
}
}
}
}
}
if(!gzZB()){
sleep(1000);
gzZB()
}
// 已經關注 ;
// if(id("d0b").exists()){
// click();
// }
}
//不再關注 text("確定不再關注此人").exists() ->text("確定").exists();
}
//查找任務
function findTask(){
let currentYXTask = 0;
let list = text("未滿").find();
log("有任務:"+list.length);
while(true){
if(list.length>0){
if(list[0].bounds().bottom>=(device.height*0.7)){
log("--->上滑動");
swipe(300,device.height*0.8,330,300,500);
list = text("未滿").find();
}else{
break;
}
}else{
break;
}
}
log("任務數:"+list.length);
if(list.length>0){
ui.run(function(){
toastLog("有任務");
})
let allList = textStartsWith("任務倒計時").find();
log("所有任務:"+allList.length);
for(let i = 0;i<allList.length;i++){
for(let j = 0;j<list.length;j++){
if(list[j].bounds().bottom<allList[i].bounds().top&&(list[j].bounds().bottom+100)>=allList[i].bounds().top){
log("位置::"+list[j].bounds().bottom);
log("任務所剩時間:"+allList[i].text());
let time = 0;
try{
time = allList[i].text().replace("任務倒計時","").split(":")[0];
}catch(err){
ui.run(function(){
toastLog("獲取任務時間出現錯誤!");
});
continue;
}
log("任務時間:"+time);
if(time>=myApp.taskMinTime){
if(list[j].bounds().centerX()>0&&list[j].bounds().centerY()){
log("點擊");
click(list[j].bounds().centerX(),list[j].bounds().centerY());
sleep(2000);
log("-->"+text("繼續接單").exists());
if(text("繼續接單").exists()){
log("繼續接單");
let qxb = text("繼續接單").findOne().bounds();
if(qxb.centerX()>0&&qxb.centerY()>0){
click(qxb.centerX(),qxb.centerY());
openZB();
log("11111111111");
taskRuning(time);
log("11111111111");
endTask();
log("11111111111");
fsTP();
ui.run(function(){
toastLog("打開直播");
})
}
}if(text("領取其他任務").exists()){
let lb = text("領取其他任務").findOne().bounds();
if(lb.centerX()>0&&lb.centerY()>0){
click(lb.centerX(),lb.centerY());
sleep(2000);
}
continue;
}else{
openZB();
log("22222222222222");
taskRuning(time);
log("22222222222222");
endTask();
log("22222222222222");
fsTP();
}
break;
}
}else{
ui.run(function(){
toastLog("任務時間太短,不接了");
})
currentYXTask++;
if(currentYXTask>j){
break;
}
while(true){
if(list.length>currentYXTask){
if(list[currentYXTask].bounds().bottom>=(device.height*0.7)){
log("--->上滑動");
swipe(300,device.height*0.8,330,300,500);
list = text("未滿").find();
}else{
break;
}
}else{
break;
}
}
}
}
}
}
}
sx();
}
var jsrwTabY = 0;
function start(fy){
let app = launchApp(myApp.appName);
sleep(3000);
if(app){
log(currentActivity());
waitForActivity(myApp.homeActivity);
openHome();
sleep(1000);
while(true){
// log("重繪第"+i);
sx();
sleep(1500);
findTask();
ui.run(function(){
toastLog("休息10秒");
})
sleep(10000);
ui.run(function(){
toastLog("重新獲取任務");
})
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/224292.html
標籤:其他
下一篇:Android WMS筆記(1)
