-
-
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
あ、自分は使ってなかったので漏れてたけどカンマ区切りセレクタには未対応だね。対応は難しくないけどまーいいや。