【Lua】淘金币自动浏览任务

环境

运行环境:LuaBox/积木编程(软件自行百度下载)
运行系统:安卓 5 以上,无需 ROOT

功能介绍

脚本功能:自动打开淘宝>>打开金币庄园>>领取浏览任务>>领金币
脚本语言:Lua
脚本原理:通过安卓无障碍权限获取界面控件节点属性信息查找界面元素进行点击
因为网速或者设备性能原因,只需要 15 秒的任务,我等待的时间比较长
但是仍然不排除会出现卡住的情况,只能算是个半自动脚本吧
开发软件过程中测试用的,在华为 P30 Pro 上运行还可以

pkgname = app.getPackageName("淘宝")
app.runApp(pkgname)
mSleep(3000)
while true do
    device.keepWake()
    local get = widget.find({["text"]="领取奖励"})
    if get ~= nil then
        toast("领取奖励")
        widget.click(get)
        mSleep(3000)
    else
        --[[local complete = widget.find({["text"]="去完成"})
    if complete ~= nil then
    toast("去完成")
    widget.click(complete)
    mSleep(30*1000)
    keycode.back()
    mSleep(5000)--]]
        local skim = widget.find({["text"]="浏览",["rule"]=2})
        if skim ~= nil then
        x1,y1,x2,y2 = widget.region(skim)
        if x1 ~= -1 then
        x = x1 + 700
        y = y1 - 18
        toast("浏览任务")
        event.tap(x,y)
        local back = widget.find({["text"]="任务已完成"})
        local t0 = os.time()
        local t1 = os.time()
        if back ~= nil or t1 - t0 >= 35 then
        keycode.back()
        mSleep(3000)
    end
    end
    else
        local mytb =  widget.find({["desc"]="我的淘宝"})
        if  mytb ~= nil then
        toast("我的淘宝")
        widget.click(mytb)
        mSleep(3000)
    end
    end
        local enter =  widget.find({["text"]="淘金币",["path"]="/FrameLayout/LinearLayout/FrameLayout/LinearLayout/FrameLayout/FrameLayout/FrameLayout/RelativeLayout/LinearLayout/RecyclerView/FrameLayout/FrameLayout/RecyclerView/FrameLayout/TextView"})
        if  enter ~= nil then
        x1,y1,x2,y2 = widget.region(enter)
        if x1 ~= -1 then
        x = (x1+x2)/2
        y = (y1+y2)/2
        toast("淘金币")
        event.tap(x,y)
        mSleep(10000)
    end
    end
    end
        local earn = widget.find({["text"]="赚金币",["path"]="/FrameLayout/LinearLayout/FrameLayout/ViewGroup/FrameLayout/WebView/bb/WebView/View/View/View/View/View/ListView/View/Button"})
        if earn ~= nil then
        toast("赚金币")
        widget.click(earn)
        mSleep(3000)
    end
    end

 

赞 (0)