-
-
Save kawaz/daa5b304293a64ffabba7a27dbbec8e2 to your computer and use it in GitHub Desktop.
document.querySelectorAll のショートハンド関数。NodeList じゃなくて配列で返してくれます。::shadow に自前対応済み!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // const q = (s,r)=>[...(r||document).querySelectorAll(s)]; | |
| const q = (selector,root) => | |
| selector.split(/::shadow\s*/) | |
| .reduce((parents,selector,idx) => | |
| parents.flatMap(parent => | |
| selector=="" ? (idx==0?parent:parent.shadowRoot) : [...(idx==0?parent:parent.shadowRoot).querySelectorAll(selector)] | |
| ) | |
| , [root||document] | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
::shadowが深すぎて面倒なとき用の奴も作った(作り途中)https://gist.github.com/kawaz/391d03249c20286ce965e198e87ec356