实践之微信自动挑选黑名单

zabite
Oct 11, 2021 2:35:51 PM
做过销售、营销的同学都知道,手机联系人少于一千都不好意思打招呼,大量的联系人占用了很多手机内存,导致手机运行越来越慢。而这些联系人中有很多已经删除了我们,或者已经拉黑了我们,如何快速把这些已经删除或者拉黑我们的联系人找出来并删除是优化手机速度很重要的手段,下面就给出基于「Android智能辅助平台」免费实现的自动挑选微信黑名单代码(红米9A、8A测试通过)
var sAlpha = '';

function main() {
    var removedList = [];

    if (!launchApp('com.tencent.mm')) {
        console.error('启动微信失败');
        return removedList;
    }

    var ret = smartFindView('txt:发现', {failed: exitPopup, maxStep: 30});
    if (ret.length <= 0) {
        console.log('进入微信失败');
        return ;
    }

    var maxSelCount = 37;
    var username = findUsername();
    console.log('username:' + username);
    if (username != '') {
        ret = switchPage('txt:通讯录', 'txt:新的朋友', {click:true, failed: exitPopup, maxStep:8});
        if (ret.length > 0) {
            console.log('进入通讯录');
            var exit = false, allNameList = [];
            while(!exit) {
                ret = switchPage('txt:更多功能按钮', 'txt:发起群聊', {click:true, failed: exitPopup, maxStep:8});
                if (ret.length > 0) {
                    ret = switchPage('txt:发起群聊', 'txt:选择一个群', {click:true, failed: exitPopup, maxStep:8});
                    if (ret.length > 0) {
                        jumpByAlpha();

                        var curList = [], preFirstText = '', selectedCount = 0;
                        while (selectedCount < maxSelCount) {
                            var firstText = '', index = -1, curSelectedCount = 0;
                            ret = smartFindView('cn:android.widget.ListView', {failed: exitPopup});
                            while (ret.length > 0 && index < ret.views[0].size - 1) {
                                if (index > -1) {
                                    index++;
                                } else {
                                    console.log('ret.views[0].size:' + ret.views[0].size);
                                    for (var item of ret.views[0]) {
                                        // console.log('item className:' + item.className);
                                        ++index;
                                        if (item.className == 'android.widget.RelativeLayout') {
                                            console.log('find first---');
                                            break;
                                        }
                                    }
                                    // console.log('find for end');
                                }

                                if (index > -1) {
                                    if (index < ret.views[0].size) {
                                        var item = ret.views[0][index];
                                        if (item.size > 0) {
                                            if (item[0].className == 'android.widget.TextView') {
                                                sAlpha = item[0].text;
                                                console.log('找到字母:' + sAlpha);
                                                if (sAlpha=='') {
                                                    firstText = item[0].text;
                                                }
                                            } else {
                                                var t = findView('cn:android.widget.TextView', {root: item});
                                                if (t.length > 0) {
                                                    var text = t.views[0].text;
                                                    if (firstText=='') {
                                                        firstText = text;
                                                    }

                                                    console.log('找到文本:' + text);
                                                    if (allNameList.indexOf(text) < 0) {
                                                        console.log('添加:' + text);
                                                        var checkView = item[0][0];
                                                        if (checkView) {
                                                            click(checkView, {click: true});
                                                            allNameList.push(text);
                                                            curList.push(text);
                                                            curSelectedCount += 1;


                                                            if (curSelectedCount + selectedCount >= maxSelCount) {
                                                                break;
                                                            }
                                                        } else {
                                                            console.log('找不到 checkbox:' + text);
                                                        }
                                                    } else {
                                                        console.log('已经找到过了:' + text);
                                                    }
                                                } else {
                                                    console.log('没有找到text');
                                                }
                                            }
                                        } else {
                                            console.log('item size is 0');
                                        }
                                    } else {
                                        console.log('一轮结束');
                                        break;
                                    }
                                } else {
                                    console.log('找到的index为-1');
                                    break;
                                }

                                ret = smartFindView('cn:android.widget.ListView', {failed: exitPopup});
                            }

                            console.log('一页完成');

                            if (preFirstText == firstText) {
                                console.log('两次相同,结束了----:' + firstText);
                                exit = true;
                                break;
                            }
                            preFirstText = firstText;

                            if (curSelectedCount > 0) {
                                selectedCount += curSelectedCount;
                                if (selectedCount < maxSelCount) {
                                    console.log('scroll 1');
                                    scroll('up', {root: ret.views[0], type: 2, afterWait: 1000});
                                }
                            } else {
                                console.log('scroll 2');
                                scroll('up', {root: ret.views[0], type: 2, afterWait: 1000});
                            }

                            console.log('一轮 正式结束 selectedCount:' + selectedCount);
                        }

                        if (selectedCount > 0) {
                            var friends = findFriends();
                            console.log('friends:' + friends);
                            for (var item of curList) {
                                if (friends.indexOf(item) < 0) {
                                    removedList.push(item);
                                }
                            }
                        }

                        if (selectedCount < maxSelCount) {
                            console.log('结束了---');
                            exit = true;
                            break;
                        }
                        console.log('完成一圈');
                    } else {
                        console.log('进入选择失败');
                    }
                } else {
                    console.log('进入群聊失败');
                }
            }

            console.log('removed:' + removedList);
        }
    } else {
        console.log('find username failed');
    }

    console.log('退出');

    return removedList;
}

function findFriends() {
    var result = [];
    var ret = switchPage('txt^:完成', 'txt^:群聊', {click:true, failed: exitPopup, maxStep: 10});
    if (ret.length > 0) {
        ret = switchPage('txt:聊天信息', 'txt:分隔栏', {click:true, failed: exitPopup, maxStep: 10});
        if (ret.length > 0) {
            var needFindFriend = true;
            ret = smartFindView('cn:android.widget.ListView', {failed: exitPopup});
            while (ret.length > 0) {
                if (needFindFriend) {
                    for (var item of ret.views[0]) {
                        if (item.className == 'android.widget.TextView') {
                            needFindFriend = false;
                            break;
                        } else {
                            for (var child of item) {
                                if (child.size == 2 && child[1].size == 1) {
                                    if (result.indexOf(child[1][0].text) < 0) {
                                        result.push(child[1][0].text);
                                    } else {
                                        console.log('已经添加过,忽略');
                                        break;
                                    }
                                } else {
                                    console.log('做完了:' + result.length);
                                    needFindFriend = false;
                                    break;
                                }
                            }

                            if (!needFindFriend) {
                                break;
                            }
                        }
                    }
                } else {
                    ret = smartFindView('txt:删除并退出', {failed: exitPopup, maxStep: 2});
                    if (ret.length > 0) {
                        console.log('删除并退出了');
                        ret = switchPage('txt:删除并退出', 'txt:离开群聊', {failed: exitPopup});
                        if (ret.length > 0) {
                            ret = switchPage('txt:离开群聊', 'txt:发现', {click: true, failed: exitPopup});
                            if (ret.length > 0) {
                                console.log('成功---');
                                return result;
                            }
                        }
                        break;
                    }
                }

                scroll('up', {distance: 0.9});
                ret = smartFindView('cn:android.widget.ListView', {failed: exitPopup});
            }
        } else {
            console.log('进入错误1');
        }
    } else {
        console.log('进入错误2');
    }

    back2Page('txt:发现', {failed: exitPopup, backFirst: false});

    return result;
}

function jumpByAlpha() {
    console.log('sAlpha:' + sAlpha);
    var jumpIndex = 0;
    if (sAlpha != '') {
        if ('#' == sAlpha) {
            jumpIndex = 26;
        } else {
            jumpIndex = sAlpha.charCodeAt(0) - 'A'.charCodeAt(0);
        }
    }

    console.log('jumpIndex:' + jumpIndex);

    if (jumpIndex > -1) {
        var ret = smartFindView('cn:android.view.View', {flag: 'find_all', failed: exitPopup});
        if (ret.length > 0) {
            console.log('total length:' + ret.views.length + '  rsDensity:' + rsDensity + ' rsScreenHeight:' + rsScreenHeight);
            for (var item of ret.views) {
                if ((item.width < 30*rsDensity) && (item.height > rsScreenHeight/2)) {
                    console.log('find panel item width:' + item.width + '  height:' + item.height);
                    var per = item.height / 29.0, x = item.left + item.width*2/3, y = parseInt((jumpIndex+2)*per + per/2 + item.top);
                    console.log('click x:' + x + '  y:' + y + '  per:' + per);
                    gestureClick(x, y, {afterWait: 1000, duration: 200});
                    break;
                }
            }
        } else {
            console.log('找不到 pandel')
        }
    } else {
        console.log('不需要跳转');
    }
}

function exitPopup() {
    var ret = findView('txt:稍后|txt:以后再说|txt:允许|txt:确定|txt:存储空间不足', {maxStep: 1});
    if (ret.length > 0) {
        console.log('找到:' + ret.tag);
        if (ret.tag == '存储空间不足') {
            clickByText('忽略', {click: true});
        } else {
            click(ret.views[0], {click: true});
        }
    }
}

function findUsername() {
    var ret = switchPage('txt:我', 'txt^:微信号', {click: true, failed: exitPopup});
    if (ret.length > 0) {
        var text = ret.views[0].text;
        return text.substring(text.indexOf('微信号:') +'微信号:'.length);
    }
    return "";
}

发表评论
最新评论
商务合作QQ:29600731
Copyright © 2021-2022 杭州汇骋科技有限公司. All rights reserved. 浙ICP备2021024418号