hexo-theme-solitude 1.12.0 → 1.12.2
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/.github/logo.svg +18 -42
- package/README.md +7 -16
- package/README_en-US.md +7 -17
- package/README_zh-Hant.md +13 -23
- package/_config.yml +27 -23
- package/languages/default.yml +14 -0
- package/languages/en.yml +14 -1
- package/languages/zh-CN.yml +13 -0
- package/languages/zh-TW.yml +13 -0
- package/layout/includes/body/mode.pug +3 -3
- package/layout/includes/inject/body.pug +2 -0
- package/layout/includes/inject/head.pug +2 -1
- package/layout/includes/widgets/home/carousel.pug +18 -1
- package/layout/includes/widgets/home/postList.pug +4 -3
- package/layout/includes/widgets/page/about/other.pug +71 -70
- package/layout/includes/widgets/post/copyright.pug +46 -0
- package/layout/includes/widgets/post/postMeta.pug +1 -1
- package/layout/includes/widgets/post/postNav.pug +4 -4
- package/layout/includes/widgets/third-party/news-comment/twikoo.pug +1 -0
- package/layout/includes/widgets/third-party/news-comment/valine.pug +1 -0
- package/layout/includes/widgets/third-party/news-comment/waline.pug +1 -0
- package/layout/post.pug +0 -22
- package/package.json +1 -1
- package/plugins.yml +6 -1
- package/scripts/event/merge_config.js +1 -0
- package/scripts/filter/post_image.js +13 -0
- package/scripts/helper/page.js +6 -2
- package/scripts/tags/btns.js +35 -0
- package/source/css/_global/index.styl +1 -0
- package/source/css/_highlight/color.styl +69 -131
- package/source/css/_highlight/highlight/diff.styl +34 -62
- package/source/css/_highlight/prismjs/diff.styl +60 -59
- package/source/css/_layout/article-container.styl +1 -5
- package/source/css/_layout/recent-post.styl +19 -7
- package/source/css/_page/_home/carousel.styl +2 -0
- package/source/css/_page/music.styl +8 -1
- package/source/css/_page/other.styl +1 -0
- package/source/css/_post/commentBarrage.styl +2 -11
- package/source/css/_post/copyright.styl +129 -2
- package/source/css/_post/meta.styl +1 -31
- package/source/css/_post/pagination.styl +13 -0
- package/source/css/_post/postAI.styl +2 -3
- package/source/css/_post/relatedPost.styl +115 -129
- package/source/css/_post/tools.styl +166 -274
- package/source/css/_tags/btns.styl +212 -0
- package/source/css/third_party/snackbar.min.css +1 -1
- package/source/css/third_party/tianli_talk.styl +16 -1
- package/source/js/main.js +97 -277
- package/source/js/music.js +1 -0
- package/source/js/right_menu.js +163 -136
package/source/js/main.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
// 移动端侧栏
|
2
1
|
const sidebarFn = () => {
|
3
2
|
const $toggleMenu = document.getElementById('toggle-menu');
|
4
3
|
const $mobileSidebarMenus = document.getElementById('sidebar-menus');
|
5
4
|
const $menuMask = document.getElementById('menu-mask');
|
6
5
|
const $body = document.body;
|
6
|
+
|
7
7
|
const toggleMobileSidebar = (isOpen) => {
|
8
8
|
utils.sidebarPaddingR();
|
9
9
|
$body.style.overflow = isOpen ? 'hidden' : '';
|
@@ -11,27 +11,26 @@ const sidebarFn = () => {
|
|
11
11
|
utils[isOpen ? 'fadeIn' : 'fadeOut']($menuMask, 0.5);
|
12
12
|
$mobileSidebarMenus.classList[isOpen ? 'add' : 'remove']('open');
|
13
13
|
}
|
14
|
-
|
15
|
-
$menuMask.addEventListener('click', () => {
|
14
|
+
const closeMobileSidebar = () => {
|
16
15
|
if ($mobileSidebarMenus.classList.contains('open')) {
|
17
16
|
toggleMobileSidebar(false);
|
18
17
|
}
|
19
|
-
}
|
18
|
+
}
|
19
|
+
$toggleMenu.addEventListener('click', () => toggleMobileSidebar(true));
|
20
|
+
$menuMask.addEventListener('click', closeMobileSidebar);
|
21
|
+
|
20
22
|
window.addEventListener('resize', () => {
|
21
23
|
if (utils.isHidden($toggleMenu) && $mobileSidebarMenus.classList.contains('open')) {
|
22
|
-
|
24
|
+
closeMobileSidebar();
|
23
25
|
}
|
24
26
|
sco.refreshWaterFall();
|
25
27
|
});
|
26
28
|
}
|
27
|
-
|
28
|
-
// 滚动事件监听
|
29
|
-
const scrollFn = function () {
|
29
|
+
const scrollFn = () => {
|
30
30
|
const innerHeight = window.innerHeight;
|
31
|
-
if (document.body.scrollHeight <= innerHeight) return;
|
32
31
|
let initTop = 0;
|
33
32
|
const $header = document.getElementById('page-header');
|
34
|
-
const throttledScroll = utils.throttle(
|
33
|
+
const throttledScroll = utils.throttle((e) => {
|
35
34
|
initThemeColor();
|
36
35
|
const currentTop = window.scrollY || document.documentElement.scrollTop;
|
37
36
|
const isDown = scrollDirection(currentTop);
|
@@ -46,7 +45,7 @@ const scrollFn = function () {
|
|
46
45
|
$header.classList.remove('nav-fixed', 'nav-visible');
|
47
46
|
}
|
48
47
|
}, 200);
|
49
|
-
window.addEventListener('scroll',
|
48
|
+
window.addEventListener('scroll', (e) => {
|
50
49
|
throttledScroll(e);
|
51
50
|
if (window.scrollY === 0) {
|
52
51
|
$header.classList.remove('nav-fixed', 'nav-visible');
|
@@ -59,8 +58,6 @@ const scrollFn = function () {
|
|
59
58
|
return result;
|
60
59
|
}
|
61
60
|
}
|
62
|
-
|
63
|
-
// 进度球
|
64
61
|
const percent = () => {
|
65
62
|
const docEl = document.documentElement;
|
66
63
|
const body = document.body;
|
@@ -74,15 +71,11 @@ const percent = () => {
|
|
74
71
|
percentDisplay.textContent = isNearEnd || scrolledPercent > 90 ? GLOBAL_CONFIG.lang.backtop : scrolledPercent;
|
75
72
|
document.querySelectorAll(".needEndHide").forEach(item => item.classList.toggle("hide", totalScrollableHeight - scrollPos < 100));
|
76
73
|
}
|
77
|
-
|
78
|
-
// 展示今日卡片
|
79
74
|
const showTodayCard = () => {
|
80
75
|
const el = document.getElementById('todayCard');
|
81
76
|
const topGroup = document.querySelector('.topGroup');
|
82
77
|
topGroup?.addEventListener('mouseleave', () => el?.classList.remove('hide'));
|
83
78
|
}
|
84
|
-
|
85
|
-
// 初始化 IntersectionObserver
|
86
79
|
const initObserver = () => {
|
87
80
|
const commentElement = document.getElementById("post-comment");
|
88
81
|
const paginationElement = document.getElementById("pagination");
|
@@ -100,8 +93,6 @@ const initObserver = () => {
|
|
100
93
|
observer.observe(commentElement);
|
101
94
|
}
|
102
95
|
};
|
103
|
-
|
104
|
-
// 复制版权信息
|
105
96
|
const addCopyright = () => {
|
106
97
|
if (!GLOBAL_CONFIG.copyright) return;
|
107
98
|
const {limit, author, link, source, info} = GLOBAL_CONFIG.copyright;
|
@@ -112,25 +103,15 @@ const addCopyright = () => {
|
|
112
103
|
e.clipboardData.setData('text', text);
|
113
104
|
});
|
114
105
|
};
|
115
|
-
|
116
|
-
// 侧边栏状态
|
117
106
|
const asideStatus = () => {
|
118
107
|
const status = utils.saveToLocal.get('aside-status');
|
119
108
|
document.documentElement.classList.toggle('hide-aside', status === 'hide');
|
120
109
|
}
|
121
|
-
|
122
|
-
// 初始化主题色
|
123
110
|
function initThemeColor() {
|
124
111
|
const currentTop = window.scrollY || document.documentElement.scrollTop;
|
125
112
|
const themeColor = currentTop > 0 ? '--efu-card-bg' : PAGE_CONFIG.is_post ? '--efu-main' : '--efu-background';
|
126
113
|
applyThemeColor(getComputedStyle(document.documentElement).getPropertyValue(themeColor));
|
127
114
|
}
|
128
|
-
|
129
|
-
/**
|
130
|
-
* applyThemeColor
|
131
|
-
* @description 应用主题色
|
132
|
-
* @param color
|
133
|
-
*/
|
134
115
|
function applyThemeColor(color) {
|
135
116
|
const themeColorMeta = document.querySelector('meta[name="theme-color"]');
|
136
117
|
const appleMobileWebAppMeta = document.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]');
|
@@ -140,39 +121,17 @@ function applyThemeColor(color) {
|
|
140
121
|
document.body.style.backgroundColor = color;
|
141
122
|
}
|
142
123
|
}
|
143
|
-
|
144
|
-
/**
|
145
|
-
* handleThemeChange
|
146
|
-
* @description 切换主题色
|
147
|
-
* @param mode
|
148
|
-
*/
|
149
124
|
const handleThemeChange = mode => {
|
150
125
|
const themeChange = window.globalFn?.themeChange || {}
|
151
126
|
for (let key in themeChange) {
|
152
127
|
themeChange[key](mode)
|
153
128
|
}
|
154
129
|
}
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
// musicPlaying 是否正在播放音乐
|
161
|
-
let musicPlaying = false
|
162
|
-
// is_rm 是否启用右键菜单
|
163
|
-
let is_rm = typeof rm !== 'undefined'
|
164
|
-
|
165
|
-
/**
|
166
|
-
* sco
|
167
|
-
* @description solitude 主题的一些方法
|
168
|
-
* @type {{showConsole: (function(): boolean), setTimeState: sco.setTimeState, toTop: (function(): void), changeTimeFormat(*): void, hideCookie: sco.hideCookie, owoBig(*): void, switchDarkMode: sco.switchDarkMode, openAllTags: sco.openAllTags, switchHideAside: sco.switchHideAside, addRuntime: sco.addRuntime, refreshWaterFall: sco.refreshWaterFall, categoriesBarActive: sco.categoriesBarActive, addNavBackgroundInit: sco.addNavBackgroundInit, toPage: sco.toPage, changeSayHelloText: sco.changeSayHelloText, initConsoleState: (function(): void), switchComments(): void, switchKeyboard: sco.switchKeyboard, listenToPageInputPress: sco.listenToPageInputPress, scrollTo: sco.scrollTo, musicToggle: sco.musicToggle, toTalk: sco.toTalk, switchCommentBarrage: sco.switchCommentBarrage, hideTodayCard: (function(): void), scrollCategoryBarToRight: sco.scrollCategoryBarToRight, scrollToComment: sco.scrollToComment, initbbtalk: sco.initbbtalk, tagPageActive: sco.tagPageActive, hideConsole: (function(): void), addPhotoFigcaption: sco.addPhotoFigcaption}}
|
169
|
-
*/
|
170
|
-
let sco = {
|
171
|
-
/**
|
172
|
-
* hideCookie
|
173
|
-
* @description 隐藏 cookie 通知
|
174
|
-
*/
|
175
|
-
hideCookie: function () {
|
130
|
+
const sco = {
|
131
|
+
lastSayHello: "",
|
132
|
+
wasPageHidden: false,
|
133
|
+
musicPlaying: false,
|
134
|
+
hideCookie() {
|
176
135
|
const cookiesWindow = document.getElementById("cookies-window");
|
177
136
|
if (cookiesWindow) {
|
178
137
|
setTimeout(() => {
|
@@ -181,12 +140,7 @@ let sco = {
|
|
181
140
|
}, 3000);
|
182
141
|
}
|
183
142
|
},
|
184
|
-
|
185
|
-
* scrollTo
|
186
|
-
* @description 滚动到指定元素
|
187
|
-
* @param elementId
|
188
|
-
*/
|
189
|
-
scrollTo: function (elementId) {
|
143
|
+
scrollTo(elementId) {
|
190
144
|
const targetElement = document.getElementById(elementId);
|
191
145
|
if (targetElement) {
|
192
146
|
const targetPosition = targetElement.getBoundingClientRect().top + window.pageYOffset - 80;
|
@@ -196,20 +150,16 @@ let sco = {
|
|
196
150
|
});
|
197
151
|
}
|
198
152
|
},
|
199
|
-
|
200
|
-
* musicToggle
|
201
|
-
* @description 音乐播放开关
|
202
|
-
*/
|
203
|
-
musicToggle: function () {
|
153
|
+
musicToggle() {
|
204
154
|
const $music = document.querySelector('#nav-music');
|
205
155
|
const $meting = document.querySelector('meting-js');
|
206
156
|
const $console = document.getElementById('consoleMusic');
|
207
157
|
const $rm_text = document.querySelector('#menu-music-toggle span');
|
208
158
|
const $rm_icon = document.querySelector('#menu-music-toggle i');
|
209
|
-
musicPlaying = !musicPlaying;
|
210
|
-
$music.classList.toggle("playing", musicPlaying);
|
211
|
-
$console.classList.toggle("on", musicPlaying);
|
212
|
-
if (musicPlaying) {
|
159
|
+
this.musicPlaying = !this.musicPlaying;
|
160
|
+
$music.classList.toggle("playing", this.musicPlaying);
|
161
|
+
$console.classList.toggle("on", this.musicPlaying);
|
162
|
+
if (this.musicPlaying) {
|
213
163
|
$meting.aplayer.play();
|
214
164
|
rm?.menuItems.music[0] && ($rm_text.textContent = GLOBAL_CONFIG.right_menu.music.stop) && ($rm_icon.className = 'solitude st-pause-fill')
|
215
165
|
} else {
|
@@ -217,11 +167,7 @@ let sco = {
|
|
217
167
|
rm?.menuItems.music[0] && ($rm_text.textContent = GLOBAL_CONFIG.right_menu.music.start) && ($rm_icon.className = 'solitude st-play-fill')
|
218
168
|
}
|
219
169
|
},
|
220
|
-
|
221
|
-
* switchCommentBarrage
|
222
|
-
* @description 切换评论弹幕
|
223
|
-
*/
|
224
|
-
switchCommentBarrage: function () {
|
170
|
+
switchCommentBarrage() {
|
225
171
|
let commentBarrageElement = document.querySelector(".comment-barrage");
|
226
172
|
if (!commentBarrageElement) return;
|
227
173
|
const isDisplayed = window.getComputedStyle(commentBarrageElement).display === "flex";
|
@@ -230,11 +176,7 @@ let sco = {
|
|
230
176
|
utils.saveToLocal.set("commentBarrageSwitch", !isDisplayed, .2);
|
231
177
|
rm?.menuItems.barrage && rm.barrage(isDisplayed)
|
232
178
|
},
|
233
|
-
|
234
|
-
* switchHideAside
|
235
|
-
* @description 切换侧边栏
|
236
|
-
*/
|
237
|
-
switchHideAside: function () {
|
179
|
+
switchHideAside() {
|
238
180
|
const htmlClassList = document.documentElement.classList;
|
239
181
|
const consoleHideAside = document.querySelector("#consoleHideAside");
|
240
182
|
const isHideAside = htmlClassList.contains("hide-aside");
|
@@ -242,76 +184,43 @@ let sco = {
|
|
242
184
|
htmlClassList.toggle("hide-aside");
|
243
185
|
consoleHideAside.classList.toggle("on", !isHideAside);
|
244
186
|
},
|
245
|
-
|
246
|
-
|
247
|
-
* @description 切换快捷键
|
248
|
-
*/
|
249
|
-
switchKeyboard: function () {
|
250
|
-
sco_keyboards = !sco_keyboards;
|
187
|
+
switchKeyboard() {
|
188
|
+
this.sco_keyboards = !this.sco_keyboards;
|
251
189
|
const consoleKeyboard = document.querySelector("#consoleKeyboard");
|
252
|
-
const keyboardFunction = sco_keyboards ? openKeyboard : closeKeyboard;
|
253
|
-
consoleKeyboard.classList.toggle("on", sco_keyboards);
|
190
|
+
const keyboardFunction = this.sco_keyboards ? openKeyboard : closeKeyboard;
|
191
|
+
consoleKeyboard.classList.toggle("on", this.sco_keyboards);
|
254
192
|
keyboardFunction();
|
255
|
-
localStorage.setItem("keyboard", sco_keyboards);
|
193
|
+
localStorage.setItem("keyboard", this.sco_keyboards);
|
256
194
|
document.getElementById('keyboard-tips')?.classList.remove('show');
|
257
195
|
},
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
/**
|
264
|
-
* changeSayHelloText
|
265
|
-
* @description 更改打招呼文本
|
266
|
-
*/
|
267
|
-
changeSayHelloText: function () {
|
196
|
+
initConsoleState() {
|
197
|
+
const consoleHideAside = document.querySelector("#consoleHideAside");
|
198
|
+
consoleHideAside.classList.toggle("on", !document.documentElement.classList.contains("hide-aside"));
|
199
|
+
},
|
200
|
+
changeSayHelloText() {
|
268
201
|
const greetings = GLOBAL_CONFIG.aside.sayhello2;
|
269
202
|
const greetingElement = document.getElementById("author-info__sayhi");
|
270
203
|
let randomGreeting;
|
271
204
|
do {
|
272
205
|
randomGreeting = greetings[Math.floor(Math.random() * greetings.length)];
|
273
|
-
} while (randomGreeting === lastSayHello);
|
206
|
+
} while (randomGreeting === this.lastSayHello);
|
274
207
|
greetingElement.textContent = randomGreeting;
|
275
|
-
lastSayHello = randomGreeting;
|
208
|
+
this.lastSayHello = randomGreeting;
|
276
209
|
},
|
277
|
-
|
278
|
-
* switchDarkMode
|
279
|
-
* @description 切换显示模式
|
280
|
-
*/
|
281
|
-
switchDarkMode: function () {
|
210
|
+
switchDarkMode() {
|
282
211
|
const isDarkMode = document.documentElement.getAttribute('data-theme') === 'dark';
|
283
212
|
const newMode = isDarkMode ? 'light' : 'dark';
|
284
213
|
document.documentElement.setAttribute('data-theme', newMode);
|
285
214
|
utils.saveToLocal.set('theme', newMode, 0.02);
|
286
215
|
utils.snackbarShow(GLOBAL_CONFIG.lang.theme[newMode], false, 2000);
|
287
|
-
if
|
216
|
+
if(typeof rm === 'object') rm.mode(!isDarkMode) && rm.hideRightMenu();
|
288
217
|
handleThemeChange(newMode);
|
289
218
|
},
|
290
|
-
/**
|
291
|
-
* hideTodayCard
|
292
|
-
* @description 隐藏今日卡片
|
293
|
-
*/
|
294
219
|
hideTodayCard: () => document.getElementById('todayCard').classList.add('hide'),
|
295
|
-
/**
|
296
|
-
* toTop
|
297
|
-
* @description 返回顶部
|
298
|
-
*/
|
299
220
|
toTop: () => utils.scrollToDest(0),
|
300
|
-
/**
|
301
|
-
* showConsole
|
302
|
-
* @description 显示控制台
|
303
|
-
*/
|
304
221
|
showConsole: () => document.getElementById('console')?.classList.toggle('show', true),
|
305
|
-
/**
|
306
|
-
* hideConsole
|
307
|
-
* @description 隐藏控制台
|
308
|
-
*/
|
309
222
|
hideConsole: () => document.getElementById('console')?.classList.remove('show'),
|
310
|
-
|
311
|
-
* refreshWaterFall
|
312
|
-
* @description 刷新瀑布流
|
313
|
-
*/
|
314
|
-
refreshWaterFall: function () {
|
223
|
+
refreshWaterFall() {
|
315
224
|
const observer = new IntersectionObserver((entries) => {
|
316
225
|
entries.forEach(entry => {
|
317
226
|
if (entry.isIntersecting) {
|
@@ -323,25 +232,16 @@ let sco = {
|
|
323
232
|
});
|
324
233
|
document.querySelectorAll('.waterfall').forEach(el => observer.observe(el));
|
325
234
|
},
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
*/
|
330
|
-
addRuntime: function () {
|
331
|
-
let el = document.getElementById('runtimeshow')
|
332
|
-
el && GLOBAL_CONFIG.runtime && (el.innerText = utils.timeDiff(new Date(GLOBAL_CONFIG.runtime), new Date()) + GLOBAL_CONFIG.lang.day)
|
235
|
+
addRuntime() {
|
236
|
+
let el = document.getElementById('runtimeshow');
|
237
|
+
el && GLOBAL_CONFIG.runtime && (el.innerText = utils.timeDiff(new Date(GLOBAL_CONFIG.runtime), new Date()) + GLOBAL_CONFIG.lang.day);
|
333
238
|
},
|
334
|
-
|
335
|
-
* toTalk
|
336
|
-
* @description 回复评论
|
337
|
-
* @param txt
|
338
|
-
*/
|
339
|
-
toTalk: function (txt) {
|
239
|
+
toTalk(txt) {
|
340
240
|
const inputs = ["#wl-edit", ".el-textarea__inner", "#veditor", ".atk-textarea"];
|
341
241
|
inputs.forEach(selector => {
|
342
242
|
const el = document.querySelector(selector);
|
343
243
|
if (el) {
|
344
|
-
el.dispatchEvent(new Event('input', {bubble: true, cancelable: true}));
|
244
|
+
el.dispatchEvent(new Event('input', { bubble: true, cancelable: true }));
|
345
245
|
el.value = '> ' + txt.replace(/\n/g, '\n> ') + '\n\n';
|
346
246
|
utils.scrollToDest(utils.getEleTop(document.getElementById('post-comment')), 300);
|
347
247
|
el.focus();
|
@@ -350,11 +250,7 @@ let sco = {
|
|
350
250
|
});
|
351
251
|
utils.snackbarShow(GLOBAL_CONFIG.lang.totalk, false, 2000);
|
352
252
|
},
|
353
|
-
|
354
|
-
* initbbtalk
|
355
|
-
* @description 初始化 bbtalk
|
356
|
-
*/
|
357
|
-
initbbtalk: function () {
|
253
|
+
initbbtalk() {
|
358
254
|
const bberTalkElement = document.querySelector('#bber-talk');
|
359
255
|
if (bberTalkElement) {
|
360
256
|
new Swiper('.swiper-container', {
|
@@ -367,28 +263,14 @@ let sco = {
|
|
367
263
|
});
|
368
264
|
}
|
369
265
|
},
|
370
|
-
|
371
|
-
* addPhotoFigcaption
|
372
|
-
* @description 添加图片标题
|
373
|
-
*/
|
374
|
-
addPhotoFigcaption: function () {
|
266
|
+
addPhotoFigcaption() {
|
375
267
|
document.querySelectorAll('#article-container img:not(.gallery-item img)').forEach(image => {
|
376
268
|
const captionText = image.getAttribute('alt');
|
377
269
|
captionText && image.insertAdjacentHTML('afterend', `<div class="img-alt is-center">${captionText}</div>`);
|
378
270
|
});
|
379
271
|
},
|
380
|
-
|
381
|
-
|
382
|
-
* @description 滚动到评论
|
383
|
-
*/
|
384
|
-
scrollToComment: function () {
|
385
|
-
utils.scrollToDest(utils.getEleTop(document.getElementById('post-comment')), 300)
|
386
|
-
},
|
387
|
-
/**
|
388
|
-
* setTimeState
|
389
|
-
* @description 设置时间状态
|
390
|
-
*/
|
391
|
-
setTimeState: function () {
|
272
|
+
scrollToComment: () => utils.scrollToDest(utils.getEleTop(document.getElementById('post-comment')), 300),
|
273
|
+
setTimeState() {
|
392
274
|
const el = document.getElementById('author-info__sayhi');
|
393
275
|
if (el) {
|
394
276
|
const hours = new Date().getHours();
|
@@ -408,29 +290,25 @@ let sco = {
|
|
408
290
|
const nick = localData ? (localData.nick ? localData.nick : localData.display_name) : null;
|
409
291
|
|
410
292
|
let prefix;
|
411
|
-
if (wasPageHidden) {
|
293
|
+
if (this.wasPageHidden) {
|
412
294
|
prefix = GLOBAL_CONFIG.aside.sayhello3.back + nick;
|
413
|
-
wasPageHidden = false;
|
295
|
+
this.wasPageHidden = false;
|
414
296
|
} else {
|
415
297
|
prefix = GLOBAL_CONFIG.aside.sayhello3.prefix + nick;
|
416
298
|
}
|
417
299
|
|
418
300
|
const greetings = [
|
419
|
-
{start: 0, end: 5, text: nick ? prefix : lang.goodnight},
|
420
|
-
{start: 6, end: 10, text: nick ? prefix : lang.morning},
|
421
|
-
{start: 11, end: 14, text: nick ? prefix : lang.noon},
|
422
|
-
{start: 15, end: 18, text: nick ? prefix : lang.afternoon},
|
423
|
-
{start: 19, end: 24, text: nick ? prefix : lang.night},
|
301
|
+
{ start: 0, end: 5, text: nick ? prefix : lang.goodnight },
|
302
|
+
{ start: 6, end: 10, text: nick ? prefix : lang.morning },
|
303
|
+
{ start: 11, end: 14, text: nick ? prefix : lang.noon },
|
304
|
+
{ start: 15, end: 18, text: nick ? prefix : lang.afternoon },
|
305
|
+
{ start: 19, end: 24, text: nick ? prefix : lang.night },
|
424
306
|
];
|
425
307
|
const greeting = greetings.find(g => hours >= g.start && hours <= g.end);
|
426
308
|
el.innerText = greeting.text;
|
427
309
|
}
|
428
310
|
},
|
429
|
-
|
430
|
-
* tagPageActive
|
431
|
-
* @description 标签页当前标签高亮
|
432
|
-
*/
|
433
|
-
tagPageActive: function () {
|
311
|
+
tagPageActive() {
|
434
312
|
const decodedPath = decodeURIComponent(window.location.pathname);
|
435
313
|
const isTagPage = /\/tags\/.*?\//.test(decodedPath);
|
436
314
|
if (isTagPage) {
|
@@ -444,11 +322,7 @@ let sco = {
|
|
444
322
|
}
|
445
323
|
}
|
446
324
|
},
|
447
|
-
|
448
|
-
* categoriesBarActive
|
449
|
-
* @description 分类栏当前分类高亮
|
450
|
-
*/
|
451
|
-
categoriesBarActive: function () {
|
325
|
+
categoriesBarActive() {
|
452
326
|
const categoryBar = document.querySelector("#category-bar");
|
453
327
|
const currentPath = decodeURIComponent(window.location.pathname);
|
454
328
|
const isHomePage = currentPath === "/";
|
@@ -462,20 +336,16 @@ let sco = {
|
|
462
336
|
}
|
463
337
|
}
|
464
338
|
},
|
465
|
-
|
466
|
-
* scrollCategoryBarToRight
|
467
|
-
* @description 滚动分类栏到右侧
|
468
|
-
*/
|
469
|
-
scrollCategoryBarToRight: function () {
|
339
|
+
scrollCategoryBarToRight() {
|
470
340
|
const scrollBar = document.getElementById("category-bar-items");
|
471
341
|
const nextElement = document.getElementById("category-bar-next");
|
472
342
|
if (scrollBar) {
|
473
343
|
const isScrollBarAtEnd = () => scrollBar.scrollLeft + scrollBar.clientWidth >= scrollBar.scrollWidth - 8;
|
474
344
|
const scroll = () => {
|
475
345
|
if (isScrollBarAtEnd()) {
|
476
|
-
scrollBar.scroll({left: 0, behavior: "smooth"});
|
346
|
+
scrollBar.scroll({ left: 0, behavior: "smooth" });
|
477
347
|
} else {
|
478
|
-
scrollBar.scrollBy({left: scrollBar.clientWidth, behavior: "smooth"});
|
348
|
+
scrollBar.scrollBy({ left: scrollBar.clientWidth, behavior: "smooth" });
|
479
349
|
}
|
480
350
|
};
|
481
351
|
scrollBar.addEventListener("scroll", () => {
|
@@ -487,19 +357,11 @@ let sco = {
|
|
487
357
|
scroll();
|
488
358
|
}
|
489
359
|
},
|
490
|
-
|
491
|
-
* openAllTags
|
492
|
-
* @description 展开所有标签
|
493
|
-
*/
|
494
|
-
openAllTags: () => {
|
360
|
+
openAllTags() {
|
495
361
|
document.querySelectorAll(".card-allinfo .card-tag-cloud").forEach(tagCloudElement => tagCloudElement.classList.add("all-tags"));
|
496
362
|
document.getElementById("more-tags-btn")?.remove();
|
497
363
|
},
|
498
|
-
|
499
|
-
* listenToPageInputPress
|
500
|
-
* @description 监听页码输入
|
501
|
-
*/
|
502
|
-
listenToPageInputPress: function () {
|
364
|
+
listenToPageInputPress() {
|
503
365
|
const toGroup = document.querySelector(".toPageGroup")
|
504
366
|
const pageText = document.getElementById("toPageText");
|
505
367
|
if (!pageText) return;
|
@@ -523,19 +385,11 @@ let sco = {
|
|
523
385
|
}
|
524
386
|
});
|
525
387
|
},
|
526
|
-
|
527
|
-
* addNavBackgroundInit
|
528
|
-
* @description 添加导航背景初始化
|
529
|
-
*/
|
530
|
-
addNavBackgroundInit: function () {
|
388
|
+
addNavBackgroundInit() {
|
531
389
|
const scrollTop = document.documentElement.scrollTop;
|
532
390
|
(scrollTop !== 0) && document.getElementById("page-header").classList.add("nav-fixed", "nav-visible");
|
533
391
|
},
|
534
|
-
|
535
|
-
* toPage
|
536
|
-
* @description 跳转到指定页
|
537
|
-
*/
|
538
|
-
toPage: function () {
|
392
|
+
toPage() {
|
539
393
|
const pageNumbers = document.querySelectorAll(".page-number");
|
540
394
|
const maxPageNumber = parseInt(pageNumbers[pageNumbers.length - 1].innerHTML);
|
541
395
|
const inputElement = document.getElementById("toPageText");
|
@@ -544,11 +398,6 @@ let sco = {
|
|
544
398
|
? window.location.href.replace(/\/page\/\d+\/$/, "/") + "page/" + inputPageNumber + "/"
|
545
399
|
: '/';
|
546
400
|
},
|
547
|
-
/**
|
548
|
-
* owobig
|
549
|
-
* @description owo 大图
|
550
|
-
* @param owoSelector
|
551
|
-
*/
|
552
401
|
owoBig(owoSelector) {
|
553
402
|
let owoBig = document.getElementById('owo-big');
|
554
403
|
if (!owoBig) {
|
@@ -581,11 +430,6 @@ let sco = {
|
|
581
430
|
document.addEventListener('mouseover', showOwoBig);
|
582
431
|
document.addEventListener('mouseout', hideOwoBig);
|
583
432
|
},
|
584
|
-
/**
|
585
|
-
* changeTimeFormat
|
586
|
-
* @description 更改时间格式
|
587
|
-
* @param selector
|
588
|
-
*/
|
589
433
|
changeTimeFormat(selector) {
|
590
434
|
selector.forEach(item => {
|
591
435
|
const timeVal = item.getAttribute('datetime')
|
@@ -593,10 +437,6 @@ let sco = {
|
|
593
437
|
item.style.display = 'inline'
|
594
438
|
})
|
595
439
|
},
|
596
|
-
/**
|
597
|
-
* switchComments
|
598
|
-
* @description 切换评论
|
599
|
-
*/
|
600
440
|
switchComments() {
|
601
441
|
const switchBtn = document.getElementById('switch-btn')
|
602
442
|
if (!switchBtn) return
|
@@ -611,12 +451,7 @@ let sco = {
|
|
611
451
|
}
|
612
452
|
utils.addEventListenerPjax(switchBtn, 'click', handleSwitchBtn)
|
613
453
|
}
|
614
|
-
}
|
615
|
-
|
616
|
-
/**
|
617
|
-
* addHighlight
|
618
|
-
* @description 添加代码高亮
|
619
|
-
*/
|
454
|
+
};
|
620
455
|
const addHighlight = () => {
|
621
456
|
const highlight = GLOBAL_CONFIG.highlight;
|
622
457
|
if (!highlight) return;
|
@@ -693,11 +528,6 @@ const addHighlight = () => {
|
|
693
528
|
})
|
694
529
|
}
|
695
530
|
}
|
696
|
-
|
697
|
-
/**
|
698
|
-
* toc
|
699
|
-
* @description 目录
|
700
|
-
*/
|
701
531
|
class toc {
|
702
532
|
static init() {
|
703
533
|
const tocContainer = document.getElementById('card-toc')
|
@@ -714,13 +544,11 @@ class toc {
|
|
714
544
|
})
|
715
545
|
this.active(el)
|
716
546
|
}
|
717
|
-
|
718
547
|
static active(toc) {
|
719
548
|
const $article = document.getElementById('article-container')
|
720
549
|
const $tocContent = document.getElementById('toc-content')
|
721
550
|
const list = $article.querySelectorAll('h1,h2,h3,h4,h5,h6')
|
722
551
|
let detectItem = ''
|
723
|
-
|
724
552
|
function autoScroll(el) {
|
725
553
|
const activePosition = el.getBoundingClientRect().top
|
726
554
|
const sidebarScrollTop = $tocContent.scrollTop
|
@@ -731,7 +559,6 @@ class toc {
|
|
731
559
|
$tocContent.scrollTop = sidebarScrollTop - 150
|
732
560
|
}
|
733
561
|
}
|
734
|
-
|
735
562
|
function findHeadPosition(top) {
|
736
563
|
if (top === 0) return false
|
737
564
|
let currentIndex = ''
|
@@ -755,7 +582,6 @@ class toc {
|
|
755
582
|
}
|
756
583
|
}
|
757
584
|
}
|
758
|
-
|
759
585
|
window.tocScrollFn = utils.throttle(function () {
|
760
586
|
const currentTop = window.scrollY || document.documentElement.scrollTop
|
761
587
|
findHeadPosition(currentTop)
|
@@ -763,48 +589,40 @@ class toc {
|
|
763
589
|
window.addEventListener('scroll', tocScrollFn)
|
764
590
|
}
|
765
591
|
}
|
766
|
-
|
767
|
-
/**
|
768
|
-
* tabs
|
769
|
-
* @description 外挂标签tabs
|
770
|
-
*/
|
771
592
|
class tabs {
|
772
593
|
static init() {
|
773
|
-
this.clickFnOfTabs()
|
774
|
-
this.backToTop()
|
594
|
+
this.clickFnOfTabs();
|
595
|
+
this.backToTop();
|
775
596
|
}
|
776
|
-
|
777
597
|
static clickFnOfTabs() {
|
778
|
-
document.querySelectorAll('#article-container .tab > button').forEach(
|
598
|
+
document.querySelectorAll('#article-container .tab > button').forEach((item) => {
|
779
599
|
item.addEventListener('click', function (e) {
|
780
|
-
const that = this
|
781
|
-
const $tabItem = that.parentNode
|
600
|
+
const that = this;
|
601
|
+
const $tabItem = that.parentNode;
|
782
602
|
if (!$tabItem.classList.contains('active')) {
|
783
|
-
const $tabContent = $tabItem.parentNode.nextElementSibling
|
784
|
-
const $siblings = utils.siblings($tabItem, '.active')[0]
|
785
|
-
$siblings && $siblings.classList.remove('active')
|
786
|
-
$tabItem.classList.add('active')
|
787
|
-
const tabId = that.getAttribute('data-href').replace('#', '')
|
788
|
-
const childList = [...$tabContent.children]
|
789
|
-
childList.forEach(item => {
|
790
|
-
if (item.id === tabId) item.classList.add('active')
|
791
|
-
else item.classList.remove('active')
|
792
|
-
})
|
603
|
+
const $tabContent = $tabItem.parentNode.nextElementSibling;
|
604
|
+
const $siblings = utils.siblings($tabItem, '.active')[0];
|
605
|
+
$siblings && $siblings.classList.remove('active');
|
606
|
+
$tabItem.classList.add('active');
|
607
|
+
const tabId = that.getAttribute('data-href').replace('#', '');
|
608
|
+
const childList = [...$tabContent.children];
|
609
|
+
childList.forEach((item) => {
|
610
|
+
if (item.id === tabId) item.classList.add('active');
|
611
|
+
else item.classList.remove('active');
|
612
|
+
});
|
793
613
|
}
|
794
|
-
})
|
795
|
-
})
|
614
|
+
});
|
615
|
+
});
|
796
616
|
}
|
797
|
-
|
798
617
|
static backToTop() {
|
799
|
-
document.querySelectorAll('#article-container .tabs .tab-to-top').forEach(
|
618
|
+
document.querySelectorAll('#article-container .tabs .tab-to-top').forEach((item) => {
|
800
619
|
item.addEventListener('click', function () {
|
801
|
-
utils.scrollToDest(utils.getEleTop(item.parentElement.parentElement.parentNode), 300)
|
802
|
-
|
803
|
-
|
804
|
-
})
|
620
|
+
utils.scrollToDest(utils.getEleTop(item.parentElement.parentElement.parentNode), 300);
|
621
|
+
});
|
622
|
+
});
|
805
623
|
}
|
806
624
|
}
|
807
|
-
|
625
|
+
|
808
626
|
window.refreshFn = () => {
|
809
627
|
const {is_home, is_page, page, is_post} = PAGE_CONFIG;
|
810
628
|
const {runtime, lazyload, lightbox, randomlink, covercolor, post_ai} = GLOBAL_CONFIG;
|
@@ -827,21 +645,23 @@ window.refreshFn = () => {
|
|
827
645
|
if (covercolor.enable) coverColor();
|
828
646
|
if (PAGE_CONFIG.toc) toc.init();
|
829
647
|
}
|
830
|
-
// 页面加载完成后执行
|
831
648
|
document.addEventListener('DOMContentLoaded', () => {
|
832
649
|
[addCopyright, sco.initConsoleState, window.refreshFn, asideStatus, () => window.onscroll = percent].forEach(fn => fn());
|
833
650
|
});
|
834
|
-
// 监听切换标签页
|
835
651
|
document.addEventListener('visibilitychange', () => {
|
836
652
|
if (document.hidden) {
|
837
|
-
wasPageHidden = true;
|
653
|
+
sco.wasPageHidden = true;
|
838
654
|
}
|
839
655
|
});
|
840
|
-
// 一些快捷键绑定
|
841
656
|
window.onkeydown = e => {
|
842
|
-
const {keyCode, ctrlKey, shiftKey} = e;
|
843
|
-
if (keyCode === 123 || (ctrlKey && shiftKey && keyCode === 67))
|
844
|
-
|
657
|
+
const { keyCode, ctrlKey, shiftKey } = e;
|
658
|
+
if (keyCode === 123 || (ctrlKey && shiftKey && keyCode === 67)) {
|
659
|
+
utils.snackbarShow(GLOBAL_CONFIG.lang.f12, false, 3000);
|
660
|
+
}
|
661
|
+
if (keyCode === 27) {
|
662
|
+
sco.hideConsole();
|
663
|
+
}
|
845
664
|
};
|
846
|
-
|
847
|
-
|
665
|
+
document.addEventListener('copy', () => {
|
666
|
+
utils.snackbarShow(GLOBAL_CONFIG.lang.copy.success, false, 3000);
|
667
|
+
});
|