forked from cjss-group/CJSS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcjss.js
37 lines (37 loc) · 1.31 KB
/
cjss.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
document.addEventListener('DOMContentLoaded', function (event) {
(function () {
var l = document.styleSheets.length;
for (var i = 0; i < l; ++i) {
var sheet = document.styleSheets && document.styleSheets[i];
if (sheet) {
var r = sheet.rules ? sheet.rules : sheet.cssRules;
if (r) {
for (var j = 0; j < r.length; ++j) {
var js = r[j].style.getPropertyValue('--js');
var html = r[j].style.getPropertyValue('--html');
var data = r[j].style.getPropertyValue('--data');
var selector = r[j].style.parentRule.selectorText;
var el = document.querySelectorAll(selector);
if (data) {
eval(`data = { ${data.trim().slice(1, -1)} }`);
}
if (html) {
el.forEach(function (e) {
e.innerHTML = eval('`' + html.trim().slice(1, -1) + '`');
});
}
if (selector === 'script') {
eval(js.trim().slice(1, -1));
} else {
if (js) {
for (n = 0; n < el.length; n++) {
eval(js.trim().slice(1, -1).replace(new RegExp('this', 'g'), `document.querySelectorAll('${selector}')[${n}]`));
}
}
}
}
}
}
}
})();
});