mirror of
https://github.com/tridactyl/tridactyl.git
synced 2026-09-10 07:16:33 -04:00
Merge pull request #5262 from Chic-Tweetz/hint-nested-shadows
Hint nested & closed shadows
This commit is contained in:
commit
c0b902fb8d
|
|
@ -336,11 +336,19 @@ export function getSelector(e: HTMLElement) {
|
|||
/* Get all the elements that match the given selector inside shadow DOM */
|
||||
function getShadowElementsBySelector(selector: string) {
|
||||
let elems = []
|
||||
document.querySelectorAll("*").forEach(elem => {
|
||||
if (elem.shadowRoot) {
|
||||
elems = elems.concat(...elem.shadowRoot.querySelectorAll(selector))
|
||||
}
|
||||
})
|
||||
const roots: (Document | ShadowRoot)[] = [document]
|
||||
|
||||
while (roots.length) {
|
||||
const root = roots.pop()
|
||||
root.querySelectorAll("*").forEach(elem => {
|
||||
if ((elem as any).openOrClosedShadowRoot) {
|
||||
roots.push((elem as any).openOrClosedShadowRoot)
|
||||
elems = elems.concat(
|
||||
...roots[roots.length - 1].querySelectorAll(selector),
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
return elems
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue