Skip to content

Instantly share code, notes, and snippets.

@ebidel
Last active June 13, 2022 21:35
Show Gist options
  • Save ebidel/4bdbe9db55d8a775d0a4 to your computer and use it in GitHub Desktop.
Save ebidel/4bdbe9db55d8a775d0a4 to your computer and use it in GitHub Desktop.
Bookmarklet for highlight custom elements on a page
// Highlights all custom elements on the page.
// 7/31/2016: updated to work with both shadow dom v0 and v1.
// To create a bookmarklet, use http://ted.mielczarek.org/code/mozilla/bookmarklet.html
var 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)';
});
javascript:(function(){var allCustomElements=[];function isCustomElement(el){const isAttr=el.getAttribute('is');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(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)';});})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment