fix: 兼容非滚动规格确认面板 (#275)
This commit is contained in:
@@ -512,6 +512,9 @@ def _find_non_scrollable_spec_panel(
|
||||
node.get("package") == PDD_PACKAGE_NAME
|
||||
for node in root.iter("node")
|
||||
)
|
||||
is_order_confirmation = (
|
||||
classify_pdd_page(root, "").kind == PAGE_ORDER_CONFIRMATION
|
||||
)
|
||||
|
||||
headings: list[ET.Element] = []
|
||||
summaries: list[ET.Element] = []
|
||||
@@ -546,9 +549,12 @@ def _find_non_scrollable_spec_panel(
|
||||
and screen_bottom
|
||||
and (bounds[1] + bounds[3]) // 2 >= screen_bottom * 0.6
|
||||
and "提交订单" in descendant_label
|
||||
and any(
|
||||
word in descendant_label
|
||||
for word in ("选择", "颜色", "尺码", "规格")
|
||||
and (
|
||||
is_order_confirmation
|
||||
or any(
|
||||
word in descendant_label
|
||||
for word in ("选择", "颜色", "尺码", "规格")
|
||||
)
|
||||
)
|
||||
):
|
||||
submit_hints.append(node)
|
||||
@@ -563,17 +569,23 @@ def _find_non_scrollable_spec_panel(
|
||||
if compact == "增加数量" and node.get("clickable") == "true":
|
||||
increases.append(node)
|
||||
|
||||
if not headings or not summaries or not panel_cues:
|
||||
return None
|
||||
if confirms:
|
||||
action_nodes = [confirms[0]]
|
||||
elif (
|
||||
pdd_node_count >= 3
|
||||
strong_confirmation_evidence = (
|
||||
is_order_confirmation
|
||||
and pdd_node_count >= 3
|
||||
and len(submit_hints) == 1
|
||||
and len(quantity_editors) == 1
|
||||
and len(decreases) == 1
|
||||
and len(increases) == 1
|
||||
):
|
||||
)
|
||||
if not headings or not summaries:
|
||||
return None
|
||||
# 部分新版确认页会把“确认款式/关闭”滚出当前视口。只有页面分类和
|
||||
# 下面的数量、提交区域证据同时成立时,才允许缺少顶部提示。
|
||||
if not panel_cues and not strong_confirmation_evidence:
|
||||
return None
|
||||
if confirms:
|
||||
action_nodes = [confirms[0]]
|
||||
elif strong_confirmation_evidence:
|
||||
action_nodes = [
|
||||
submit_hints[0],
|
||||
quantity_editors[0],
|
||||
@@ -583,7 +595,9 @@ def _find_non_scrollable_spec_panel(
|
||||
else:
|
||||
return None
|
||||
|
||||
required = [*headings, summaries[0], panel_cues[0], *action_nodes]
|
||||
required = [*headings, summaries[0], *action_nodes]
|
||||
if panel_cues:
|
||||
required.append(panel_cues[0])
|
||||
common = set([required[0], *_ancestors(required[0], parents)])
|
||||
for node in required[1:]:
|
||||
common.intersection_update([node, *_ancestors(node, parents)])
|
||||
@@ -595,17 +609,22 @@ def _find_non_scrollable_spec_panel(
|
||||
)
|
||||
|
||||
candidates: list[tuple[int, ET.Element]] = []
|
||||
full_screen_candidates: list[tuple[int, ET.Element]] = []
|
||||
for node in common:
|
||||
bounds = _parse_bounds(node.get("bounds", ""))
|
||||
if bounds is None or node.get("visible-to-user", "true") != "true":
|
||||
continue
|
||||
area = (bounds[2] - bounds[0]) * (bounds[3] - bounds[1])
|
||||
if screen_area and area >= screen_area * 0.95:
|
||||
if strong_confirmation_evidence:
|
||||
full_screen_candidates.append((area, node))
|
||||
continue
|
||||
candidates.append((area, node))
|
||||
if not candidates:
|
||||
return None
|
||||
return min(candidates, key=lambda item: item[0])[1]
|
||||
if candidates:
|
||||
return min(candidates, key=lambda item: item[0])[1]
|
||||
if full_screen_candidates:
|
||||
return min(full_screen_candidates, key=lambda item: item[0])[1]
|
||||
return None
|
||||
|
||||
|
||||
def _is_spec_panel_open(xml_data: str | bytes) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user