Skip to content

Instantly share code, notes, and snippets.

@bultas
Created December 13, 2018 20:31
Show Gist options
  • Save bultas/8640b40e70716dea1bfc6afdde50fab9 to your computer and use it in GitHub Desktop.
Save bultas/8640b40e70716dea1bfc6afdde50fab9 to your computer and use it in GitHub Desktop.
Find custom elements
const allCustomElements = [];
function isCustomElement(el) {
const isAttr = el.getAttribute('is');
// Check for <super-button> and <button is="super-button">.
return el.localName.includes('-') || isAttr && isAttr.includes('-');
}
function findAllCustomElements(nodes) {
for (let i = 0, el; el = nodes[i]; ++i) {
if (isCustomElement(el)) {
allCustomElements.push(el);
}
// If the element has shadow DOM, dig deeper.
if (el.shadowRoot) {
findAllCustomElements(el.shadowRoot.querySelectorAll('*'));
}
}
}
findAllCustomElements(document.querySelectorAll('*'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment