Created
June 12, 2020 18:42
-
-
Save Pamblam/99def16e272a2157fa544e5542300c93 to your computer and use it in GitHub Desktop.
detect all media queries in use..
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
(async function(d){ | |
console.clear(); | |
const styles = []; | |
const stylesheets = d.querySelectorAll("link[rel='stylesheet'][href]"); | |
// get all stylesheet urls | |
const stylesheet_urls = [...stylesheets].map(s=>s.href); | |
// fetch the contents of the stylesheets | |
const ss_promises = stylesheet_urls.map(href=>{ | |
return fetch(href).then(s=>s.text()).then(s=>{ | |
return { | |
source: href, | |
styles: s | |
}; | |
}); | |
}); | |
const ss_promises_resolved = await Promise.all(ss_promises); | |
styles.push(...ss_promises_resolved); | |
// get all the inline <style> tag contents | |
document.querySelectorAll('style').forEach(ele=>styles.push({ | |
source: "inline", | |
styles: ele.innerText | |
})); | |
styles.forEach(stylesheet=>{ | |
var media_queries = Array.from(stylesheet.styles.matchAll(/@media[^{]*/g), m => m[0].trim()); | |
if(!media_queries.length) return; | |
console.groupCollapsed(stylesheet.source); | |
[... new Set(media_queries)].forEach(mq=>console.log(mq)); | |
console.groupEnd(); | |
}); | |
})(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment