Skip to content

Instantly share code, notes, and snippets.

@tomalec
Last active November 30, 2017 12:32
Show Gist options
  • Select an option

  • Save tomalec/47f0acd910a729d0b6a2e55061e5c26e to your computer and use it in GitHub Desktop.

Select an option

Save tomalec/47f0acd910a729d0b6a2e55061e5c26e to your computer and use it in GitHub Desktop.
Find stylesheets in all HTML Imports, as they are now deprecated https://github.com/TakayoshiKochi/deprecate-style-in-html-imports
<a href="javascript:(function(){var%20screl=document.createElement('script');screl.setAttribute('type','text/javascript');screl.setAttribute('src','https://gist.githubusercontent.com/tomalec/47f0acd910a729d0b6a2e55061e5c26e/raw/4843f8a32d971f0465871a2d26cf6cc5c88e1229/findStylesheetsInAllHTMLImports.js');document.body.appendChild(screl);})();">Find HTML Imported styles bookmarklet</a>
function findStylesheetsInImportedDocs(doc, map) {
map = map || {};
// map = map || new Map();
Array.prototype.forEach.call(doc.querySelectorAll('link[rel=import]'), (e) => {
const importedDoc = e.import;
if (importedDoc && !map[importedDoc]) {
const styles = importedDoc.querySelectorAll('style,link[rel=stylesheet]');
if (styles.length) {
map[importedDoc.URL] = {
doc: importedDoc,
styles: styles
};
// map.set(importedDoc, styles);
}
findStylesheetsInImportedDocs(importedDoc, map)
}
});
return map;
}
console.log(findStylesheetsInImportedDocs(document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment