Harden forge NBC worker runtime and MVPD selection
This commit is contained in:
parent
3402f7dab2
commit
8065860449
4 changed files with 102 additions and 3 deletions
|
|
@ -816,6 +816,21 @@ fn advance_nbc_auth_flow(tab: &Arc<Tab>) -> Result<Option<NbcAuthAdvanceResult>>
|
|||
actions.push(action);
|
||||
return true;
|
||||
}};
|
||||
const pressEnter = (node) => {{
|
||||
if (!node) return false;
|
||||
for (const type of ["keydown", "keypress", "keyup"]) {{
|
||||
node.dispatchEvent?.(new KeyboardEvent(type, {{
|
||||
key: "Enter",
|
||||
code: "Enter",
|
||||
which: 13,
|
||||
keyCode: 13,
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}}));
|
||||
}}
|
||||
actions.push("press:enter");
|
||||
return true;
|
||||
}};
|
||||
const setValue = (node, value) => {{
|
||||
if (!node) return false;
|
||||
const prototype = Object.getPrototypeOf(node);
|
||||
|
|
@ -835,7 +850,7 @@ fn advance_nbc_auth_flow(tab: &Arc<Tab>) -> Result<Option<NbcAuthAdvanceResult>>
|
|||
const url = window.location.href || "";
|
||||
const candidates = Array.from(
|
||||
document.querySelectorAll(
|
||||
"button,a,[role='button'],label,li,div,span,[data-provider-name],[data-provider-id],[data-provider]"
|
||||
"button,a,[role='button'],[role='option'],label,li,[data-provider-name],[data-provider-id],[data-provider]"
|
||||
)
|
||||
);
|
||||
|
||||
|
|
@ -873,9 +888,24 @@ fn advance_nbc_auth_flow(tab: &Arc<Tab>) -> Result<Option<NbcAuthAdvanceResult>>
|
|||
}});
|
||||
if (input && normalize(input.value || "") !== normalize(provider)) {{
|
||||
setValue(input, provider);
|
||||
pressEnter(input);
|
||||
}}
|
||||
|
||||
const providerNode = candidates.find((node) => {{
|
||||
const inputRect = input?.getBoundingClientRect?.() || null;
|
||||
const searchNode = inputRect && candidates.find((node) => {{
|
||||
const text = textOf(node);
|
||||
const rect = node.getBoundingClientRect?.();
|
||||
if (!visible(node) || !rect) return false;
|
||||
const sameRow = Math.abs((rect.top + rect.height / 2) - (inputRect.top + inputRect.height / 2)) <= Math.max(48, inputRect.height);
|
||||
const nearRightEdge = rect.left >= inputRect.right - 24 && rect.left <= inputRect.right + 160;
|
||||
const looksLikeSearch = text.includes("search") || text.includes("find");
|
||||
const compactButton = rect.width <= 96 && rect.height <= Math.max(96, inputRect.height * 2);
|
||||
return (looksLikeSearch || compactButton) && sameRow && nearRightEdge;
|
||||
}});
|
||||
clickNode(searchNode, "click:provider-search");
|
||||
|
||||
const providerNode = candidates
|
||||
.filter((node) => {{
|
||||
const text = textOf(node);
|
||||
const providerMeta = normalize([
|
||||
node.getAttribute?.("data-provider-name") || "",
|
||||
|
|
@ -885,7 +915,8 @@ fn advance_nbc_auth_flow(tab: &Arc<Tab>) -> Result<Option<NbcAuthAdvanceResult>>
|
|||
return visible(node) && providerNeedles.some((needle) =>
|
||||
text.includes(needle) || providerMeta.includes(needle)
|
||||
);
|
||||
}});
|
||||
}})
|
||||
.sort((a, b) => textOf(a).length - textOf(b).length)[0];
|
||||
clickNode(providerNode, `click:provider:${{textOf(providerNode).slice(0, 120)}}`);
|
||||
}}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue