Last active
January 16, 2017 15:26
-
-
Save motss/5e6f5d857ac48865b9549294596c8901 to your computer and use it in GitHub Desktop.
Simple script to find custom elements on a page
This file contains 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
var foundCustomElements = []; | |
var foundCustomElementNames = []; | |
// main function to deeply find all custom elements on a page. | |
function getAllCustomElements(nodes) { | |
nodes.forEach(el => { | |
if (el.shadowRoot) getAllCustomElements(node.shadowRoot.querySelectorAll('*')); | |
if (el.localName.includes('-') || el.getAttribute('is') && el.getAttribute('is').includes('-')) { | |
foundCustomElements.push(el); | |
} | |
}); | |
} | |
// To querySelectorAll * to find all custom elements on a page. | |
getAllCustomElements(document.querySelectorAll('*')); | |
foundCustomElementNames = foundCustomElements.map(el => el.localName.includes('-') && el.localName || `${el.getAttribute('is')} (${el.localName})`).sort().filter((el, i, a) => i === a.indexOf(el)); | |
// console.log found custom elements. | |
console.info(`%cDone! %c${foundCustomElementNames.length} custom elements found on the page.`, 'color: #2196F3; font-size: 16px;', 'color: #E91E63; font-size: 16px;'); | |
console.log(foundCustomElementNames, foundCustomElements); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment