The last part of autojs commonly used function functions.

Join our QQ group 553908361 , and communicate with each author in the same group.
One-click add group: click to add group.
This tutorial will be published in the paid script v group first.
Part of the code is collected on the Internet (now I don’t know who the author is). If there is any infringement, please
send me a private message to delete the last commonly used function function of autojs.
Adapt to Android 5 to 9 Note that you can customize the name of these functions. Simple to your favorite name, Chinese functions are also available
Insert picture description here

base64 encryption and decryption

function FuckYourFamily(str) {
    
    
    return java.lang.String(android.util.Base64.decode(java.lang.String(str).getBytes(), 0));
}
//调用方式,直接  FuckYourFamily(str) 即可,其中str为base64加密

Adapt to Android 5 to 9. If you have root, you will click or slide with root.

function 滑动(x1, y1, x2, y2,time){
    
    
    if(device.sdkInt<24){
    
    
        Swipe(x1, y1, x2, y2,time)
    }else{
    
    
        swipe(x1, y1, x2, y2,time)
    }
}
function 点击(x,y){
    
    
    if(device.sdkInt<24){
    
    
        Tap(x,y)
    }else{
    
    
        click(x,y)
    }
}
function home(){
    
    
    if(device.sdkInt<24){
    
    
        Home()
    }else{
    
    
       home()
    }
}
function back(){
    
    
    if(device.sdkInt<24){
    
    
        Back()
    }else{
    
    
       back()
    }
}

/** * Controls that cannot be clicked, click by coordinates * @param {*} uiSelector */

function clickUiBounds(ui) {
    
    
    if (ui.exists()) {
    
    
        var a = ui.findOnce();
        if (a) {
    
    
            var b = a.bounds();
            if (b) {
    
    
                click(b.centerX(), b.centerY());
                return true;
            }
        }

    }
    return false;
}

Configuration read and write

function 写配置(文件名,,) {
    
    
    const storage = storages.create(文件名);
    storage.put(,);
}
function 读配置(文件名,, 默认值) {
    
    
    const storage = storages.create(文件名);
    if (storage.contains()) {
    
    
        return storage.get(, 默认值);
    };
    写配置(文件名,, 默认值);
    return 默认值;
}

Text manipulation

function 到文本(数值) {
    
    
    return 数值 + ""
}

function 到整数(文本) {
    
    
    return 文本 * 1
}

function 随机数(min, max) {
    
    
    return Math.floor(Math.random() * (max - min + 1)) + min
}
//log(随机数(1,5))


function 子文本替换(原始文本, 欲被替换的文本, 用作替换的文本) {
    
    
    return 原始文本.replace(eval("/" + 欲被替换的文本 + "/g"), 用作替换的文本)
}
log(子文本替换("1234567890", "123", "qwe"))
function 取文本中间(str, firstStr, secondStr) 
//字符串,开头,结尾
{
    
    
    if (firstStr == "") {
    
     str = "**" + str; firstStr = "**" }
    if (secondStr == "") {
    
     str = str + "**"; secondStr = "**" }
    if (str == "" || str == null || str == undefined) {
    
    
        return "";
    }
    if (str.indexOf(firstStr) < 0) {
    
    
        return "";
    }
    var subFirstStr = str.substring(str.indexOf(firstStr) + firstStr.length, str.length);
    var subSecondStr = subFirstStr.substring(0, subFirstStr.indexOf(secondStr));
    return subSecondStr;}

Determine whether the system is ROOT

function isRoot() {
    
    
    var r = shell("ls /system/bin", true).result.toString()
    if (r.length > 50) {
    
    
        return true
    } else {
    
    
        return false
    }
}

Determine network status

function networkInfo() {
    
    
    importClass(android.net.ConnectivityManager);
    var mConnectivityManager = context.getSystemService(context.CONNECTIVITY_SERVICE);
    netInfo = mConnectivityManager.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isAvailable()) {
    
    
        /网络连接
        var name = netInfo.getTypeName();
        if (netInfo.getType() == ConnectivityManager.TYPE_WIFI) {
    
    
            /WiFi网络
            return "WIFI"
        } else if (netInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
    
    
            /有线网络
            return "有线"

        } else if (netInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
    
    
            /3g网络
            return "移动"

        }
        else {
    
    
            return "未知"
        }
    } else {
    
    
        网络断开
        return "断开"
    }
}

Clear cache

checkSpace()
function clickUi(ui) {
    
    
    if (ui.exists()) {
    
    
        var a = ui.findOnce();
        if (a) {
    
    
            var b = a.bounds();
            if (b) {
    
    
                click(b.centerX(), b.centerY());
                return true;
            }
        }

    }
    return false;
}
//清理缓存,如果缓存空间不足
function checkSpace() {
    
    
    if (textStartsWith('存储空间').exists() && text('取消').exists()) {
    
    
        var o = text('取消').findOnce();
        if (o) {
    
    
         clickui(o);
           sleep(1000);
        }

        if (device.sdkInt>24) {
    
    
            var intent = new Intent();
            intent.setAction("android.settings.INTERNAL_STORAGE_SETTINGS"); //MEMORY_CARD_SETTINGS
            app.startActivity(intent);
            sleep(3000);


            var o = text('缓存数据').findOnce();    //小米
            if (o) {
    
    
              clickui(o);
              sleep(1000);
                if (text('取消').exists() && text('确定').exists()) {
    
    
                    var o = text('确定').findOnce();
                clickui(o);
            sleep(10000);
                }
            }

         swipe(100,200,100,500,500);//z注意,这里需要修改.这里是用于滑动的
            var o = text('垃圾清理').findOnce();    //小米
            if (o.length > 0) {
    
    
                // clickObject(o[o.length - 1]);
                o.click()
                sleep(3000);
                var iii = 10;
                while (iii-- > 0) {
    
    
                    if (textStartsWith('清理选中垃圾').exists()) {
    
    
                        var o = textStartsWith('清理选中垃圾').findOnce();
                       o.click()
                  sleep(5000);
                    back();
                        break;
                    }
                    else
                      sleep(5000);
                }
            }
        }
        else {
    
    
            app.startActivity({
    
    
                action: "android.settings.INTERNAL_STORAGE_SETTINGS",
                root: true
            });
       sleep(8000);

            var o = text('缓存数据').findOnce();    //小米
            if (o) {
    
    
                o.click();
           sleep(1000);
                if (text('取消').exists() && text('确定').exists()) {
    
    
                    var o = text('确定').findOnce();
                 clickui(o);
              sleep(10000);
                }
            }
        }

       back();
    }
}

Guess you like

Origin blog.csdn.net/qq_30931547/article/details/108845590