Skip to content

Instantly share code, notes, and snippets.

@ebidel
Last active July 5, 2018 20:14
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ebidel/fcd9d17fb285591fd9ba3b65b500ed54 to your computer and use it in GitHub Desktop.
Save ebidel/fcd9d17fb285591fd9ba3b65b500ed54 to your computer and use it in GitHub Desktop.
Continuous custom element higlighter
// Continuously higlights the custom elements on the page. This is useful
// if new custom elements are lazy loaded later on or you have a SPA
// that uses other elements.
// CE finding code from: https://gist.github.com/ebidel/4bdbe9db55d8a775d0a4
(function() {
let cache = [];
function highlightCustomElements() {
if (cache.includes(location.href)) {
return;
}
cache.push(location.href);
let 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('*'));
allCustomElements.forEach(function(el, i) {
el.style.outline = '1px dashed red';
el.style.backgroundColor = 'rgba(255,0,0,0.1)';
});
}
setInterval(highlightCustomElements, 100);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment