autoJS 網易公開課app封裝函數


環境 安卓7.0或以上 網易公開課app

/**
 * 關注用戶
 * @return bool true or false
 */
function followUser() {
    waitForActivity("com.netease.vopen.feature.timeline.ui.UserTimelineActivity");
    if (id('timeline_profile_care_btn').exists()) {
        var text = id('timeline_profile_care_btn').findOnce().text();
        if (text == "關注") {
            id('timeline_profile_care_btn').click();
            log('關注成功');
            return true;
        } else if (text == "已關注") {
            log('已關注');
            return true;
        } else {
            log('關注失敗');
            return false;
        }

    } else {
        log("ERROR:未找到控件");
        return false;
    }
}


/**
 * 獲取用戶性別
 * @return str gender 
 */
function getUserGender() {
    if (!requestScreenCapture()) {
        toast("請求截圖失敗");
        exit();
    }
    waitForActivity("com.netease.vopen.feature.timeline.ui.UserTimelineActivity");
    if (id('timeline_profile_gender').exists()) {
        var rect = id('timeline_profile_gender').findOnce().bounds();
        var img = captureScreen();
        var point = findColor(img, -622207, {
            region: [rect.left, rect.top, rect.width(), rect.height()],
            threshold: 4
        });
        if (point) {
            return "女";
        } else {
            var point = findColor(img, -7943189, {
                region: [rect.left, rect.top, rect.width(), rect.height()],
                threshold: 4
            });
            if (point) {
                return "男";
            }
        };

    } else {
        return "未知";
    }
}
/**
 * 獲取用戶昵稱
 * @return str userName
 */
function getUserName() {
    var userName = '';
    //等待個人人資料頁面出現
    waitForActivity("com.netease.vopen.feature.timeline.ui.UserTimelineActivity");
    if (id('mid_title').exists()) {
        userName = id('mid_title').findOnce().text();
    } else {
        log('ERROR:未獲取到用戶昵稱');
    }
    return userName;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM