Skip to content

Instantly share code, notes, and snippets.

@asumaran
Created September 30, 2013 04:42
Show Gist options
  • Save asumaran/6759450 to your computer and use it in GitHub Desktop.
Save asumaran/6759450 to your computer and use it in GitHub Desktop.
(function () {
var e = {}, t = {}, n = 0,
r = {
refreshStylesheets: function () {
function i(e) {
var t = document.location,
n = new RegExp("^\\.|^/(?!/)|^[\\w]((?!://).)*$|" + t.protocol + "//" + t.host);
return e.match(n)
}
var n = document.getElementsByTagName("head")[0],
r = document.getElementById("LPCodeKitLiveTransitionRule");
r && n.removeChild(r);
var s = document.styleSheets,
o = document.styleSheets.length;
for (var u = 0; u < o; u++) {
var a = s[u];
if (!a) continue;
var f = a.media.mediaText,
l = f.search(/print/i);
if (l !== -1) continue;
var c = a.href;
if (!c) continue;
if (!i(c)) continue;
var h = c.split("?now=")[0],
p = a.ownerNode,
d = p.nextSibling,
v = document.createElement("link");
v.setAttribute("type", "text/css");
v.setAttribute("rel", "stylesheet");
v.setAttribute("href", h + "?now=" + new Date * 1);
d ? n.insertBefore(v, d) : n.appendChild(v);
e[h] = v;
t[h] = p
}
},
removeOldLinkElements: function () {
if (n > 130) return;
var i = 0;
for (var s in t) {
try {
var o = e[s],
u = t[s],
a = o.sheet || o.styleSheet,
f = a.rules || a.cssRules;
if (f.length >= 0) {
n = 0;
u.parentNode.removeChild(u);
delete t[s]
}
} catch (l) {
n++;
i++
}
i && setTimeout(r.removeOldLinkElements, 50)
}
},
removeoldLinkElementsInChromeWithFileURL: function () {
for (var e in t) {
var n = t[e];
n.parentNode.removeChild(n);
delete t[e]
}
}
};
r.refreshStylesheets();
var i = navigator.userAgent.toLowerCase().indexOf("chrome") > -1,
s = document.URL.indexOf("file://") > -1;
i && s ? setTimeout(r.removeoldLinkElementsInChromeWithFileURL, 400) : r.removeOldLinkElements()
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment