Skip to content

Commit 08d88c3

Browse files
committed
Updated Something
1 parent f893d15 commit 08d88c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3021
-256
lines changed

basis/NightTime.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

basis/NightTime.max.js

+65-70
Original file line numberDiff line numberDiff line change
@@ -23,51 +23,46 @@
2323
*/
2424

2525
{
26-
let thisPath = "";
27-
for (let i of document.getElementsByTagName("script"))
28-
if (i.src.includes("NightTime"))
29-
thisPath = i.getAttribute("src");
26+
let thisPath = document.getElementsByTagName("script");
27+
thisPath = thisPath[thisPath.length - 1].getAttribute("src");
3028
thisPath = thisPath.slice(0, thisPath.lastIndexOf("/") + 1);
3129
let path = (href = "") => thisPath + href;
32-
let type = obj => {
33-
return Object.prototype.toString.call(obj).slice(8, -1);
34-
}
35-
let profile = new Object;
36-
if (type(window["NightTime"]) === "Object")
30+
let type = obj => (obj ? obj.constructor.name : Object.prototype.toString.call(obj).slice(8, -1));
31+
let profile = {};
32+
if (type(window.NightTime) === "Object")
3733
Object.assign(profile, NightTime);
3834

39-
var NightTime = new Object;
35+
var NightTime = {};
4036

41-
let _this = NightTime;
37+
let _ = NightTime;
4238
let hour = new Date().getHours();
43-
if (hour < 7 || hour >= 19)
44-
_this.darkModeFact = true; //晚上7点到次日早上7点启动深色主题
45-
if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches)
46-
_this.darkModeFact = true; //若浏览器开启了深色主题,也会启动深色主题
47-
_this.theme = "";
48-
_this.nightDo = _this.lightDo = () => {};
39+
if (hour < 7 || hour >= 19 || //晚上7点到次日早上7点启动深色主题
40+
matchMedia && matchMedia("(prefers-color-scheme: dark)").matches) //若浏览器开启了深色主题,也会启动深色主题
41+
_.darkModeFact = true;
42+
_.theme = "";
43+
_.nightDo = _.lightDo = () => { };
4944
/** method description
5045
* 切换到当前主题
5146
* @returns void - 切换到正常情况下配置而应该呈现的主题
5247
*/
53-
_this.CurrentModeStyle = () => {
54-
_this.css = document.getElementById("css");
55-
if (_this.css) _this.theme = _this.css.getAttribute("data-theme").toLowerCase();
56-
if (_this.darkModeFact) return _this.DarkModeStyle();
57-
else return _this.LightModeStyle();
48+
_.CurrentModeStyle = () => {
49+
_.css = document.getElementById("css");
50+
if (_.css) _.theme = _.css.getAttribute("data-theme").toLowerCase();
51+
if (_.darkModeFact) return _.DarkModeStyle();
52+
else return _.LightModeStyle();
5853
}
5954
/** method description
6055
* 切换到对立主题
6156
* @returns void - 切换到不是当前状态下的主题,即浅色深色模式互相切换
6257
*/
63-
_this.ToggleModeStyle = () => {
64-
_this.darkModeFact = !_this.darkModeFact;
65-
return _this.CurrentModeStyle();
58+
_.ToggleModeStyle = () => {
59+
_.darkModeFact = !_.darkModeFact;
60+
return _.CurrentModeStyle();
6661
}
67-
_this.LightBackgroundColor = "white";
68-
_this.DarkBackgroundColor = "#222";
69-
_this.LightCSS = _this.DarkCSS = undefined;
70-
_this.defineCustomBackgroundColor = false;
62+
_.LightBackgroundColor = "white";
63+
_.DarkBackgroundColor = "#222";
64+
_.LightCSS = _.DarkCSS = undefined;
65+
_.defineCustomBackgroundColor = false;
7166
String.prototype.i = function (index, character = "") {
7267
return this.slice(0, index) + character + this.slice(index + 1);
7368
}
@@ -79,9 +74,9 @@
7974
}
8075
return hyphenCase;
8176
}
82-
_this.scrollbar = () => {
83-
_this.appendStyleByAjax(`css/scrollbar.css`, "scrollbar", {
84-
"var(--text-color-parts)": (_this.darkModeFact ? "255, 255, 255" : "0, 0, 0")
77+
_.scrollbar = () => {
78+
_.appendStyleByAjax(`css/scrollbar.css`, "scrollbar", {
79+
"var(--text-color-parts)": (_.darkModeFact ? "255, 255, 255" : "0, 0, 0")
8580
});
8681
}
8782
const notAvailableLog = new Error("The ID you specified has been occupied by the other element, please try to use other ID!");
@@ -92,7 +87,7 @@
9287
* @returns true - 添加成功
9388
* @exception false - 添加失败,输入的 id 名称被占用且不为 style 标签
9489
*/
95-
_this.appendStyle = (style, id = "") => {
90+
_.appendStyle = (style, id = "") => {
9691
var css;
9792
if (type(style) == "Object") {
9893
css = JSON.stringify(style, undefined, "\t");
@@ -119,7 +114,7 @@
119114
* @returns true - 添加成功
120115
* @exception false - 添加失败,输入的 id 名称被占用且不为 link 标签
121116
*/
122-
_this.appendCSSLink = (href, id = "") => {
117+
_.appendCSSLink = (href, id = "") => {
123118
var linkTag = document.getElementById(id);
124119
if (!linkTag) {
125120
linkTag = document.createElement("link");
@@ -143,7 +138,7 @@
143138
* @returns true - 添加成功
144139
* @exception false - 添加失败,输入的 id 名称被占用且不为 link 标签
145140
*/
146-
_this.appendStyleByAjax = (href, id = "", variable) => {
141+
_.appendStyleByAjax = (href, id = "", variable) => {
147142
var css = new XMLHttpRequest();
148143
css.onreadystatechange = () => {
149144
if (css.readyState == 4 && css.status == 200) {
@@ -178,7 +173,7 @@
178173
* @returns true - 移除成功
179174
* @exception false - 移除失败,移除的不是 style 或 link 标签
180175
*/
181-
_this.removeStyle = _this.removeCSSLink = id => {
176+
_.removeStyle = _.removeCSSLink = id => {
182177
let el = document.getElementById(id);
183178
if (!el) return false;
184179
if (el.tagName != "STYLE" && el.tagName != "LINK") return false;
@@ -189,71 +184,71 @@
189184
* 强制切换到深色主题
190185
* @returns void
191186
*/
192-
_this.DarkModeStyle = () => {
193-
_this.darkModeFact = true;
194-
if (_this.theme.includes("bootstrap")) {
195-
_this.appendCSSLink("https://bootswatch.com/4/darkly/bootstrap.min.css", "css");
187+
_.DarkModeStyle = () => {
188+
_.darkModeFact = true;
189+
if (_.theme.includes("bootstrap")) {
190+
_.appendCSSLink("https://bootswatch.com/4/darkly/bootstrap.min.css", "css");
196191
for (let i of document.getElementsByClassName("navbar")) {
197192
i.classList.remove("navbar-light");
198193
i.classList.remove("bg-light");
199194
i.classList.add("navbar-dark");
200195
i.classList.add("bg-dark");
201196
}
202197
const bbolsf = "bootstrap-btn-outline-light-style-fix";
203-
_this.appendStyleByAjax(`css/${bbolsf}.css`, bbolsf);
198+
_.appendStyleByAjax(`css/${bbolsf}.css`, bbolsf);
204199
}
205-
_this.scrollbar();
206-
_this.removeStyle("light-root");
207-
_this.appendStyle({
200+
_.scrollbar();
201+
_.removeStyle("light-root");
202+
_.appendStyle({
208203
":root": {
209204
"--text-color": "white",
210-
"--background-color": _this.DarkBackgroundColor
205+
"--background-color": _.DarkBackgroundColor
211206
}
212207
}, "dark-root");
213-
_this.nightDo();
214-
if (_this.defineCustomBackgroundColor) document.body.style.backgroundColor = _this.DarkBackgroundColor;
215-
if (_this.DarkCSS) _this.appendCSSLink(_this.DarkCSS, "css");
208+
_.nightDo();
209+
if (_.defineCustomBackgroundColor) document.body.style.backgroundColor = _.DarkBackgroundColor;
210+
if (_.DarkCSS) _.appendCSSLink(_.DarkCSS, "css");
216211
return true;
217212
}
218213
/** method description
219214
* 强制切换到浅色主题
220215
* @returns void
221216
*/
222-
_this.LightModeStyle = () => {
223-
_this.darkModeFact = false;
224-
if (_this.theme.includes("bootstrap")) {
225-
_this.appendCSSLink("https://bootswatch.com/_vendor/bootstrap/dist/css/bootstrap.min.css", "css");
217+
_.LightModeStyle = () => {
218+
_.darkModeFact = false;
219+
if (_.theme.includes("bootstrap")) {
220+
_.appendCSSLink("https://bootswatch.com/_vendor/bootstrap/dist/css/bootstrap.min.css", "css");
226221
for (let i of document.getElementsByClassName("navbar")) {
227222
i.classList.remove("navbar-dark");
228223
i.classList.remove("bg-dark");
229224
i.classList.add("navbar-light");
230225
i.classList.add("bg-light");
231226
}
232227
}
233-
_this.scrollbar();
234-
_this.removeStyle("bootstrap-btn-outline-light-style-fix");
235-
_this.removeStyle("dark-root");
236-
_this.appendStyle({
228+
_.scrollbar();
229+
_.removeStyle("bootstrap-btn-outline-light-style-fix");
230+
_.removeStyle("dark-root");
231+
_.appendStyle({
237232
":root": {
238233
"--text-color": "black",
239-
"--background-color": _this.LightBackgroundColor
234+
"--background-color": _.LightBackgroundColor
240235
}
241236
}, "light-root");
242-
_this.lightDo();
243-
if (_this.defineCustomBackgroundColor) document.body.style.backgroundColor = _this.LightBackgroundColor;
244-
if (_this.LightCSS) _this.appendCSSLink(_this.LightCSS, "css");
237+
_.lightDo();
238+
if (_.defineCustomBackgroundColor) document.body.style.backgroundColor = _.LightBackgroundColor;
239+
if (_.LightCSS) _.appendCSSLink(_.LightCSS, "css");
245240
return true;
246241
}
247-
if (type(profile.darkMode) === "Boolean") _this.darkModeFact = Boolean(profile.darkMode);
248-
if (profile.nightDo && type(profile.nightDo) === "Function") _this.nightDo = profile.nightDo;
249-
if (profile.darkDo && type(profile.darkDo) === "Function") _this.nightDo = profile.darkDo;
250-
if (profile.lightDo && type(profile.lightDo) === "Function") _this.lightDo = profile.lightDo;
242+
if (type(profile.darkMode) === "Boolean") _.darkModeFact = Boolean(profile.darkMode);
243+
if (type(profile.nightDo) === "Function") _.nightDo = profile.nightDo;
244+
if (type(profile.darkDo) === "Function") _.nightDo = profile.darkDo;
245+
if (type(profile.lightDo) === "Function") _.lightDo = profile.lightDo;
251246
if (profile.lightBackgroundColor || profile.darkBackgroundColor) {
252-
if (profile.lightBackgroundColor) _this.LightBackgroundColor = profile.lightBackgroundColor;
253-
if (profile.darkBackgroundColor) _this.DarkBackgroundColor = profile.darkBackgroundColor;
254-
_this.defineCustomBackgroundColor = true;
247+
if (profile.lightBackgroundColor) _.LightBackgroundColor = profile.lightBackgroundColor;
248+
if (profile.darkBackgroundColor) _.DarkBackgroundColor = profile.darkBackgroundColor;
249+
_.defineCustomBackgroundColor = true;
255250
}
256-
if (profile.lightCSS) _this.LightCSS = profile.lightCSS;
257-
if (profile.darkCSS) _this.DarkCSS = profile.darkCSS;
258-
_this.CurrentModeStyle();
251+
if (profile.lightCSS) _.LightCSS = profile.lightCSS;
252+
if (profile.darkCSS) _.DarkCSS = profile.darkCSS;
253+
_.CurrentModeStyle();
259254
}

0 commit comments

Comments
 (0)