// 相同位置存在原生控件时使用原生点击,避免坐标被系统无障碍悬浮按钮截获。 function tryNativeYibaoOcrClick(match, x, y) { if (typeof text !== "function") return false; try { var foreground = getForegroundApp(); if (!foreground || (foreground.packageName !== CONFIG.yibaoPackage && !isInstallerForeground(foreground))) return false; var label = String(match.item.text || ""); if (!label) return false; var node = text(label).packageName(foreground.packageName).findOnce(); if (!node || !node.enabled() || !node.visibleToUser()) return false; var rect = node.bounds(); // 同名但位于别处的控件不能替代 OCR 刚确认的目标。 if (x < rect.left - 16 || x > rect.right + 16 || y < rect.top - 16 || y > rect.bottom + 16) return false; for (var depth = 0; node && depth < 4; depth += 1) { rect = node.bounds(); if (rect.height() > device.height * .30 || rect.width() <= 0 || rect.height() <= 0 || !node.enabled() || !node.visibleToUser()) return false; if (node.clickable() && node.click()) { log("相同位置原生控件点击成功:" + label + " bounds=" + rect); return true; } node = node.parent(); } } catch (error) { log("原生文字点击不可用,沿用已确认的 OCR 位置:" + errorText(error)); } return false; } function clickOcrMatch(match, offsetYRatio) { var offset = offsetYRatio || 0; var x = Math.max(1, Math.min(device.width - 1, Math.round(match.item.centerX))); var y = Math.max(1, Math.min(device.height - 1, Math.round(match.item.centerY + device.height * offset))); log("点击 text=" + match.item.text + " target=" + match.target + " bounds=" + JSON.stringify(match.item.bounds)); var before = logForegroundApp("点击前"); if (offset !== 0 || !tryNativeYibaoOcrClick(match, x, y)) click(x, y); observeAfterAction("点击 " + match.target, before); return true; }