51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
(function() {
|
|
var KssStateGenerator;
|
|
|
|
KssStateGenerator = (function() {
|
|
|
|
function KssStateGenerator() {
|
|
var idx, idxs, pseudos, replaceRule, rule, stylesheet, _i, _j, _len, _len1, _ref, _ref1;
|
|
pseudos = /(\:hover|\:disabled|\:active|\:visited|\:focus|\:target)/g;
|
|
try {
|
|
_ref = document.styleSheets;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
stylesheet = _ref[_i];
|
|
if (stylesheet.href.indexOf(document.domain) >= 0 || stylesheet.href[0] == '/') {
|
|
idxs = [];
|
|
_ref1 = stylesheet.cssRules;
|
|
for (idx = _j = 0, _len1 = _ref1.length; _j < _len1; idx = ++_j) {
|
|
rule = _ref1[idx];
|
|
if ((rule.type === CSSRule.STYLE_RULE) && pseudos.test(rule.selectorText)) {
|
|
replaceRule = function(matched, stuff) {
|
|
return matched.replace(/\:/g, '.pseudo-class-');
|
|
};
|
|
this.insertRule(rule.cssText.replace(pseudos, replaceRule));
|
|
}
|
|
pseudos.lastIndex = 0;
|
|
}
|
|
}
|
|
}
|
|
} catch (_error) {}
|
|
}
|
|
|
|
KssStateGenerator.prototype.insertRule = function(rule) {
|
|
var headEl, styleEl;
|
|
headEl = document.getElementsByTagName('head')[0];
|
|
styleEl = document.createElement('style');
|
|
styleEl.type = 'text/css';
|
|
if (styleEl.styleSheet) {
|
|
styleEl.styleSheet.cssText = rule;
|
|
} else {
|
|
styleEl.appendChild(document.createTextNode(rule));
|
|
}
|
|
return headEl.appendChild(styleEl);
|
|
};
|
|
|
|
return KssStateGenerator;
|
|
|
|
})();
|
|
|
|
new KssStateGenerator;
|
|
|
|
}).call(this);
|