Skip to content

Commit

Permalink
Refactor function getAptContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
david-tejada committed Jan 9, 2024
1 parent 3bde0e0 commit 4237df5
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions src/content/hints/getContextForHint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,28 +171,23 @@ export function getAptContainer(origin: Element) {

if (!(current instanceof HTMLElement) || current.shadowRoot) {
current = current.parentNode;
continue;
}

const { display } = getCachedStyle(current);

if (
current.matches("thead, tbody, tfoot, caption, colgroup, col, tr, th, td")
) {
current = current.closest("table") ?? current.parentElement;
continue;
}

if (current.tagName === "TABLE" || display.startsWith("table")) {
current = current.parentElement;
continue;
}

if (current.tagName !== "DETAILS" && display !== "contents") {
return current;
} else {
const { display } = getCachedStyle(current);

if (
current.matches(
"thead, tbody, tfoot, caption, colgroup, col, tr, th, td"
)
) {
current = current.closest("table") ?? current.parentElement;
} else if (current.tagName === "TABLE" || display.startsWith("table")) {
current = current.parentElement;
} else if (current.tagName !== "DETAILS" && display !== "contents") {
return current;
} else {
current = current.parentElement;
}
}

current = current.parentElement;
}

return document.body;
Expand Down

0 comments on commit 4237df5

Please sign in to comment.