autojs-快手極速版

//檢查無障礙服務
auto.waitFor();

/**
 * 開啓線程
 */
threads.start(KsVideoAutoPagerChrome);

//-------------------------按鍵監聽-------------------------------//
//啓用按鍵監聽
events.observeKey();
//監聽音量下鍵按下
events.onKeyDown("volume_down", function(event){
    console.log("音量下鍵被按下了");
    console.hide();
    console.log("關閉控制檯");
    console.log("停止快手極速版子腳本");
    exit();
});
//監聽say事件
events.on("say", function(words){
    if(words == "關閉控制檯"){
        console.hide();
        console.log("關閉控制檯");
    }
});
//保持腳本運行
setInterval(()=>{}, 1000);
//-------------------------按鍵監聽-------------------------------//
/**
 * 打開快手極速版
 */
function OpenKsJsb(){
    if(app.getPackageName("快手極速版") != null){
        sleep(random(800,1000));
        app.launchApp("快手極速版");
    }else{
        alert("溫馨提示", "請下載安裝快手極速版");
        console.log("請下載安裝快手極速版");
        console.hide();
        console.log("關閉控制檯");
        console.log("停止快手極速版子腳本");
        exit();
    }
}
/**
 * 快手極速版自動翻頁
 */
function KsVideoAutoPagerChrome(){
    console.show()
    if(!requestScreenCapture()){
        toast("請求截圖失敗");
        stop();
    }
    //快手極速版
    sleep(random(800,1000));
    OpenKsJsb();
    sleep(random(1000,2000));
    while(true){
        var time = VideoRandomTime();
        console.log("下一視頻,請等待" + time/1000 +"秒");
        sleep(time);  
        //檢測青少年模式
        if(text("設置青少年模式").findOnce() != null){
            console.log("設置青少年模式");
            sleep(random(1000,2000));
            text("我知道了").findOne().click();
            console.log("點擊我知道了");
            sleep(random(1000,2000));
        }
        //立即邀請
        if(text("立即邀請").findOnce() != null){
            console.log("立即邀請");
            sleep(random(1000,2000));
            back();
            console.log("關閉立即邀請");
            sleep(random(1000,2000));
        }
        //檢測滑塊
        if(text("拖動滑塊").findOnce() != null){
            console.log("出現滑塊驗證");
            DragSlider();
            sleep(random(1000,2000));
        }
        //進入個人主頁
        if(desc("返回").findOnce() != null){
            console.log("進入個人主頁");
            sleep(random(1000,2000));
            desc("返回").findOne().click();
            sleep(random(1000,2000));
        }
        //開始滑動視頻
        var x1 = random(device.width/4,(device.width/4)*3);
        var y1 = random((device.height/4)*3.5,(device.height/4)*3.75);
        var x2 = random(device.width/4,(device.width/4)*3);
        var y2 = random((device.height/4)*0.25,(device.height/4)*0.5);
        RandomSwipe(x1, y1, x2, y2,random(100,500));
    }
}
/**
 * 獲取視頻隨機停留時間
 */
function VideoRandomTime(){
    //設置隨機停留時長範圍
    var timeMin = 4000;
    var timeMax = 7000;
    return random(timeMin,timeMax);
}
//-------------------------拖動滑塊-----------------------------//
/**
 * 拖動滑塊
 */
function DragSlider() {
    for (var i = 0; i < 0; i++) { sleep(1000); log(i); }
    while (true) {
        img = images.captureScreen();
        if (img) {
            console.log("截圖成功。進行識別滑塊!");
            break;
        } else {
            console.log('截圖失敗,重新截圖');
        }
    }
    var zx = discernSlidingblock(img, device.width) + 65
    console.info("識別結果滑塊X座標:" + zx);
    if (zx > -1) {
        //計算拖到滑塊座標
        var 向右拖動滑塊填充拼圖 = text("向右拖動滑塊填充拼圖").findOne();
        var qx = 向右拖動滑塊填充拼圖.bounds().left + (向右拖動滑塊填充拼圖.bounds().width() * 0.15) / 2;
        var qy = 向右拖動滑塊填充拼圖.bounds().centerY();
        var zy = qy;
        console.log(qx);
        console.log(qy);
        DragSliderSwipe(qx, qy, zx, zy)
        return true;
    } else {
        console.log("識別有誤,請確認是否在滑塊界面");
        return false;
    }
}
/**
 * 計算滑塊位置
 * @param {圖片} img 
 * @param {分辨率} ratio 
 */
function discernSlidingblock(img, ratio) {
    //創建識別變量
    var temp, temp2, x, y, num, color, p, temp3, arr1;
    //分析設備分辨率
    if (ratio == 720) {
        var tb = [348, 253, 691, 638, 81]
        log("您的設備分辨率爲:720p");
    } else if (ratio == 1080) {
        var tb = [463, 387, 912, 831, 125]
        log("您的設備分辨率爲:1080p");
    } else {
        log("當前設備分辨率不符合規範")
        return -2
    }
    num = Math.ceil(tb[4] / 3.3 - 4);

    //計算滑塊位置
    for (var k = 29; k <= 40; k++) {
        temp2 = "";
        color = "#" + k + "" + k + "" + k + "";
        for (var i = 1; i <= num; i++) {
            temp2 = temp2 + "0|" + i + "|" + color + ",";
            temp2 = temp2 + i + "|0|" + color + ",";
            temp2 = temp2 + "1|" + i + "|" + color + ",";
            temp2 = temp2 + i + "|1|" + color + ",";
            temp2 = temp2 + "2|" + i + "|" + color + ",";
            temp2 = temp2 + i + "|2|" + color + ",";
        }
        x = 0;
        while (x > -2) {
            y = 0;
            while (y > -2) {
                temp = "";
                for (var i = 1; i <= num; i += 2) {
                    temp = temp + "0|" + (tb[4] + y - i - 1) + "|" + color + ",";
                    temp = temp + (tb[4] + x) + "|" + i + "|" + color + ",";
                    temp = temp + (tb[4] + x) + "|" + (tb[4] + y - i - 1) + "|" + color + ",";
                    temp = temp + (tb[4] + x - i - 1) + "|0|" + color + ",";
                    temp = temp + i + "|" + (tb[4] + y) + "|" + color + ",";
                    temp = temp + (tb[4] + x - i - 1) + "|" + (tb[4] + y) + "|" + color + ",";
                    temp = temp + "1|" + (tb[4] + y - i - 1) + "|" + color + ",";
                    temp = temp + (tb[4] + x - 1) + "|" + i + "|" + color + ",";
                    temp = temp + (tb[4] + x - 1) + "|" + (tb[4] + y - i - 1) + "|" + color + ",";
                    temp = temp + (tb[4] + x - i - 1) + "|1|" + color + ",";
                    temp = temp + i + "|" + (tb[4] + y - 1) + "|" + color + ",";
                    temp = temp + (tb[4] + x - i - 1) + "|" + (tb[4] + y - 1) + "|" + color + ",";
                }
                temp = temp + temp2 + "0|0|" + color;
                arr1 = temp.split(",");
                var arr2 = new Array();
                for (var i = 0; i < arr1.length - 1; i++) {
                    arr2[i] = new Array();
                    temp3 = arr1[i].split("|");
                    arr2[i] = [Number(temp3[0]), Number(temp3[1]), temp3[2]];
                }
                try {
                    p = images.findMultiColors(img, color, arr2, {
                        region: [tb[0], tb[1], tb[2] - tb[0], tb[3] - tb[1]],
                        threshold: (Math.floor(k / 10) * 16 + k % 10)
                    });
                    if (p) {
                        img.recycle();
                        return p.x
                    }
                } catch (error) {
                    //出錯
                    console.log("識別失敗,錯誤原因:" + error);
                    return -1;
                }
                y = --y;
            }
            x = --x;
        }
    }
    try {
        img.recycle();
    } catch (error) {
        console.log("識別失敗,錯誤原因:" + error);
    }
    return -1;
}
/**
 * 真人模擬滑動函數 (滑塊滑動)
 * @param {起點x} sx 
 * @param {起點y} sy 
 * @param {終點x} ex 
 * @param {終點y} ey 
 */
function DragSliderSwipe(sx, sy, ex, ey) {
    //設置隨機滑動時長範圍
    var timeMin = 1000
    var timeMax = 3000
    //設置控制點極限距離
    var leaveHeightLength = 500

    //根據偏差距離,應用不同的隨機方式
    if (Math.abs(ex - sx) > Math.abs(ey - sy)) {
        var my = (sy + ey) / 2
        var y2 = my + random(0, leaveHeightLength)
        var y3 = my - random(0, leaveHeightLength)

        var lx = (sx - ex) / 3
        if (lx < 0) { lx = -lx }
        var x2 = sx + lx / 2 + random(0, lx)
        var x3 = sx + lx + lx / 2 + random(0, lx)
    } else {
        var mx = (sx + ex) / 2
        var y2 = mx + random(0, leaveHeightLength)
        var y3 = mx - random(0, leaveHeightLength)

        var ly = (sy - ey) / 3
        if (ly < 0) { ly = -ly }
        var y2 = sy + ly / 2 + random(0, ly)
        var y3 = sy + ly + ly / 2 + random(0, ly)
    }   
    //獲取運行軌跡,及參數
    var time = [0, random(timeMin, timeMax)]
    var track = bezierCreate(sx, sy, x2, y2, x3, y3, ex, ey)
    // log("隨機控制點A座標:" + x2 + "," + y2)
    // log("隨機控制點B座標:" + x3 + "," + y3)
    // log("隨機滑動時長:" + time[1])
    //滑動
    gestures(time.concat(track))
}
/**
 * 計算滑動軌跡
 */
function bezierCreate(x1, y1, x2, y2, x3, y3, x4, y4) {
    //構建參數
    var h = 100;
    var cp = [{ x: x1, y: y1 + h }, { x: x2, y: y2 + h }, { x: x3, y: y3 + h }, { x: x4, y: y4 + h }];
    var numberOfPoints = 100;
    var curve = [];
    var dt = 1.0 / (numberOfPoints - 1);
    //計算軌跡
    for (var i = 0; i < numberOfPoints; i++) {
        var ax, bx, cx;
        var ay, by, cy;
        var tSquared, tCubed;
        var result_x, result_y;

        cx = 3.0 * (cp[1].x - cp[0].x);
        bx = 3.0 * (cp[2].x - cp[1].x) - cx;
        ax = cp[3].x - cp[0].x - cx - bx;
        cy = 3.0 * (cp[1].y - cp[0].y);
        by = 3.0 * (cp[2].y - cp[1].y) - cy;
        ay = cp[3].y - cp[0].y - cy - by;

        var t = dt * i
        tSquared = t * t;
        tCubed = tSquared * t;
        result_x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
        result_y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
        curve[i] = {
            x: result_x,
            y: result_y
        };
    }
    //軌跡轉路數組
    var array = [];
    for (var i = 0; i < curve.length; i++) {
        try {
            var j = (i < 100) ? i : (199 - i);
            xx = parseInt(curve[j].x)
            yy = parseInt(Math.abs(100 - curve[j].y))
        } catch (e) {
            break
        }
        array.push([xx, yy])
    }
    return array
}
//-------------------------拖動滑塊-----------------------------//
//-------------------------曲線滑動-----------------------------//
/**
 * 仿真隨機帶曲線滑動(視頻/小說)
 * @param {起點x} qx 
 * @param {起點y} qy 
 * @param {終點x} zx 
 * @param {終點y} zy 
 * @param {過程耗時單位毫秒} time 
 */
function RandomSwipe(qx, qy, zx, zy, time) {
    var xxy = [time];
    var point = [];
    var dx0 = {
        "x": qx,
        "y": qy
    };
    var dx1 = {
        "x": random(qx - (device.width/4)*0.25, qx + (device.width/4)*0.25),
        "y": random(qy , qy + 50)
    };
    var dx2 = {
        "x": random(zx - (device.width/4)*0.25, zx + (device.width/4)*0.25),
        "y": random(zy , zy + 50)
    };
    var dx3 = {
        "x": zx,
        "y": zy
    };
    for (var i = 0; i < 4; i++) {
        eval("point.push(dx" + i + ")");
    };
    for (let i = 0; i < 1; i += 0.08) {
        xxyy = [parseInt(bezier_curves(point, i).x), parseInt(bezier_curves(point, i).y)]
        xxy.push(xxyy);
    }
    gesture.apply(null, xxy);
};
function bezier_curves(cp, t) {
    cx = 3.0 * (cp[1].x - cp[0].x); 
    bx = 3.0 * (cp[2].x - cp[1].x) - cx; 
    ax = cp[3].x - cp[0].x - cx - bx; 
    cy = 3.0 * (cp[1].y - cp[0].y); 
    by = 3.0 * (cp[2].y - cp[1].y) - cy; 
    ay = cp[3].y - cp[0].y - cy - by; 
    
    tSquared = t * t; 
    tCubed = tSquared * t; 
    result = {
        "x": 0,
        "y": 0
    };
    result.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x; 
    result.y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y; 
    return result; 
};
//-------------------------曲線滑動-----------------------------//
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章