forked from DirkPersky/criticalcss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookmark.js
1 lines (1 loc) · 1.85 KB
/
bookmark.js
1
javascript:void function () { (function () { if (typeof window.getMatchedCSSRules !== 'function') { window.getMatchedCSSRules = function (element) { var i, len, matching = [], sheets = document.styleSheets; function loopRules(rules) { var i, len, rule; for (i = 0, len = rules.length; i < len; i++) { rule = rules[i]; if (rule instanceof CSSMediaRule) { if (window.matchMedia(rule.conditionText).matches) { if(typeof rule.cssRules == 'object' && rule.cssRules.length > 0) { loopRules(rule.cssRules); } } } else if (rule instanceof CSSStyleRule) { if (element.matches(rule.selectorText)) { matching.push(rule); } } } }; for (i = 0, len = sheets.length; i < len; i++) { try { if(typeof sheets[i].cssRules == 'object' && sheets[i].cssRules.length > 0) { loopRules(sheets[i].cssRules); } } catch (err){ } } return matching; } } var e = function (e, t, n) { var r = n || {}, o = {}, i = function (e) { try { if(typeof o[e.selectorText] == 'undefined') { o[e.selectorText] = {}; } for (var t = e.style.cssText.split(/;(%3F![A-Za-z0-9])/), n = 0; n < t.length; n++) if (!!t[n] != !1) { var r = t[n].split(": "); r[0] = r[0].trim(), r[1] = r[1].trim(), o[e.selectorText][r[0]] = r[1] } } catch(err) { console.error('ERROR: in generating!! plz contact Dirk Persky'); } finally { console.warn('Scan Next Node'); } }, a = function () { for (var n = e.innerHeight, o = t.createTreeWalker(t, NodeFilter.SHOW_ELEMENT, function (e) { return NodeFilter.FILTER_ACCEPT }, !0); o.nextNode();) { var a = o.currentNode, c = a.getBoundingClientRect(); if (c.top < n || r.scanFullPage) { var l = e.getMatchedCSSRules(a); if (l) for (var f = 0; f < l.length; f++) i(l[f]) } } }; this.generateCSS = function () { var e = ""; for (var t in o) { e += t + " { "; for (var n in o[t]) e += n + ": " + o[t][n] + "; "; e += "}\n" } return e }, a() }, t = new e(window, document), n = t.generateCSS(); console.log(n) })() } ();