forked from TonyJiangWJ/AutoScriptBase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4bc51f2
commit 2e0b8a0
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
let sRequire = require('../lib/SingletonRequirer')(runtime, this) | ||
let automator = sRequire('Automator') | ||
let widgetUtils = sRequire('WidgetUtils') | ||
let logUtils = sRequire('LogUtils') | ||
|
||
let bottomWidget = widgetUtils.widgetGetById('com.tencent.mm:id/czl') | ||
let bottomHeight = device.height - 160 | ||
if (bottomWidget) { | ||
bottomHeight = bottomWidget.bounds().top | ||
} | ||
|
||
function checkAndClick() { | ||
let target = widgetUtils.widgetGetById('com.tencent.mm:id/ga3') | ||
if (target && target.bounds().top < bottomHeight) { | ||
automator.clickCenter(target) | ||
sleep(1000) | ||
automator.back() | ||
return true | ||
} else { | ||
return false | ||
} | ||
} | ||
|
||
function getUnreadInfo() { | ||
let target = widgetUtils.widgetGetById('android:id/text1') | ||
if (target) { | ||
let content = target.desc() || target.text() | ||
let regex = /微信.*(\d+)/ | ||
if (regex.test(content)) { | ||
let unreadCount = parseInt(regex.exec(content)[1]) | ||
logUtils.debugInfo(['未读数据: {}', unreadCount]) | ||
return unreadCount | ||
} else { | ||
logUtils.warnInfo(['未匹配到未读数据: {}', content]) | ||
} | ||
} | ||
logUtils.debugInfo(['未找到未读数据']) | ||
return 0 | ||
} | ||
|
||
while (getUnreadInfo() > 0) { | ||
while(checkAndClick()) { | ||
sleep(500) | ||
} | ||
automator.scrollDown() | ||
} |