完善惊喜任务逐项执行和存储授权,兼容微信浏览入口及应用推荐下载落点。增加重复运行保护、投影恢复和任务完成复核,并保留原有安装适配。 验证:59项离线回归通过,生成文件一致性、语法及差异空白检查通过。
133 lines
8.8 KiB
JavaScript
133 lines
8.8 KiB
JavaScript
// 自绘页面仍由 OCR 判断;应用宝首页底部导航优先补充原生的精确文字和真实 bounds。
|
||
function nativeYibaoRecognition(page) {
|
||
if(!page || page.packageName!==CONFIG.yibaoPackage)return null;
|
||
var items=(page.items || []).filter(function(item){
|
||
var b=item.bounds;
|
||
return b && b.left>=0 && b.top>=0 && b.right<=device.width && b.bottom<=device.height &&
|
||
b.right>b.left && b.bottom>b.top && (item.text || item.desc);
|
||
}).map(function(item){
|
||
return {text:String(item.text || item.desc),bounds:item.bounds,centerX:item.centerX,centerY:item.centerY,
|
||
enabled:item.enabled,resourceId:item.resourceId,source:"native"};
|
||
});
|
||
var corpus=normalizeText(items.map(function(item){return item.text;}).join(""));
|
||
// 只看到底栏不代表读到了自绘任务正文,不能据此宣告任务入口消失。
|
||
if(/广告|点击后.*秒|恭喜|现在退出|任务未完成|继续做任务/.test(corpus))return null;
|
||
if(findNativeYibaoMoneyEntry({packageName:page.packageName,items:items},[]) &&
|
||
/热门软件|热门游戏|新游日历/.test(corpus))return {kind:"首页底栏",items:items};
|
||
var actions=items.filter(function(item){return /^(去观看|去完成|去领取|领取|去下载|去浏览|去清理|打开)$/.test(normalizeText(item.text));});
|
||
if(isYibaoTaskCenter(items) && items.length>=8 && actions.length>=2)return {kind:"完整任务正文",items:items};
|
||
return null;
|
||
}
|
||
function isYibaoTaskCenter(items) {
|
||
items = items || [];
|
||
var corpus = normalizeText(items.map(function (item) { return String(item.text || ""); }).join(""))
|
||
.replace(/賺/g,"赚").replace(/赚积[枳积]?分/g,"赚积分");
|
||
// 保留原有顶部多特征规则;另外兼容列表滚到特别任务区域、顶部标题不在屏幕内。
|
||
var markers = [["任务中心"], ["积分兑好礼", "积分兑豪礼"], ["每日福利签到"],
|
||
["看视频赚积分"], ["限时应用专区"], ["我的积分"], ["可兑现金", "可兌现金"]];
|
||
var hits = markers.filter(function (aliases) {
|
||
return aliases.some(function (label) { return corpus.indexOf(label) >= 0; });
|
||
}).length;
|
||
if (hits >= 2) return true;
|
||
var labels = items.map(function (item) { return normalizeText(item.text).replace(/賺/g, "赚"); });
|
||
var footer = items.filter(function (item) {
|
||
return item.bounds && item.bounds.top >= device.height * .9 && item.bounds.bottom <= device.height;
|
||
}).map(function (item) { return normalizeText(item.text).replace(/賺/g, "赚"); });
|
||
var navCount = ["首页", "秒玩", "赚钱", "商城", "我的"].filter(function (label) { return footer.indexOf(label) >= 0; }).length;
|
||
var heading = labels.some(function (label) { return /^(?:特别任务赚积分|惊喜任务赚积分(?:兑[好豪]礼)?)$/.test(label); });
|
||
var rows = labels.filter(function (label) {
|
||
return /^(?:浏览|浏覧).+15秒$|^每日完成手机垃圾清理$|^去快影看视频赚积分$|^去酷狗听音乐赚金币$/.test(label);
|
||
}).length;
|
||
var deepList = navCount >= 3 && heading && rows >= 2;
|
||
if (deepList) log("通过底部导航、任务分区标题及多条任务确认赚钱列表,保留当前滚动位置");
|
||
return deepList;
|
||
}
|
||
|
||
function findNativeYibaoMoneyEntry(page, ocrItems) {
|
||
if (!page || page.packageName !== CONFIG.yibaoPackage) return null;
|
||
var items = page.items || [];
|
||
var corpus = items.concat(ocrItems || []).map(function (item) {return normalizeText(item.text || item.desc || "");}).join("");
|
||
if (/任务未完成|现在退出|恭喜|奖励还差|继续做任务得额外奖励/.test(corpus)) return null;
|
||
var footer = items.filter(function (item) {
|
||
return item.enabled !== false && item.bounds && item.bounds.left >= 0 && item.bounds.right <= device.width &&
|
||
item.bounds.bottom <= device.height && item.centerY >= device.height * .90;
|
||
});
|
||
var labels = footer.map(function (item) {return normalizeText(item.text || item.desc);});
|
||
// 应用宝会恢复到小游戏等首页分栏,不一定有热门软件/热门游戏标题。
|
||
// 仍要求完整底栏中的至少三个其他标签,不能把广告中的“赚钱”当导航。
|
||
if (["首页", "秒玩", "商城", "我的"].filter(function (label) {return labels.indexOf(label) >= 0;}).length < 3) return null;
|
||
var entries = footer.filter(function (item) {return normalizeText(item.text || item.desc) === "赚钱";});
|
||
return entries.length === 1 ? entries[0] : null;
|
||
}
|
||
function supplementYibaoNavigation(items) {
|
||
if (!items) return items;
|
||
var entry = findNativeYibaoMoneyEntry(readCommonInstallPage(), items);
|
||
if (!entry) return items;
|
||
var alreadyExact = items.some(function (item) {
|
||
return normalizeText(item.text) === "赚钱" && Math.abs(item.centerY - entry.centerY) < 40;
|
||
});
|
||
if (alreadyExact) return items;
|
||
log("首页底部赚钱使用原生文字补充 OCR,bounds=" + JSON.stringify(entry.bounds));
|
||
return items.concat([{text:"赚钱",bounds:entry.bounds,centerX:entry.centerX,centerY:entry.centerY,enabled:true,source:"native"}]);
|
||
}
|
||
|
||
function yibaoTaskRowKind(text) {
|
||
text=normalizeText(text);
|
||
var suffix=text.match(/.+(去观看|去浏览|去下载|去清理|领积分)$/);
|
||
if(suffix)return suffix[1];
|
||
if(/^看精彩视[频頻].*领积分/.test(text))return "去观看";
|
||
if(/^每日下载(?:一)?次软件/.test(text))return "去下载";
|
||
if(/^每日完成手机垃圾[清漬]理/.test(text))return "去清理";
|
||
if(/^浏览.+15/.test(text))return "去浏览";
|
||
return "";
|
||
}
|
||
function yibaoTaskColumnAction(text,kind) {
|
||
text=normalizeText(text).replace(/去漬理/g,"去清理");
|
||
if(text.length<=6 && /领积分$/.test(text))return "领积分";
|
||
if(kind==="去观看" && /^\d*(?:去观看|去观|去看)$/.test(text))return kind;
|
||
if(kind==="去下载" && text.length<=8 && /下载$/.test(text))return kind;
|
||
if(kind==="去浏览" && text.length<=6 && /(?:去浏览|去刘览|刘览|浏览)$/.test(text))return kind;
|
||
if(kind==="去清理" && /^(?:去)?[清漬]理$/.test(text))return kind;
|
||
return /^(去观看|去浏览|去下载|领积分|去清理)$/.test(text)?text:"";
|
||
}
|
||
function recognizeYibaoTaskButtonRows(anchors) {
|
||
var frame=captureCurrentScreen(),found=[];
|
||
try {
|
||
anchors.forEach(function(anchor){
|
||
var kind=yibaoTaskRowKind(anchor.text),left=Math.round(device.width*.77);
|
||
var top=Math.max(0,Math.floor(anchor.bounds.top-12));
|
||
var bottom=Math.min(device.height,Math.ceil(anchor.bounds.bottom+12));
|
||
if(bottom<=top)return;
|
||
var crop=null,enlarged=null;
|
||
try {
|
||
crop=images.clip(frame,left,top,device.width-left,bottom-top);
|
||
enlarged=images.resize(crop,[(device.width-left)*3,(bottom-top)*3]);
|
||
var raw=recognizeWithAvailableEngine(enlarged);
|
||
var local=listOcrItems(raw).map(normalizeOcrItem).filter(function(item){return !!item;});
|
||
log("惊喜任务右侧按钮局部识别:"+anchor.text+" -> "+local.map(function(item){return item.text;}).join(" | "));
|
||
var candidates=local.map(function(item){
|
||
var action=yibaoTaskColumnAction(item.text,kind);if(!action)return null;
|
||
var b=item.bounds,bounds={left:left+b.left/3,top:top+b.top/3,right:left+b.right/3,bottom:top+b.bottom/3};
|
||
return {text:action,originalText:item.text,bounds:bounds,centerX:(bounds.left+bounds.right)/2,
|
||
centerY:(bounds.top+bounds.bottom)/2,source:"task-column",rowTitle:anchor.text};
|
||
}).filter(function(item){return item && Math.abs(item.centerY-anchor.centerY)<device.height*.025;});
|
||
if(candidates.length===1)found.push(candidates[0]);
|
||
}finally{if(enlarged && enlarged.recycle)enlarged.recycle();if(crop && crop.recycle)crop.recycle();}
|
||
});
|
||
}finally{if(frame && frame.recycle)frame.recycle();}
|
||
return found;
|
||
}
|
||
function supplementYibaoTaskButtons(items) {
|
||
if(!items || !activeYibaoFlow || activeYibaoFlow.id!=="3")return items;
|
||
var actions=/^(去观看|去浏览|去下载|领积分|去清理)$/;
|
||
var anchors=items.filter(function(item){
|
||
if(!item.bounds || item.bounds.top<device.height*.08 || item.bounds.bottom>device.height*.94)return false;
|
||
var text=normalizeText(item.text);
|
||
if(/已领取|己领取|已完成/.test(text) || actions.test(text))return false;
|
||
if(!yibaoTaskRowKind(text) && !/.+(?:去观看|去浏览|去下载|去清理)$/.test(text))return false;
|
||
return !items.some(function(button){return actions.test(normalizeText(button.text)) &&
|
||
Math.abs(button.centerY-item.centerY)<device.height*.025;});
|
||
}).slice(0,5);
|
||
return anchors.length?items.concat(recognizeYibaoTaskButtonRows(anchors)):items;
|
||
}
|