hexo-theme-solitude 3.0.9 → 3.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_config.yml +15 -27
- package/languages/default.yml +14 -15
- package/languages/en.yml +22 -24
- package/languages/zh-CN.yml +14 -15
- package/languages/zh-TW.yml +14 -15
- package/layout/includes/head/config.pug +0 -11
- package/layout/includes/head/page_config.pug +1 -1
- package/layout/includes/inject/body.pug +1 -1
- package/layout/includes/layout.pug +0 -4
- package/layout/includes/page/brevity.pug +2 -2
- package/layout/includes/widgets/page/about/skillsinfo.pug +12 -11
- package/layout/includes/widgets/page/kit/content.pug +3 -2
- package/layout/includes/widgets/page/links/banner.pug +7 -6
- package/layout/includes/widgets/post/ai.pug +7 -0
- package/layout/post.pug +2 -2
- package/package.json +1 -1
- package/plugins.yml +4 -4
- package/scripts/event/cdn.js +83 -60
- package/scripts/event/merge_config.js +385 -385
- package/scripts/filter/default.js +22 -24
- package/scripts/tags/tabs.js +29 -18
- package/source/css/_global/index.styl +2 -2
- package/source/css/_layout/article-container.styl +1 -1
- package/source/css/_layout/other.styl +2 -2
- package/source/css/_layout/recent-post.styl +6 -0
- package/source/css/_page/brevity.styl +0 -2
- package/source/css/_page/tag.styl +2 -4
- package/source/css/_post/index.styl +103 -4
- package/source/css/_tags/tabs.styl +40 -101
- package/source/css/index.styl +0 -4
- package/source/js/main.js +447 -257
- package/source/js/post_ai.js +60 -0
- package/source/js/utils.js +0 -6
- package/layout/includes/widgets/post/post-ai.pug +0 -12
- package/layout/includes/widgets/third-party/tianli-talk.pug +0 -26
- package/source/css/_post/postAI.styl +0 -132
- package/source/css/third_party/tianli_talk.styl +0 -77
- package/source/js/third_party/post_ai.min.js +0 -184
package/source/js/main.js
CHANGED
@@ -1,27 +1,29 @@
|
|
1
1
|
const sidebarFn = () => {
|
2
|
-
const $toggleMenu = document.getElementById(
|
3
|
-
const $mobileSidebarMenus = document.getElementById(
|
4
|
-
const $menuMask = document.getElementById(
|
2
|
+
const $toggleMenu = document.getElementById("toggle-menu");
|
3
|
+
const $mobileSidebarMenus = document.getElementById("sidebar-menus");
|
4
|
+
const $menuMask = document.getElementById("menu-mask");
|
5
5
|
const $body = document.body;
|
6
6
|
|
7
7
|
const toggleMobileSidebar = (isOpen) => {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
$mobileSidebarMenus.classList.toggle('open', isOpen);
|
8
|
+
$body.style.overflow = isOpen ? "hidden" : "";
|
9
|
+
utils[isOpen ? "fadeIn" : "fadeOut"]($menuMask, 0.5);
|
10
|
+
$mobileSidebarMenus.classList.toggle("open", isOpen);
|
12
11
|
};
|
13
12
|
|
14
13
|
const closeMobileSidebar = () => {
|
15
|
-
if ($mobileSidebarMenus.classList.contains(
|
14
|
+
if ($mobileSidebarMenus.classList.contains("open")) {
|
16
15
|
toggleMobileSidebar(false);
|
17
16
|
}
|
18
17
|
};
|
19
18
|
|
20
|
-
$toggleMenu.addEventListener(
|
21
|
-
$menuMask.addEventListener(
|
19
|
+
$toggleMenu.addEventListener("click", () => toggleMobileSidebar(true));
|
20
|
+
$menuMask.addEventListener("click", closeMobileSidebar);
|
22
21
|
|
23
|
-
window.addEventListener(
|
24
|
-
if (
|
22
|
+
window.addEventListener("resize", () => {
|
23
|
+
if (
|
24
|
+
utils.isHidden($toggleMenu) &&
|
25
|
+
$mobileSidebarMenus.classList.contains("open")
|
26
|
+
) {
|
25
27
|
closeMobileSidebar();
|
26
28
|
}
|
27
29
|
sco.refreshWaterFall();
|
@@ -29,23 +31,23 @@ const sidebarFn = () => {
|
|
29
31
|
};
|
30
32
|
|
31
33
|
const scrollFn = () => {
|
32
|
-
const $rightside = document.getElementById(
|
33
|
-
const $header = document.getElementById(
|
34
|
+
const $rightside = document.getElementById("rightside");
|
35
|
+
const $header = document.getElementById("page-header");
|
34
36
|
let initTop = 0;
|
35
37
|
|
36
38
|
const updateHeaderAndRightside = (isDown, currentTop) => {
|
37
39
|
if (currentTop > 0) {
|
38
|
-
$header.classList.toggle(
|
39
|
-
$header.classList.add(
|
40
|
+
$header.classList.toggle("nav-visible", !isDown);
|
41
|
+
$header.classList.add("nav-fixed");
|
40
42
|
if ($rightside) {
|
41
|
-
$rightside.style.opacity =
|
42
|
-
$rightside.style.transform =
|
43
|
+
$rightside.style.opacity = "0.8";
|
44
|
+
$rightside.style.transform = "translateX(-58px)";
|
43
45
|
}
|
44
46
|
} else {
|
45
|
-
$header.classList.remove(
|
47
|
+
$header.classList.remove("nav-fixed", "nav-visible");
|
46
48
|
if ($rightside) {
|
47
|
-
$rightside.style.opacity =
|
48
|
-
$rightside.style.transform =
|
49
|
+
$rightside.style.opacity = "";
|
50
|
+
$rightside.style.transform = "";
|
49
51
|
}
|
50
52
|
}
|
51
53
|
};
|
@@ -58,13 +60,13 @@ const scrollFn = () => {
|
|
58
60
|
updateHeaderAndRightside(isDown, currentTop);
|
59
61
|
}, 200);
|
60
62
|
|
61
|
-
window.addEventListener(
|
63
|
+
window.addEventListener("scroll", (e) => {
|
62
64
|
throttledScroll(e);
|
63
65
|
if (window.scrollY === 0) {
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
66
|
+
$header.classList.remove("nav-fixed", "nav-visible");
|
67
|
+
if ($rightside) {
|
68
|
+
$rightside.style.cssText = "opacity: ''; transform: ''";
|
69
|
+
}
|
68
70
|
}
|
69
71
|
});
|
70
72
|
};
|
@@ -73,24 +75,46 @@ const percent = () => {
|
|
73
75
|
const docEl = document.documentElement;
|
74
76
|
const body = document.body;
|
75
77
|
const scrollPos = window.pageYOffset || docEl.scrollTop;
|
76
|
-
const totalScrollableHeight =
|
78
|
+
const totalScrollableHeight =
|
79
|
+
Math.max(
|
80
|
+
body.scrollHeight,
|
81
|
+
docEl.scrollHeight,
|
82
|
+
body.offsetHeight,
|
83
|
+
docEl.offsetHeight,
|
84
|
+
body.clientHeight,
|
85
|
+
docEl.clientHeight
|
86
|
+
) - docEl.clientHeight;
|
77
87
|
const scrolledPercent = Math.round((scrollPos / totalScrollableHeight) * 100);
|
78
88
|
const navToTop = document.querySelector("#nav-totop");
|
79
89
|
const rsToTop = document.querySelector(".rs_show .top i");
|
80
90
|
const percentDisplay = document.querySelector("#percent");
|
81
|
-
const isNearEnd =
|
91
|
+
const isNearEnd =
|
92
|
+
window.scrollY + docEl.clientHeight >=
|
93
|
+
(
|
94
|
+
document.getElementById("post-comment") ||
|
95
|
+
document.getElementById("footer")
|
96
|
+
).offsetTop;
|
82
97
|
|
83
98
|
navToTop?.classList.toggle("long", isNearEnd || scrolledPercent > 90);
|
84
99
|
rsToTop?.classList.toggle("show", isNearEnd || scrolledPercent > 90);
|
85
|
-
percentDisplay.textContent =
|
86
|
-
|
87
|
-
|
100
|
+
percentDisplay.textContent =
|
101
|
+
isNearEnd || scrolledPercent > 90
|
102
|
+
? navToTop
|
103
|
+
? GLOBAL_CONFIG.lang.backtop
|
104
|
+
: ""
|
105
|
+
: scrolledPercent;
|
106
|
+
|
107
|
+
document
|
108
|
+
.querySelectorAll(".needEndHide")
|
109
|
+
.forEach((item) =>
|
110
|
+
item.classList.toggle("hide", totalScrollableHeight - scrollPos < 100)
|
111
|
+
);
|
88
112
|
};
|
89
113
|
|
90
114
|
const showTodayCard = () => {
|
91
|
-
const el = document.getElementById(
|
92
|
-
const topGroup = document.querySelector(
|
93
|
-
topGroup?.addEventListener(
|
115
|
+
const el = document.getElementById("todayCard");
|
116
|
+
const topGroup = document.querySelector(".topGroup");
|
117
|
+
topGroup?.addEventListener("mouseleave", () => el?.classList.remove("hide"));
|
94
118
|
};
|
95
119
|
|
96
120
|
const initObserver = () => {
|
@@ -99,11 +123,13 @@ const initObserver = () => {
|
|
99
123
|
const commentBarrageElement = document.querySelector(".comment-barrage");
|
100
124
|
|
101
125
|
if (commentElement && paginationElement) {
|
102
|
-
const observer = new IntersectionObserver(entries => {
|
103
|
-
entries.forEach(entry => {
|
126
|
+
const observer = new IntersectionObserver((entries) => {
|
127
|
+
entries.forEach((entry) => {
|
104
128
|
paginationElement.classList.toggle("show-window", entry.isIntersecting);
|
105
129
|
if (GLOBAL_CONFIG.comment.commentBarrage) {
|
106
|
-
commentBarrageElement.style.bottom = entry.isIntersecting
|
130
|
+
commentBarrageElement.style.bottom = entry.isIntersecting
|
131
|
+
? "-200px"
|
132
|
+
: "0px";
|
107
133
|
}
|
108
134
|
});
|
109
135
|
});
|
@@ -115,28 +141,40 @@ const addCopyright = () => {
|
|
115
141
|
if (!GLOBAL_CONFIG.copyright) return;
|
116
142
|
const { limit, author, link, source, info } = GLOBAL_CONFIG.copyright;
|
117
143
|
|
118
|
-
document.body.addEventListener(
|
144
|
+
document.body.addEventListener("copy", (e) => {
|
119
145
|
e.preventDefault();
|
120
146
|
const copyText = window.getSelection().toString();
|
121
|
-
const text =
|
122
|
-
|
147
|
+
const text =
|
148
|
+
copyText.length > limit
|
149
|
+
? `${copyText}\n\n${author}\n${link}${window.location.href}\n${source}\n${info}`
|
150
|
+
: copyText;
|
151
|
+
e.clipboardData.setData("text", text);
|
123
152
|
});
|
124
153
|
};
|
125
154
|
|
126
155
|
const asideStatus = () => {
|
127
|
-
const status = utils.saveToLocal.get(
|
128
|
-
document.documentElement.classList.toggle(
|
156
|
+
const status = utils.saveToLocal.get("aside-status");
|
157
|
+
document.documentElement.classList.toggle("hide-aside", status === "hide");
|
129
158
|
};
|
130
159
|
|
131
160
|
function initThemeColor() {
|
132
161
|
const currentTop = window.scrollY || document.documentElement.scrollTop;
|
133
|
-
const themeColor =
|
134
|
-
|
162
|
+
const themeColor =
|
163
|
+
currentTop > 0
|
164
|
+
? "--efu-card-bg"
|
165
|
+
: PAGE_CONFIG.is_post
|
166
|
+
? "--efu-main"
|
167
|
+
: "--efu-background";
|
168
|
+
applyThemeColor(
|
169
|
+
getComputedStyle(document.documentElement).getPropertyValue(themeColor)
|
170
|
+
);
|
135
171
|
}
|
136
172
|
|
137
173
|
function applyThemeColor(color) {
|
138
174
|
const themeColorMeta = document.querySelector('meta[name="theme-color"]');
|
139
|
-
const appleMobileWebAppMeta = document.querySelector(
|
175
|
+
const appleMobileWebAppMeta = document.querySelector(
|
176
|
+
'meta[name="apple-mobile-web-app-status-bar-style"]'
|
177
|
+
);
|
140
178
|
themeColorMeta?.setAttribute("content", color);
|
141
179
|
appleMobileWebAppMeta?.setAttribute("content", color);
|
142
180
|
if (window.matchMedia("(display-mode: standalone)").matches) {
|
@@ -144,9 +182,9 @@ function applyThemeColor(color) {
|
|
144
182
|
}
|
145
183
|
}
|
146
184
|
|
147
|
-
const handleThemeChange = mode => {
|
185
|
+
const handleThemeChange = (mode) => {
|
148
186
|
const themeChange = window.globalFn?.themeChange || {};
|
149
|
-
Object.values(themeChange).forEach(fn => fn(mode));
|
187
|
+
Object.values(themeChange).forEach((fn) => fn(mode));
|
150
188
|
};
|
151
189
|
|
152
190
|
const sco = {
|
@@ -156,7 +194,8 @@ const sco = {
|
|
156
194
|
scrollTo(elementId) {
|
157
195
|
const targetElement = document.getElementById(elementId);
|
158
196
|
if (targetElement) {
|
159
|
-
const targetPosition =
|
197
|
+
const targetPosition =
|
198
|
+
targetElement.getBoundingClientRect().top + window.pageYOffset - 80;
|
160
199
|
window.scroll({ top: targetPosition, behavior: "smooth" });
|
161
200
|
}
|
162
201
|
},
|
@@ -164,20 +203,24 @@ const sco = {
|
|
164
203
|
if (!this.isMusicBind) {
|
165
204
|
this.musicBind();
|
166
205
|
}
|
167
|
-
const $music = document.querySelector(
|
168
|
-
const $meting = document.querySelector(
|
169
|
-
const $console = document.getElementById(
|
170
|
-
const $rmText = document.querySelector(
|
171
|
-
const $rmIcon = document.querySelector(
|
206
|
+
const $music = document.querySelector("#nav-music");
|
207
|
+
const $meting = document.querySelector("meting-js");
|
208
|
+
const $console = document.getElementById("consoleMusic");
|
209
|
+
const $rmText = document.querySelector("#menu-music-toggle span");
|
210
|
+
const $rmIcon = document.querySelector("#menu-music-toggle i");
|
172
211
|
|
173
212
|
this.musicPlaying = !this.musicPlaying;
|
174
213
|
$music.classList.toggle("playing", this.musicPlaying);
|
175
214
|
$music.classList.toggle("stretch", this.musicPlaying);
|
176
215
|
$console?.classList.toggle("on", this.musicPlaying);
|
177
216
|
|
178
|
-
if (typeof rm !==
|
179
|
-
$rmText.textContent = this.musicPlaying
|
180
|
-
|
217
|
+
if (typeof rm !== "undefined" && rm?.menuItems.music[0]) {
|
218
|
+
$rmText.textContent = this.musicPlaying
|
219
|
+
? GLOBAL_CONFIG.right_menu.music.stop
|
220
|
+
: GLOBAL_CONFIG.right_menu.music.start;
|
221
|
+
$rmIcon.className = this.musicPlaying
|
222
|
+
? "solitude fas fa-pause"
|
223
|
+
: "solitude fas fa-play";
|
181
224
|
}
|
182
225
|
|
183
226
|
if (isMeting) {
|
@@ -185,15 +228,15 @@ const sco = {
|
|
185
228
|
}
|
186
229
|
},
|
187
230
|
musicBind() {
|
188
|
-
const $music = document.querySelector(
|
189
|
-
const $name = document.querySelector(
|
190
|
-
const $button = document.querySelector(
|
231
|
+
const $music = document.querySelector("#nav-music");
|
232
|
+
const $name = document.querySelector("#nav-music .aplayer-music");
|
233
|
+
const $button = document.querySelector("#nav-music .aplayer-button");
|
191
234
|
|
192
|
-
$name?.addEventListener(
|
235
|
+
$name?.addEventListener("click", () => {
|
193
236
|
$music.classList.toggle("stretch");
|
194
237
|
});
|
195
238
|
|
196
|
-
$button?.addEventListener(
|
239
|
+
$button?.addEventListener("click", () => {
|
197
240
|
this.musicToggle(false);
|
198
241
|
});
|
199
242
|
|
@@ -201,13 +244,16 @@ const sco = {
|
|
201
244
|
},
|
202
245
|
switchCommentBarrage() {
|
203
246
|
const commentBarrageElement = document.querySelector(".comment-barrage");
|
204
|
-
const consoleCommentBarrage = document.querySelector(
|
247
|
+
const consoleCommentBarrage = document.querySelector(
|
248
|
+
"#consoleCommentBarrage"
|
249
|
+
);
|
205
250
|
if (!commentBarrageElement) return;
|
206
251
|
|
207
|
-
const isDisplayed =
|
252
|
+
const isDisplayed =
|
253
|
+
window.getComputedStyle(commentBarrageElement).display === "flex";
|
208
254
|
commentBarrageElement.style.display = isDisplayed ? "none" : "flex";
|
209
255
|
consoleCommentBarrage?.classList.toggle("on", !isDisplayed);
|
210
|
-
utils.saveToLocal.set("commentBarrageSwitch", !isDisplayed, .2);
|
256
|
+
utils.saveToLocal.set("commentBarrageSwitch", !isDisplayed, 0.2);
|
211
257
|
rm?.menuItems.barrage && rm.barrage(isDisplayed);
|
212
258
|
},
|
213
259
|
switchHideAside() {
|
@@ -225,12 +271,15 @@ const sco = {
|
|
225
271
|
consoleKeyboard?.classList.toggle("on", this.sco_keyboards);
|
226
272
|
keyboardFunction();
|
227
273
|
localStorage.setItem("keyboard", this.sco_keyboards);
|
228
|
-
document.getElementById(
|
274
|
+
document.getElementById("keyboard-tips")?.classList.remove("show");
|
229
275
|
},
|
230
276
|
initConsoleState() {
|
231
277
|
const consoleHideAside = document.querySelector("#consoleHideAside");
|
232
278
|
if (!consoleHideAside) return;
|
233
|
-
consoleHideAside.classList.toggle(
|
279
|
+
consoleHideAside.classList.toggle(
|
280
|
+
"on",
|
281
|
+
document.documentElement.classList.contains("hide-aside")
|
282
|
+
);
|
234
283
|
},
|
235
284
|
changeWittyWord() {
|
236
285
|
const greetings = GLOBAL_CONFIG.aside.witty_words;
|
@@ -243,46 +292,64 @@ const sco = {
|
|
243
292
|
this.lastWittyWord = randomGreeting;
|
244
293
|
},
|
245
294
|
switchDarkMode() {
|
246
|
-
const isDarkMode =
|
247
|
-
|
248
|
-
|
249
|
-
|
295
|
+
const isDarkMode =
|
296
|
+
document.documentElement.getAttribute("data-theme") === "dark";
|
297
|
+
const newMode = isDarkMode ? "light" : "dark";
|
298
|
+
document.documentElement.setAttribute("data-theme", newMode);
|
299
|
+
utils.saveToLocal.set("theme", newMode, 0.02);
|
250
300
|
utils.snackbarShow(GLOBAL_CONFIG.lang.theme[newMode], false, 2000);
|
251
|
-
if (typeof rm ===
|
301
|
+
if (typeof rm === "object") rm.mode(!isDarkMode) && rm.hideRightMenu();
|
252
302
|
handleThemeChange(newMode);
|
253
303
|
},
|
254
|
-
hideTodayCard: () =>
|
304
|
+
hideTodayCard: () =>
|
305
|
+
document.getElementById("todayCard").classList.add("hide"),
|
255
306
|
toTop: () => utils.scrollToDest(0),
|
256
|
-
showConsole: () =>
|
257
|
-
|
307
|
+
showConsole: () =>
|
308
|
+
document.getElementById("console")?.classList.toggle("show", true),
|
309
|
+
hideConsole: () =>
|
310
|
+
document.getElementById("console")?.classList.remove("show"),
|
258
311
|
refreshWaterFall() {
|
259
312
|
const observer = new IntersectionObserver((entries) => {
|
260
|
-
entries.forEach(entry => {
|
313
|
+
entries.forEach((entry) => {
|
261
314
|
if (entry.isIntersecting) {
|
262
315
|
setTimeout(() => {
|
263
316
|
waterfall(entry.target).then(() => {
|
264
|
-
entry.target.classList.add(
|
317
|
+
entry.target.classList.add("show");
|
265
318
|
});
|
266
319
|
}, 300);
|
267
320
|
}
|
268
321
|
});
|
269
322
|
});
|
270
|
-
document
|
323
|
+
document
|
324
|
+
.querySelectorAll(".waterfall")
|
325
|
+
.forEach((el) => observer.observe(el));
|
271
326
|
},
|
272
327
|
addRuntime() {
|
273
|
-
const el = document.getElementById(
|
328
|
+
const el = document.getElementById("runtimeshow");
|
274
329
|
if (el && GLOBAL_CONFIG.runtime) {
|
275
|
-
el.innerText =
|
330
|
+
el.innerText =
|
331
|
+
utils.timeDiff(new Date(GLOBAL_CONFIG.runtime), new Date()) +
|
332
|
+
GLOBAL_CONFIG.lang.day;
|
276
333
|
}
|
277
334
|
},
|
278
335
|
toTalk(txt) {
|
279
|
-
const inputs = [
|
280
|
-
|
336
|
+
const inputs = [
|
337
|
+
"#wl-edit",
|
338
|
+
".el-textarea__inner",
|
339
|
+
"#veditor",
|
340
|
+
".atk-textarea",
|
341
|
+
];
|
342
|
+
inputs.forEach((selector) => {
|
281
343
|
const el = document.querySelector(selector);
|
282
344
|
if (el) {
|
283
|
-
el.dispatchEvent(
|
284
|
-
|
285
|
-
|
345
|
+
el.dispatchEvent(
|
346
|
+
new Event("input", { bubble: true, cancelable: true })
|
347
|
+
);
|
348
|
+
el.value = "> " + txt.replace(/\n/g, "\n> ") + "\n\n";
|
349
|
+
utils.scrollToDest(
|
350
|
+
utils.getEleTop(document.getElementById("post-comment")),
|
351
|
+
300
|
352
|
+
);
|
286
353
|
el.focus();
|
287
354
|
el.setSelectionRange(-1, -1);
|
288
355
|
}
|
@@ -290,34 +357,51 @@ const sco = {
|
|
290
357
|
utils.snackbarShow(GLOBAL_CONFIG.lang.totalk, false, 2000);
|
291
358
|
},
|
292
359
|
initbbtalk() {
|
293
|
-
const bberTalkElement = document.querySelector(
|
360
|
+
const bberTalkElement = document.querySelector("#bber-talk");
|
294
361
|
if (bberTalkElement) {
|
295
|
-
new Swiper(
|
296
|
-
direction:
|
362
|
+
new Swiper(".swiper-container", {
|
363
|
+
direction: "vertical",
|
297
364
|
loop: true,
|
298
365
|
autoplay: {
|
299
366
|
delay: 3000,
|
300
|
-
pauseOnMouseEnter: true
|
367
|
+
pauseOnMouseEnter: true,
|
301
368
|
},
|
302
369
|
});
|
303
370
|
}
|
304
371
|
},
|
305
372
|
addPhotoFigcaption() {
|
306
|
-
document
|
307
|
-
|
308
|
-
|
309
|
-
image.
|
310
|
-
|
311
|
-
|
373
|
+
document
|
374
|
+
.querySelectorAll(".article-container img:not(.gallery-item img)")
|
375
|
+
.forEach((image) => {
|
376
|
+
const captionText = image.getAttribute("alt");
|
377
|
+
if (captionText) {
|
378
|
+
image.insertAdjacentHTML(
|
379
|
+
"afterend",
|
380
|
+
`<div class="img-alt is-center">${utils.escapeHtml(
|
381
|
+
captionText
|
382
|
+
)}</div>`
|
383
|
+
);
|
384
|
+
}
|
385
|
+
});
|
312
386
|
},
|
313
|
-
scrollToComment: () =>
|
387
|
+
scrollToComment: () =>
|
388
|
+
utils.scrollToDest(
|
389
|
+
utils.getEleTop(document.getElementById("post-comment")),
|
390
|
+
300
|
391
|
+
),
|
314
392
|
setTimeState() {
|
315
|
-
const el = document.getElementById(
|
393
|
+
const el = document.getElementById("sayhi");
|
316
394
|
if (el) {
|
317
395
|
const hours = new Date().getHours();
|
318
396
|
const lang = GLOBAL_CONFIG.aside.state;
|
319
397
|
|
320
|
-
const localData = getLocalData([
|
398
|
+
const localData = getLocalData([
|
399
|
+
"twikoo",
|
400
|
+
"WALINE_USER_META",
|
401
|
+
"WALINE_USER",
|
402
|
+
"_v_Cache_Meta",
|
403
|
+
"ArtalkUser",
|
404
|
+
]);
|
321
405
|
|
322
406
|
function getLocalData(keys) {
|
323
407
|
for (let key of keys) {
|
@@ -327,10 +411,12 @@ const sco = {
|
|
327
411
|
}
|
328
412
|
}
|
329
413
|
return null;
|
330
|
-
}
|
331
|
-
const nick = localData ?
|
414
|
+
}
|
415
|
+
const nick = localData ? localData.nick || localData.display_name : null;
|
332
416
|
|
333
|
-
const prefix = this.wasPageHidden
|
417
|
+
const prefix = this.wasPageHidden
|
418
|
+
? GLOBAL_CONFIG.aside.witty_comment.back + nick
|
419
|
+
: GLOBAL_CONFIG.aside.witty_comment.prefix + nick;
|
334
420
|
|
335
421
|
const greetings = [
|
336
422
|
{ start: 0, end: 5, text: nick ? prefix : lang.goodnight },
|
@@ -339,7 +425,9 @@ const sco = {
|
|
339
425
|
{ start: 15, end: 18, text: nick ? prefix : lang.afternoon },
|
340
426
|
{ start: 19, end: 24, text: nick ? prefix : lang.night },
|
341
427
|
];
|
342
|
-
const greeting = greetings.find(
|
428
|
+
const greeting = greetings.find(
|
429
|
+
(g) => hours >= g.start && hours <= g.end
|
430
|
+
);
|
343
431
|
el.innerText = greeting.text;
|
344
432
|
}
|
345
433
|
},
|
@@ -350,7 +438,7 @@ const sco = {
|
|
350
438
|
const tag = decodedPath.split("/").slice(-2, -1)[0];
|
351
439
|
const tagElement = document.getElementById(tag);
|
352
440
|
if (tagElement) {
|
353
|
-
document.querySelectorAll("a.select").forEach(link => {
|
441
|
+
document.querySelectorAll("a.select").forEach((link) => {
|
354
442
|
link.classList.remove("select");
|
355
443
|
});
|
356
444
|
tagElement.classList.add("select");
|
@@ -363,8 +451,10 @@ const sco = {
|
|
363
451
|
const isHomePage = currentPath === GLOBAL_CONFIG.root;
|
364
452
|
if (categoryBar) {
|
365
453
|
const categoryItems = categoryBar.querySelectorAll(".category-bar-item");
|
366
|
-
categoryItems.forEach(item => item.classList.remove("select"));
|
367
|
-
const activeItemId = isHomePage
|
454
|
+
categoryItems.forEach((item) => item.classList.remove("select"));
|
455
|
+
const activeItemId = isHomePage
|
456
|
+
? "category-bar-home"
|
457
|
+
: currentPath.split("/").slice(-2, -1)[0];
|
368
458
|
const activeItem = document.getElementById(activeItemId);
|
369
459
|
if (activeItem) {
|
370
460
|
activeItem.classList.add("select");
|
@@ -375,21 +465,30 @@ const sco = {
|
|
375
465
|
const scrollBar = document.getElementById("category-bar-items");
|
376
466
|
const nextElement = document.getElementById("category-bar-next");
|
377
467
|
if (scrollBar) {
|
378
|
-
const isScrollBarAtEnd = () =>
|
468
|
+
const isScrollBarAtEnd = () =>
|
469
|
+
scrollBar.scrollLeft + scrollBar.clientWidth >=
|
470
|
+
scrollBar.scrollWidth - 8;
|
379
471
|
const scroll = () => {
|
380
|
-
scrollBar.scroll({
|
472
|
+
scrollBar.scroll({
|
473
|
+
left: isScrollBarAtEnd() ? 0 : scrollBar.clientWidth,
|
474
|
+
behavior: "smooth",
|
475
|
+
});
|
381
476
|
};
|
382
477
|
scrollBar.addEventListener("scroll", () => {
|
383
478
|
clearTimeout(this.timeoutId);
|
384
479
|
this.timeoutId = setTimeout(() => {
|
385
|
-
nextElement.style.transform = isScrollBarAtEnd()
|
480
|
+
nextElement.style.transform = isScrollBarAtEnd()
|
481
|
+
? "rotate(180deg)"
|
482
|
+
: "";
|
386
483
|
}, 150);
|
387
484
|
});
|
388
485
|
scroll();
|
389
486
|
}
|
390
487
|
},
|
391
488
|
openAllTags() {
|
392
|
-
document
|
489
|
+
document
|
490
|
+
.querySelectorAll(".card-allinfo .card-tag-cloud")
|
491
|
+
.forEach((tagCloudElement) => tagCloudElement.classList.add("all-tags"));
|
393
492
|
document.getElementById("more-tags-btn")?.remove();
|
394
493
|
},
|
395
494
|
listenToPageInputPress() {
|
@@ -404,13 +503,16 @@ const sco = {
|
|
404
503
|
return;
|
405
504
|
}
|
406
505
|
pageText.addEventListener("keydown", (event) => {
|
407
|
-
if (event.key ===
|
506
|
+
if (event.key === "Enter") {
|
408
507
|
sco.toPage();
|
409
508
|
pjax.loadUrl(pageButton.href);
|
410
509
|
}
|
411
510
|
});
|
412
511
|
pageText.addEventListener("input", () => {
|
413
|
-
pageButton.classList.toggle(
|
512
|
+
pageButton.classList.toggle(
|
513
|
+
"haveValue",
|
514
|
+
pageText.value !== "" && pageText.value !== "0"
|
515
|
+
);
|
414
516
|
if (+pageText.value > lastPageNumber) {
|
415
517
|
pageText.value = lastPageNumber;
|
416
518
|
}
|
@@ -419,152 +521,174 @@ const sco = {
|
|
419
521
|
addNavBackgroundInit() {
|
420
522
|
const scrollTop = document.documentElement.scrollTop;
|
421
523
|
if (scrollTop !== 0) {
|
422
|
-
document
|
524
|
+
document
|
525
|
+
.getElementById("page-header")
|
526
|
+
.classList.add("nav-fixed", "nav-visible");
|
423
527
|
}
|
424
528
|
},
|
425
529
|
toPage() {
|
426
530
|
const pageNumbers = document.querySelectorAll(".page-number");
|
427
|
-
const maxPageNumber = parseInt(
|
531
|
+
const maxPageNumber = parseInt(
|
532
|
+
pageNumbers[pageNumbers.length - 1].innerHTML
|
533
|
+
);
|
428
534
|
const inputElement = document.getElementById("toPageText");
|
429
535
|
const inputPageNumber = parseInt(inputElement.value);
|
430
|
-
document.getElementById("toPageButton").href =
|
431
|
-
|
432
|
-
|
536
|
+
document.getElementById("toPageButton").href =
|
537
|
+
!isNaN(inputPageNumber) &&
|
538
|
+
inputPageNumber <= maxPageNumber &&
|
539
|
+
inputPageNumber > 1
|
540
|
+
? window.location.href.replace(/\/page\/\d+\/$/, "/") +
|
541
|
+
"page/" +
|
542
|
+
inputPageNumber +
|
543
|
+
"/"
|
544
|
+
: "/";
|
433
545
|
},
|
434
546
|
owoBig(owoSelector) {
|
435
|
-
let owoBig = document.getElementById(
|
547
|
+
let owoBig = document.getElementById("owo-big");
|
436
548
|
if (!owoBig) {
|
437
|
-
owoBig = document.createElement(
|
438
|
-
owoBig.id =
|
549
|
+
owoBig = document.createElement("div");
|
550
|
+
owoBig.id = "owo-big";
|
439
551
|
document.body.appendChild(owoBig);
|
440
552
|
}
|
441
|
-
const showOwoBig = event => {
|
553
|
+
const showOwoBig = (event) => {
|
442
554
|
const target = event.target;
|
443
555
|
const owoItem = target.closest(owoSelector.item);
|
444
556
|
if (owoItem && target.closest(owoSelector.body)) {
|
445
|
-
const imgSrc = owoItem.querySelector(
|
557
|
+
const imgSrc = owoItem.querySelector("img")?.src;
|
446
558
|
if (imgSrc) {
|
447
559
|
owoBig.innerHTML = `<img src="${imgSrc}" style="max-width: 100%; height: auto;">`;
|
448
|
-
owoBig.style.display =
|
560
|
+
owoBig.style.display = "block";
|
449
561
|
positionOwoBig(owoItem);
|
450
562
|
}
|
451
563
|
}
|
452
564
|
};
|
453
|
-
const hideOwoBig = event => {
|
454
|
-
if (
|
455
|
-
|
565
|
+
const hideOwoBig = (event) => {
|
566
|
+
if (
|
567
|
+
event.target.closest(owoSelector.item) &&
|
568
|
+
event.target.closest(owoSelector.body)
|
569
|
+
) {
|
570
|
+
owoBig.style.display = "none";
|
456
571
|
}
|
457
572
|
};
|
458
|
-
const positionOwoBig = owoItem => {
|
573
|
+
const positionOwoBig = (owoItem) => {
|
459
574
|
const itemRect = owoItem.getBoundingClientRect();
|
460
|
-
owoBig.style.left = `${itemRect.left -
|
575
|
+
owoBig.style.left = `${itemRect.left - owoBig.offsetWidth / 4}px`;
|
461
576
|
owoBig.style.top = `${itemRect.top}px`;
|
462
577
|
};
|
463
|
-
document.addEventListener(
|
464
|
-
document.addEventListener(
|
578
|
+
document.addEventListener("mouseover", showOwoBig);
|
579
|
+
document.addEventListener("mouseout", hideOwoBig);
|
465
580
|
},
|
466
581
|
changeTimeFormat(selector) {
|
467
|
-
selector.forEach(item => {
|
468
|
-
const timeVal = item.getAttribute(
|
582
|
+
selector.forEach((item) => {
|
583
|
+
const timeVal = item.getAttribute("datetime");
|
469
584
|
item.textContent = utils.diffDate(timeVal, true);
|
470
|
-
item.style.display =
|
585
|
+
item.style.display = "inline";
|
471
586
|
});
|
472
587
|
},
|
473
588
|
switchComments() {
|
474
|
-
const switchBtn = document.getElementById(
|
589
|
+
const switchBtn = document.getElementById("switch-btn");
|
475
590
|
if (!switchBtn) return;
|
476
591
|
let switchDone = false;
|
477
|
-
const commentContainer = document.getElementById(
|
592
|
+
const commentContainer = document.getElementById("post-comment");
|
478
593
|
const handleSwitchBtn = () => {
|
479
|
-
commentContainer.classList.toggle(
|
480
|
-
if (!switchDone && typeof loadTwoComment ===
|
594
|
+
commentContainer.classList.toggle("move");
|
595
|
+
if (!switchDone && typeof loadTwoComment === "function") {
|
481
596
|
switchDone = true;
|
482
597
|
loadTwoComment();
|
483
598
|
}
|
484
599
|
};
|
485
|
-
utils.addEventListenerPjax(switchBtn,
|
600
|
+
utils.addEventListenerPjax(switchBtn, "click", handleSwitchBtn);
|
486
601
|
},
|
487
602
|
homeTypeit() {
|
488
|
-
if(typeof
|
603
|
+
if (typeof home_subtitle === "undefined") return;
|
489
604
|
const ty = new TypeIt(".banners-title-small", {
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
605
|
+
speed: 200,
|
606
|
+
waitUntilVisible: true,
|
607
|
+
loop: true,
|
608
|
+
lifeLike: true,
|
494
609
|
});
|
495
|
-
home_subtitle.forEach(item => {
|
496
|
-
|
610
|
+
home_subtitle.forEach((item) => {
|
611
|
+
ty.type(item).pause(500).delete(item);
|
497
612
|
});
|
498
613
|
ty.go();
|
499
|
-
}
|
614
|
+
},
|
500
615
|
};
|
501
616
|
|
502
617
|
const addHighlight = () => {
|
503
618
|
const highlight = GLOBAL_CONFIG.highlight;
|
504
619
|
if (!highlight) return;
|
505
620
|
const { copy, expand, limit, syntax } = highlight;
|
506
|
-
const $isPrismjs = syntax ===
|
621
|
+
const $isPrismjs = syntax === "prismjs";
|
507
622
|
const $isShowTool = highlight.enable || copy || expand || limit;
|
508
|
-
const expandClass = expand ?
|
509
|
-
const $syntaxHighlight =
|
510
|
-
|
623
|
+
const expandClass = expand ? "" : "closed";
|
624
|
+
const $syntaxHighlight =
|
625
|
+
syntax === "highlight.js"
|
626
|
+
? document.querySelectorAll("figure.highlight")
|
627
|
+
: document.querySelectorAll('pre[class*="language-"]');
|
628
|
+
|
511
629
|
if (!(($isShowTool || limit) && $syntaxHighlight.length)) return;
|
512
630
|
|
513
|
-
const copyEle = copy
|
631
|
+
const copyEle = copy
|
632
|
+
? `<i class="solitude fas fa-copy copy-button"></i>`
|
633
|
+
: "<i></i>";
|
514
634
|
const expandEle = `<i class="solitude fas fa-angle-down expand"></i>`;
|
515
|
-
const limitEle = limit
|
516
|
-
|
635
|
+
const limitEle = limit
|
636
|
+
? `<i class="solitude fas fa-angles-down"></i>`
|
637
|
+
: "<i></i>";
|
638
|
+
|
517
639
|
const alertInfo = (ele, text) => utils.snackbarShow(text, false, 2000);
|
518
|
-
|
640
|
+
|
519
641
|
const copyFn = (e) => {
|
520
642
|
const $buttonParent = e.parentNode;
|
521
|
-
$buttonParent.classList.add(
|
643
|
+
$buttonParent.classList.add("copy-true");
|
522
644
|
const selection = window.getSelection();
|
523
645
|
const range = document.createRange();
|
524
|
-
const preCodeSelector = $isPrismjs ?
|
525
|
-
range.selectNodeContents(
|
646
|
+
const preCodeSelector = $isPrismjs ? "pre code" : "table .code pre";
|
647
|
+
range.selectNodeContents(
|
648
|
+
$buttonParent.querySelectorAll(`${preCodeSelector}`)[0]
|
649
|
+
);
|
526
650
|
selection.removeAllRanges();
|
527
651
|
selection.addRange(range);
|
528
|
-
document.execCommand(
|
652
|
+
document.execCommand("copy");
|
529
653
|
alertInfo(e.lastChild, GLOBAL_CONFIG.lang.copy.success);
|
530
654
|
selection.removeAllRanges();
|
531
|
-
$buttonParent.classList.remove(
|
655
|
+
$buttonParent.classList.remove("copy-true");
|
532
656
|
};
|
533
657
|
|
534
|
-
const expandClose = (e) => e.classList.toggle(
|
658
|
+
const expandClose = (e) => e.classList.toggle("closed");
|
535
659
|
const shrinkEle = function () {
|
536
|
-
this.classList.toggle(
|
660
|
+
this.classList.toggle("expand-done");
|
537
661
|
};
|
538
662
|
|
539
663
|
const ToolsFn = function (e) {
|
540
664
|
const $target = e.target.classList;
|
541
|
-
if ($target.contains(
|
542
|
-
else if ($target.contains(
|
665
|
+
if ($target.contains("expand")) expandClose(this);
|
666
|
+
else if ($target.contains("copy-button")) copyFn(this);
|
543
667
|
};
|
544
668
|
|
545
669
|
const createEle = (lang, item, service) => {
|
546
670
|
const fragment = document.createDocumentFragment();
|
547
671
|
if ($isShowTool) {
|
548
|
-
const captionItem = item.querySelector(
|
549
|
-
let caption =
|
672
|
+
const captionItem = item.querySelector("figcaption");
|
673
|
+
let caption = "";
|
550
674
|
if (captionItem) {
|
551
675
|
caption = `<div class="caption">${captionItem.innerHTML}</div>`;
|
552
676
|
item.removeChild(captionItem);
|
553
677
|
}
|
554
|
-
const hlTools = document.createElement(
|
678
|
+
const hlTools = document.createElement("div");
|
555
679
|
hlTools.className = `highlight-tools ${expandClass}`;
|
556
680
|
hlTools.innerHTML = expandEle + lang + caption + copyEle;
|
557
|
-
utils.addEventListenerPjax(hlTools,
|
681
|
+
utils.addEventListenerPjax(hlTools, "click", ToolsFn);
|
558
682
|
fragment.appendChild(hlTools);
|
559
683
|
}
|
560
684
|
if (limit && item.offsetHeight > limit + 30) {
|
561
|
-
const ele = document.createElement(
|
562
|
-
ele.className =
|
685
|
+
const ele = document.createElement("div");
|
686
|
+
ele.className = "code-expand-btn";
|
563
687
|
ele.innerHTML = limitEle;
|
564
|
-
utils.addEventListenerPjax(ele,
|
688
|
+
utils.addEventListenerPjax(ele, "click", shrinkEle);
|
565
689
|
fragment.appendChild(ele);
|
566
690
|
}
|
567
|
-
if (service ===
|
691
|
+
if (service === "hl") {
|
568
692
|
item.insertBefore(fragment, item.firstChild);
|
569
693
|
} else {
|
570
694
|
item.parentNode.insertBefore(fragment, item);
|
@@ -572,49 +696,65 @@ const addHighlight = () => {
|
|
572
696
|
};
|
573
697
|
|
574
698
|
if ($isPrismjs) {
|
575
|
-
$syntaxHighlight.forEach(item => {
|
576
|
-
const langName = item.getAttribute(
|
577
|
-
const highlightLangEle = `<div class="code-lang">${utils.escapeHtml(
|
578
|
-
|
699
|
+
$syntaxHighlight.forEach((item) => {
|
700
|
+
const langName = item.getAttribute("data-language") || "Code";
|
701
|
+
const highlightLangEle = `<div class="code-lang">${utils.escapeHtml(
|
702
|
+
langName
|
703
|
+
)}</div>`;
|
704
|
+
utils.wrap(item, "figure", { class: "highlight" });
|
579
705
|
createEle(highlightLangEle, item);
|
580
706
|
});
|
581
707
|
} else {
|
582
|
-
$syntaxHighlight.forEach(item => {
|
583
|
-
let langName = item.getAttribute(
|
584
|
-
if (langName ===
|
585
|
-
const highlightLangEle = `<div class="code-lang">${utils.escapeHtml(
|
586
|
-
|
708
|
+
$syntaxHighlight.forEach((item) => {
|
709
|
+
let langName = item.getAttribute("class").split(" ")[1];
|
710
|
+
if (langName === "plain" || langName === undefined) langName = "Code";
|
711
|
+
const highlightLangEle = `<div class="code-lang">${utils.escapeHtml(
|
712
|
+
langName
|
713
|
+
)}</div>`;
|
714
|
+
createEle(highlightLangEle, item, "hl");
|
587
715
|
});
|
588
716
|
}
|
589
717
|
};
|
590
718
|
|
591
719
|
class toc {
|
592
720
|
static init() {
|
593
|
-
const tocContainer = document.getElementById(
|
594
|
-
if (!tocContainer || !tocContainer.querySelector(
|
595
|
-
tocContainer.style.display =
|
721
|
+
const tocContainer = document.getElementById("card-toc");
|
722
|
+
if (!tocContainer || !tocContainer.querySelector(".toc a")) {
|
723
|
+
tocContainer.style.display = "none";
|
596
724
|
return;
|
597
725
|
}
|
598
|
-
const el = document.querySelectorAll(
|
726
|
+
const el = document.querySelectorAll(".toc a");
|
599
727
|
el.forEach((e) => {
|
600
|
-
e.addEventListener(
|
728
|
+
e.addEventListener("click", (event) => {
|
601
729
|
event.preventDefault();
|
602
|
-
utils.scrollToDest(
|
730
|
+
utils.scrollToDest(
|
731
|
+
utils.getEleTop(
|
732
|
+
document.getElementById(
|
733
|
+
decodeURI(
|
734
|
+
(event.target.className === "toc-text"
|
735
|
+
? event.target.parentNode.hash
|
736
|
+
: event.target.hash
|
737
|
+
).replace("#", "")
|
738
|
+
)
|
739
|
+
)
|
740
|
+
),
|
741
|
+
300
|
742
|
+
);
|
603
743
|
});
|
604
744
|
});
|
605
745
|
this.active(el);
|
606
746
|
}
|
607
747
|
|
608
748
|
static active(toc) {
|
609
|
-
const $article = document.querySelector(
|
610
|
-
const $tocContent = document.getElementById(
|
611
|
-
const list = $article.querySelectorAll(
|
612
|
-
let detectItem =
|
749
|
+
const $article = document.querySelector(".article-container");
|
750
|
+
const $tocContent = document.getElementById("toc-content");
|
751
|
+
const list = $article.querySelectorAll("h1,h2,h3,h4,h5,h6");
|
752
|
+
let detectItem = "";
|
613
753
|
|
614
754
|
const autoScroll = (el) => {
|
615
755
|
const activePosition = el.getBoundingClientRect().top;
|
616
756
|
const sidebarScrollTop = $tocContent.scrollTop;
|
617
|
-
if (activePosition >
|
757
|
+
if (activePosition > document.documentElement.clientHeight - 100) {
|
618
758
|
$tocContent.scrollTop = sidebarScrollTop + 150;
|
619
759
|
}
|
620
760
|
if (activePosition < 100) {
|
@@ -624,7 +764,7 @@ class toc {
|
|
624
764
|
|
625
765
|
const findHeadPosition = (top) => {
|
626
766
|
if (top === 0) return false;
|
627
|
-
let currentIndex =
|
767
|
+
let currentIndex = "";
|
628
768
|
list.forEach((ele, index) => {
|
629
769
|
if (top > utils.getEleTop(ele) - 80) {
|
630
770
|
currentIndex = index;
|
@@ -632,16 +772,16 @@ class toc {
|
|
632
772
|
});
|
633
773
|
if (detectItem === currentIndex) return;
|
634
774
|
detectItem = currentIndex;
|
635
|
-
document.querySelectorAll(
|
636
|
-
i.classList.remove(
|
775
|
+
document.querySelectorAll(".toc .active").forEach((i) => {
|
776
|
+
i.classList.remove("active");
|
637
777
|
});
|
638
778
|
const activeitem = toc[detectItem];
|
639
779
|
if (activeitem) {
|
640
780
|
let parent = toc[detectItem].parentNode;
|
641
|
-
activeitem.classList.add(
|
781
|
+
activeitem.classList.add("active");
|
642
782
|
autoScroll(activeitem);
|
643
|
-
for (; !parent.matches(
|
644
|
-
if (parent.matches(
|
783
|
+
for (; !parent.matches(".toc"); parent = parent.parentNode) {
|
784
|
+
if (parent.matches("li")) parent.classList.add("active");
|
645
785
|
}
|
646
786
|
}
|
647
787
|
};
|
@@ -650,49 +790,43 @@ class toc {
|
|
650
790
|
const currentTop = window.scrollY || document.documentElement.scrollTop;
|
651
791
|
findHeadPosition(currentTop);
|
652
792
|
}, 100);
|
653
|
-
window.addEventListener(
|
793
|
+
window.addEventListener("scroll", tocScrollFn);
|
654
794
|
}
|
655
795
|
}
|
656
796
|
|
657
797
|
class tabs {
|
658
798
|
static init() {
|
659
799
|
this.clickFnOfTabs();
|
660
|
-
this.backToTop();
|
661
800
|
}
|
662
801
|
|
663
802
|
static clickFnOfTabs() {
|
664
|
-
document
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
const $
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
static backToTop() {
|
682
|
-
document.querySelectorAll('.article-container .tabs .tab-to-top').forEach((item) => {
|
683
|
-
item.addEventListener('click', function () {
|
684
|
-
utils.scrollToDest(utils.getEleTop(this.parentElement.parentElement.parentNode), 300);
|
803
|
+
document
|
804
|
+
.querySelectorAll(".article-container .tab > button")
|
805
|
+
.forEach((item) => {
|
806
|
+
item.addEventListener("click", function () {
|
807
|
+
const $tabItem = this.parentNode;
|
808
|
+
if (!$tabItem.classList.contains("active")) {
|
809
|
+
const $tabContent = $tabItem.parentNode.nextElementSibling;
|
810
|
+
const $siblings = utils.siblings($tabItem, ".active")[0];
|
811
|
+
$siblings && $siblings.classList.remove("active");
|
812
|
+
$tabItem.classList.add("active");
|
813
|
+
const tabId = this.getAttribute("data-href").replace("#", "");
|
814
|
+
[...$tabContent.children].forEach((item) => {
|
815
|
+
item.classList.toggle("active", item.id === tabId);
|
816
|
+
});
|
817
|
+
}
|
818
|
+
});
|
685
819
|
});
|
686
|
-
});
|
687
820
|
}
|
688
821
|
|
689
822
|
static lureAddListener() {
|
690
823
|
if (!GLOBAL_CONFIG.lure) return;
|
691
824
|
const title = document.title;
|
692
|
-
document.addEventListener(
|
825
|
+
document.addEventListener("visibilitychange", () => {
|
693
826
|
const { lure } = GLOBAL_CONFIG;
|
694
|
-
document.title =
|
695
|
-
|
827
|
+
document.title =
|
828
|
+
document.visibilityState === "hidden" ? lure.jump : lure.back;
|
829
|
+
if (document.visibilityState === "visible") {
|
696
830
|
setTimeout(() => {
|
697
831
|
document.title = title;
|
698
832
|
}, 2000);
|
@@ -703,16 +837,30 @@ class tabs {
|
|
703
837
|
static expireAddListener() {
|
704
838
|
const { expire } = GLOBAL_CONFIG;
|
705
839
|
if (!expire) return;
|
706
|
-
const list = document.querySelectorAll(
|
707
|
-
const post_date = list.length
|
840
|
+
const list = document.querySelectorAll(".post-meta-date time");
|
841
|
+
const post_date = list.length
|
842
|
+
? list[list.length - 1]
|
843
|
+
: document.querySelector(".datetime");
|
708
844
|
if (!post_date) return;
|
709
|
-
const ex = Math.ceil(
|
845
|
+
const ex = Math.ceil(
|
846
|
+
(new Date().getTime() -
|
847
|
+
new Date(post_date.getAttribute("datetime")).getTime()) /
|
848
|
+
1000 /
|
849
|
+
60 /
|
850
|
+
60 /
|
851
|
+
24
|
852
|
+
);
|
710
853
|
if (expire.time > ex) return;
|
711
|
-
const ele = document.createElement(
|
712
|
-
ele.className =
|
713
|
-
ele.innerHTML = `<i class="solitude fas fa-circle-exclamation"></i>${
|
714
|
-
|
715
|
-
|
854
|
+
const ele = document.createElement("div");
|
855
|
+
ele.className = "expire";
|
856
|
+
ele.innerHTML = `<i class="solitude fas fa-circle-exclamation"></i>${
|
857
|
+
expire.text_prev
|
858
|
+
}${-(expire.time - ex)}${expire.text_next}`;
|
859
|
+
const articleContainer = document.querySelector(".article-container");
|
860
|
+
articleContainer.insertAdjacentElement(
|
861
|
+
expire.position === "top" ? "afterbegin" : "beforeend",
|
862
|
+
ele
|
863
|
+
);
|
716
864
|
}
|
717
865
|
}
|
718
866
|
|
@@ -720,23 +868,30 @@ const scrollFnToDo = () => {
|
|
720
868
|
const { toc } = PAGE_CONFIG;
|
721
869
|
|
722
870
|
if (toc) {
|
723
|
-
const $cardTocLayout = document.getElementById(
|
724
|
-
const $cardToc = $cardTocLayout.querySelector(
|
725
|
-
const $tocLink = $cardToc.querySelectorAll(
|
726
|
-
const $tocPercentage = $cardTocLayout.querySelector(
|
727
|
-
const isExpand = $cardToc.classList.contains(
|
728
|
-
|
729
|
-
const tocItemClickFn = e => {
|
730
|
-
const target = e.target.closest(
|
871
|
+
const $cardTocLayout = document.getElementById("card-toc");
|
872
|
+
const $cardToc = $cardTocLayout.querySelector(".toc-content");
|
873
|
+
const $tocLink = $cardToc.querySelectorAll(".toc-link");
|
874
|
+
const $tocPercentage = $cardTocLayout.querySelector(".toc-percentage");
|
875
|
+
const isExpand = $cardToc.classList.contains("is-expand");
|
876
|
+
|
877
|
+
const tocItemClickFn = (e) => {
|
878
|
+
const target = e.target.closest(".toc-link");
|
731
879
|
if (!target) return;
|
732
880
|
|
733
881
|
e.preventDefault();
|
734
|
-
utils.scrollToDest(
|
882
|
+
utils.scrollToDest(
|
883
|
+
utils.getEleTop(
|
884
|
+
document.getElementById(
|
885
|
+
decodeURI(target.getAttribute("href")).replace("#", "")
|
886
|
+
)
|
887
|
+
),
|
888
|
+
300
|
889
|
+
);
|
735
890
|
if (window.innerWidth < 900) {
|
736
|
-
$cardTocLayout.classList.remove(
|
891
|
+
$cardTocLayout.classList.remove("open");
|
737
892
|
}
|
738
893
|
};
|
739
|
-
utils.addEventListenerPjax($cardToc,
|
894
|
+
utils.addEventListenerPjax($cardToc, "click", tocItemClickFn);
|
740
895
|
}
|
741
896
|
};
|
742
897
|
|
@@ -745,24 +900,50 @@ const forPostFn = () => {
|
|
745
900
|
};
|
746
901
|
|
747
902
|
window.refreshFn = () => {
|
748
|
-
const { is_home, is_page, page, is_post } = PAGE_CONFIG;
|
749
|
-
const { runtime, lazyload, lightbox, randomlink, covercolor,
|
750
|
-
|
751
|
-
|
903
|
+
const { is_home, is_page, page, is_post, ai_text } = PAGE_CONFIG;
|
904
|
+
const { runtime, lazyload, lightbox, randomlink, covercolor, lure, expire } =
|
905
|
+
GLOBAL_CONFIG;
|
906
|
+
const timeSelector =
|
907
|
+
(is_home
|
908
|
+
? ".post-meta-date time"
|
909
|
+
: is_post
|
910
|
+
? ".post-meta-date time"
|
911
|
+
: ".datetime") + ", .webinfo-item time";
|
912
|
+
document.body.setAttribute("data-type", page);
|
752
913
|
sco.changeTimeFormat(document.querySelectorAll(timeSelector));
|
753
914
|
runtime && sco.addRuntime();
|
754
|
-
[
|
915
|
+
[
|
916
|
+
scrollFn,
|
917
|
+
sidebarFn,
|
918
|
+
sco.addPhotoFigcaption,
|
919
|
+
sco.setTimeState,
|
920
|
+
sco.tagPageActive,
|
921
|
+
sco.categoriesBarActive,
|
922
|
+
sco.listenToPageInputPress,
|
923
|
+
sco.addNavBackgroundInit,
|
924
|
+
sco.refreshWaterFall,
|
925
|
+
].forEach((fn) => fn());
|
755
926
|
lazyload.enable && utils.lazyloadImg();
|
756
|
-
lightbox &&
|
927
|
+
lightbox &&
|
928
|
+
utils.lightbox(
|
929
|
+
document.querySelectorAll(
|
930
|
+
".article-container img:not(.flink-avatar,.gallery-group img, .no-lightbox)"
|
931
|
+
)
|
932
|
+
);
|
757
933
|
randomlink && randomLinksList();
|
758
|
-
|
934
|
+
if (is_post) {
|
935
|
+
if (ai_text) {
|
936
|
+
ai.init();
|
937
|
+
}
|
938
|
+
}
|
759
939
|
sco.switchComments();
|
760
940
|
initObserver();
|
761
941
|
if (is_home) {
|
762
942
|
showTodayCard();
|
763
943
|
sco.homeTypeit();
|
764
944
|
}
|
765
|
-
typeof updatePostsBasedOnComments ===
|
945
|
+
typeof updatePostsBasedOnComments === "function" &&
|
946
|
+
updatePostsBasedOnComments();
|
766
947
|
if (is_post || is_page) {
|
767
948
|
addHighlight();
|
768
949
|
tabs.init();
|
@@ -773,30 +954,39 @@ window.refreshFn = () => {
|
|
773
954
|
if (covercolor.enable) coverColor();
|
774
955
|
if (PAGE_CONFIG.toc) toc.init();
|
775
956
|
if (lure) tabs.lureAddListener();
|
776
|
-
page ===
|
957
|
+
page === "music" && initializeMusicPlayer();
|
777
958
|
forPostFn();
|
778
959
|
};
|
779
960
|
|
780
|
-
document.addEventListener(
|
781
|
-
[
|
961
|
+
document.addEventListener("DOMContentLoaded", () => {
|
962
|
+
[
|
963
|
+
addCopyright,
|
964
|
+
window.refreshFn,
|
965
|
+
asideStatus,
|
966
|
+
() => (window.onscroll = percent),
|
967
|
+
sco.initConsoleState,
|
968
|
+
].forEach((fn) => fn());
|
782
969
|
});
|
783
970
|
|
784
|
-
document.addEventListener(
|
971
|
+
document.addEventListener("visibilitychange", () => {
|
785
972
|
if (document.hidden) {
|
786
973
|
sco.wasPageHidden = true;
|
787
974
|
}
|
788
975
|
});
|
789
976
|
|
790
|
-
window.onkeydown = e => {
|
977
|
+
window.onkeydown = (e) => {
|
791
978
|
const { code, ctrlKey, shiftKey } = e;
|
792
|
-
if (
|
979
|
+
if (
|
980
|
+
code === "F12" ||
|
981
|
+
(ctrlKey && shiftKey && (code === "KeyI" || code === "KeyC"))
|
982
|
+
) {
|
793
983
|
utils.snackbarShow(GLOBAL_CONFIG.lang.f12, false, 3000);
|
794
984
|
}
|
795
|
-
if (code ===
|
985
|
+
if (code === "Escape") {
|
796
986
|
sco.hideConsole();
|
797
987
|
}
|
798
988
|
};
|
799
989
|
|
800
|
-
document.addEventListener(
|
990
|
+
document.addEventListener("copy", () => {
|
801
991
|
utils.snackbarShow(GLOBAL_CONFIG.lang.copy.success, false, 3000);
|
802
992
|
});
|