编辑代码

//1111
auto();

const Utils = require('/sdcard/HuaWeiZ/Utils.js')
const path = "/sdcard/HuaWeiZ/";
const path_2 = "/sdcard/HuaWeiZ/其他/";
const ttPath = "/sdcard/HuaWeiZ/天天/";
let mi=Utils.mi
const jss=["直播红包.js","抢红包.js","亲密度.js","买基金.js","其他.js"]

var window = floaty.window(
    <frame>
        <vertical>
            <button id="remove" text="移动/关闭" w="70" h="40" bg="#77ffffff"/>
            <button id="pageRed" text="首页红包" w="70" h="40" bg="#77ffffff"/>
            <button id="autoJsAll" text="自动(3)" w="70" h="38" bg="#77ffffff"/>
            <button id="inputM" text="密码" w="70" h="40" bg="#77ffffff"/>
            <vertical id="h">
                <button id="stopAli" text="停支付宝" w="70" h="40" bg="#77ffffff"/>
                <button id="grabRed" text="抢红包" w="70" h="40" bg="#77ffffff"/>
                <button id="intimacy" text="亲密度" w="70" h="40" bg="#77ffffff"/>
                <button id="buyFund" text="买基金" w="70" h="40" bg="#77ffffff"/>
                <button id="incomeFund" text="买入基金" w="70" h="40" bg="#77ffffff"/>
                <button id="payFund" text="卖出基金" w="70" h="40" bg="#77ffffff"/>
                <button id="autoTT" text="天天积分" w="70" h="38" bg="#77ffffff"/>
                <button id="payTT" text="天天卖出" w="70" h="38" bg="#77ffffff"/>
                <button id="ttJanCha" text="买入检查" w="70" h="40" bg="#77ffffff"/>
                <button id="ttRedJanCha" text="定投检查" w="70" h="40" bg="#77ffffff"/>
                <button id="ttRedBack" text="恢复定投" w="70" h="40" bg="#77ffffff"/>
                <button id="syncScript" text="同步脚本" w="70" h="40" bg="#77ffffff"/>
                <button id="others" text="其他" w="70" h="40" bg="#77ffffff"/>
            </vertical>
        </vertical>
    </frame>
);
window.setPosition(2, 80)

setInterval(() => {
}, 1000);

//其他
let syncScriptExe=null;
window.syncScript.click(()=>{
    if(window.syncScript.getText() == '同步脚本'){
        if(!files.exists(path)){
            toast("脚本文件不存在: " + path+"同步脚本.js");
            return
        }
        syncScriptExe = engines.execScriptFile(path+"同步脚本.js");
        window.syncScript.setText('停止运行');
    }else{
        if(syncScriptExe){
            syncScriptExe.getEngine().forceStop();
        }
        window.syncScript.setText('同步脚本');
    }
})


//恢复定投
let ttRedBackExe=null;
window.ttRedBack.click(()=>{
    if(window.ttRedBack.getText() == '恢复定投'){
        if(!files.exists(path)){
            toast("脚本文件不存在: " + ttPath+"恢复定投.js");
            return
        }
        ttRedBackExe = engines.execScriptFile(ttPath+"/恢复定投.js");
        window.ttRedBack.setText('停止运行');
    }else{
        if(ttRedBackExe){
            ttRedBackExe.getEngine().forceStop();
        }
        window.ttRedBack.setText('恢复定投');
    }
})

//定投检查
let ttRedJanChaExe=null;
window.ttRedJanCha.click(()=>{
    if(window.ttRedJanCha.getText() == '定投检查'){
        if(!files.exists(path)){
            toast("脚本文件不存在: " + ttPath+"定投检查.js");
            return
        }
        ttRedJanChaExe = engines.execScriptFile(ttPath+"/定投检查.js");
        window.ttRedJanCha.setText('停止运行');
    }else{
        if(ttRedJanChaExe){
            ttRedJanChaExe.getEngine().forceStop();
        }
        window.ttRedJanCha.setText('定投检查');
    }
})

//自动天天积分
let autoTTExe=null;
window.autoTT.click(()=>{
    if(window.autoTT.getText() == '天天积分'){
        if(!files.exists(path)){
            toast("脚本文件不存在: " + ttPath+"天天积分.js");
            return
        }
        autoTTExe = engines.execScriptFile(ttPath+"/天天积分.js");
        window.autoTT.setText('停止运行');
    }else{
        if(autoTTExe){
            autoTTExe.getEngine().forceStop();
        }
        window.autoTT.setText('天天积分');
    }
})

//卖ETF
let payTTExe=null;
window.payTT.click(()=>{
    if(window.payTT.getText() == '天天卖出'){
        if(!files.exists(path)){
            toast("脚本文件不存在: " + ttPath+"/天天卖出.js");
            return
        }
        payTTExe = engines.execScriptFile(ttPath+"/天天卖出.js");
        window.payTT.setText('停止运行');
    }else{
        if(payTTExe){
            payTTExe.getEngine().forceStop();
        }
        window.payTT.setText('天天卖出');
    }
})

//天天买入检查
let ttJanChaExe=null;
window.ttJanCha.click(()=>{
    if(window.ttJanCha.getText() == '买入检查'){
        if(!files.exists(ttPath)){
            toast("脚本文件不存在: " + ttPath+"买入检查.js");
            return
        }
        ttJanChaExe = engines.execScriptFile(ttPath+"买入检查.js");
        window.ttJanCha.setText('停止运行');
    }else{
        if(ttJanChaExe){
            ttJanChaExe.getEngine().forceStop();
        }
        window.ttJanCha.setText('买入检查');
    }
})


//自动(3)
let autoJsAllExe=null;
window.autoJsAll.click(()=>{
    if(window.autoJsAll.getText() == '自动(3)'){
        window.autoJsAll.setText('停止运行');
        autoJsAllFn();
    }else{
        if(autoJsAllExe){
            autoJsAllExe.getEngine().forceStop();
        }
        window.autoJsAll.setText('自动(3)');
    }
})

//其他
let othersExe=null;
window.others.click(()=>{
    if(window.others.getText() == '其他'){
        if(!files.exists(path)){
            toast("脚本文件不存在: " + path+"其他.js");
            return
        }
        othersExe = engines.execScriptFile(path+"其他.js");
        window.others.setText('停止运行');
    }else{
        if(othersExe){
            othersExe.getEngine().forceStop();
        }
        window.others.setText('其他');
    }
})


//亲密度
let intimacyExe = null;
window.intimacy.click(()=>{
    if(window.intimacy.getText() == '亲密度'){
        if(!files.exists(path)){
            toast("脚本文件不存在: " + path+"亲密度.js");
            return
        }
        intimacyExe = engines.execScriptFile(path+"亲密度.js");
        window.intimacy.setText('停止运行');
    }else{
        if(intimacyExe){
            intimacyExe.getEngine().forceStop();
        }
        window.intimacy.setText('亲密度');
    }
})

//抢红包
let grabRedExe = null;
window.grabRed.click(()=>{
    if(window.grabRed.getText() == '抢红包'){
        if(!files.exists(path)){
            toast("脚本文件不存在: " + path+"抢红包.js");
            return
        }
        grabRedExe = engines.execScriptFile(path+"抢红包.js");
        window.grabRed.setText('停止运行');
    }else{
        if(grabRedExe){
            grabRedExe.getEngine().forceStop();
        }
        window.grabRed.setText('抢红包');
    }
})


//买入基金
let incomeFundExe=null;
window.incomeFund.click(()=>{
    if(window.incomeFund.getText() == '买入基金'){
        if(!files.exists(path)){
            toast("脚本文件不存在: " + path+"http买基金.js");
            return
        }
        incomeFundExe = engines.execScriptFile(path+"http买基金.js");
        window.incomeFund.setText('停止运行');
    }else{
        if(incomeFundExe){
            incomeFundExe.getEngine().forceStop();
        }
        window.incomeFund.setText('买入基金');
    }
})



//卖出基金
let payFundExe=null;
window.payFund.click(()=>{
    if(window.payFund.getText() == '卖出基金'){
        if(!files.exists(path)){
            toast("脚本文件不存在: " + path+"http卖基金.js");
            return
        }
        payFundExe = engines.execScriptFile(path+"http卖基金.js");
        window.payFund.setText('停止运行');
    }else{
        if(payFundExe){
            payFundExe.getEngine().forceStop();
        }
        window.payFund.setText('卖出基金');
    }
})

//首页红包
let pageRedExe=null;
window.pageRed.click(()=>{
    if(window.pageRed.getText() == '首页红包'){
        if(!files.exists(path)){
            toast("脚本文件不存在: " + path+"抢红包/首页红包.js");
            return
        }
        pageRedExe = engines.execScriptFile(path+"抢红包/首页红包.js");
        window.pageRed.setText('停止运行');
    }else{
        if(pageRedExe){
            pageRedExe.getEngine().forceStop();
        }
        window.pageRed.setText('首页红包');
    }
})

//停止支付宝
window.stopAli.click(()=>{
    Utils.stopApp("com.eg.android.AlipayGphone")
})

//买基金
let buyFundExe=null;
window.buyFund.click(()=>{
    if(window.buyFund.getText() == '买基金'){
        if(!files.exists(path)){
            toast("脚本文件不存在: " + path+jss[3]);
            return
        }
        buyFundExe = engines.execScriptFile(path+jss[3]);
        window.buyFund.setText('停止运行');
    }else{
        if(buyFundExe){
            buyFundExe.getEngine().forceStop();
        }
        window.buyFund.setText('买基金');
    }
})

//输入密码
window.inputM.click(()=>{
    if(window.inputM.getText() == '密码'){
        window.inputM.setText('停止运行');
        thread=threads.start(function() {
            var domm = text("使用密码").findOne(1000)
            if (domm) {
                text("使用密码").findOnce().click();
            } else {
                sleep(1000)
            }
            Utils.inputText(mi);
            window.inputM.setText('密码');
        })
    }else{
        window.inputM.setText('密码');
    }
});


window.h.setVisibility(8)

//记录按键被按下时的触摸坐标
var x = 0, y = 0;
//记录按键被按下时的悬浮窗位置
var windowX, windowY;
//记录按键被按下的时间以便判断长按等动作
let downTime;

window.remove.setOnTouchListener(function (view, event) {
    switch (event.getAction()) {
        case event.ACTION_DOWN:
            x = event.getRawX();
            y = event.getRawY();
            windowX = window.getX();
            windowY = window.getY();
            downTime = new Date().getTime();
            return true;
        case event.ACTION_MOVE:
            //移动手指时调整悬浮窗位置
            window.setPosition(windowX + (event.getRawX() - x),
                windowY + (event.getRawY() - y));
            //如果按下的时间超过3.5秒判断为长按,退出脚本
            if (new Date().getTime() - downTime > 3500) {
                exit();
            }
            return true;
        case event.ACTION_UP:
            //手指弹起时如果偏移很小则判断为点击
            if (Math.abs(event.getRawY() - y) < 5 && Math.abs(event.getRawX() - x) < 5) {
                //toast(window.h.getVisibility())
                if (window.h.getVisibility() == 0) {
                    window.h.setVisibility(8)
                } else {
                    window.h.setVisibility(0)
                }
            }
            return true;
    }
    return true;
});
function autoJsAllFn() {
    thread = threads.start(function () {
        let filePathList = ["支付宝积分.js","泓德基金.js", "国寿模拟.js", "中欧养老.js"];
        events.on("exit", function () {
            log("exit");
        });
        setInterval(function () {}, 1000);
        let limitTime = 360000;
        while (1) {
            if (filePathList.length > 0) {
                let e = engines.execScriptFile(path_2+filePathList[0]);
                while (!e.getEngine()); //等待脚本运行
                let currentScriptEngine = e.getEngine();
                let lastTime = new Date().getTime();
                while (1) {
                    let currentTime = new Date().getTime();
                    if (currentTime - lastTime > limitTime) {
                        log("脚本运行超时, 开始 执行销毁命令");
                        currentScriptEngine.forceStop();
                        log("脚本运行超时, 结束 执行销毁命令");
                        break;
                    }
                    if (currentScriptEngine.isDestroyed()) {
                        break;
                    } else {
                        sleep(500);
                    }
                }
            } else {
                log("脚本运行结束");
                return
                // engines.myEngine().forceStop();
            }
            filePathList.shift();
        }
    })
}
//1111