hexo-theme-solitude 1.12.0 → 1.12.1

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