-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgoodnight.js
46 lines (37 loc) · 980 Bytes
/
goodnight.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
38
39
40
41
42
43
44
45
46
(function (g, ns) {
"use strict";
function gn() {
var Goodnight = { AM: 6, PM: 18 }, hours = new Date().getHours(), ln = [];
Goodnight.night = function () {
return hours < this.PM ? hours < this.AM ? true : false : true;
};
Goodnight.css = function (path) {
if (!path) {
return;
}
var item = document.createElement("link");
item.rel = "stylesheet";
item.href = path;
ln.push(item);
if (this.night()) {
document.documentElement.firstChild.appendChild(item);
}
};
Goodnight.class = function (cssClass) {
if (this.night()) {
document.body.className += " " + (cssClass || "goodnight");
}
};
Goodnight.toggle = function () {
for (var i = 0; i < ln.length; i++) {
if (ln[i].parentNode) {
ln[i].parentNode.removeChild(ln[i]);
} else {
document.documentElement.firstChild.appendChild(ln[i]);
}
}
};
return Goodnight;
}
g[ns] = gn();
})(window, "Goodnight");