Last active
August 29, 2015 14:07
-
-
Save d4rkr00t/12f4507d881038b94d65 to your computer and use it in GitHub Desktop.
Dev Tools Snippet for getting all Media Queries on 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 _pairs = function(obj) { | |
var resArr = []; | |
for (k in obj) { | |
if(obj.hasOwnProperty(k)) { | |
resArr.push([k, obj[k]]); | |
} | |
} | |
return resArr; | |
}; | |
var _getRules = function (styles) { | |
var mq = {}; | |
for (var i = 0, max = styles.length; i < max; i++) { | |
for (var j = 0, max2 = styles[i].rules.length; j < max2; j++) { | |
var rule = styles[i].rules[j]; | |
if (rule.media) { | |
mq[rule.media.mediaText] = | |
mq[rule.media.mediaText] ? | |
mq[rule.media.mediaText] + 1 : | |
1; | |
} | |
} | |
} | |
return mq; | |
}; | |
var _displayResults = function (result) { | |
for (var i = 0, max = result.length; i < max; i++) { | |
console.log(result[i][0] + ' — ' + result[i][1]); | |
} | |
}; | |
_displayResults( | |
_pairs(_getRules(document.styleSheets)).sort(function(a, b) { | |
if (a[1] > b[1]) return -1; | |
if (a[1] < b[1]) return 1; | |
return 0; | |
}) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment