hexo-theme-shokax 0.3.13 → 0.4.0-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. package/_config.yml +11 -5
  2. package/layout/_mixin/comment.pug +4 -4
  3. package/package.json +4 -4
  4. package/scripts/filters/locals.d.ts +1 -0
  5. package/scripts/filters/locals.ts +59 -0
  6. package/scripts/filters/post.d.ts +0 -0
  7. package/scripts/filters/post.ts +6 -0
  8. package/scripts/generaters/archive.d.ts +1 -0
  9. package/scripts/generaters/archive.ts +144 -0
  10. package/scripts/generaters/config.d.ts +1 -0
  11. package/scripts/generaters/config.ts +52 -0
  12. package/scripts/generaters/images.d.ts +1 -0
  13. package/scripts/generaters/images.ts +26 -0
  14. package/scripts/generaters/index.d.ts +1 -0
  15. package/scripts/generaters/index.ts +110 -0
  16. package/scripts/generaters/pages.d.ts +0 -0
  17. package/scripts/generaters/pages.ts +16 -0
  18. package/scripts/generaters/script.d.ts +1 -0
  19. package/scripts/generaters/script.js +22 -6
  20. package/scripts/generaters/script.ts +110 -0
  21. package/scripts/helpers/asset.d.ts +1 -0
  22. package/scripts/helpers/asset.ts +158 -0
  23. package/scripts/helpers/engine.d.ts +1 -0
  24. package/scripts/helpers/engine.ts +171 -0
  25. package/scripts/helpers/list_categories.d.ts +1 -0
  26. package/scripts/helpers/list_categories.ts +104 -0
  27. package/scripts/helpers/summary_ai.d.ts +1 -0
  28. package/scripts/helpers/summary_ai.ts +100 -0
  29. package/scripts/helpers/symbols_count_time.d.ts +1 -0
  30. package/scripts/helpers/symbols_count_time.ts +76 -0
  31. package/scripts/plugin/check.d.ts +1 -0
  32. package/scripts/plugin/check.ts +35 -0
  33. package/scripts/plugin/index.d.ts +6 -0
  34. package/scripts/plugin/index.ts +52 -0
  35. package/scripts/plugin/lib/injects-point.d.ts +5 -0
  36. package/scripts/plugin/lib/injects-point.ts +20 -0
  37. package/scripts/plugin/lib/injects.d.ts +2 -0
  38. package/scripts/plugin/lib/injects.ts +101 -0
  39. package/scripts/tags/links.d.ts +1 -0
  40. package/scripts/tags/links.ts +75 -0
  41. package/scripts/tags/media.d.ts +1 -0
  42. package/scripts/tags/media.ts +19 -0
  43. package/source/js/_app/components/sidebar.ts +237 -0
  44. package/source/js/_app/globals/globalVars.ts +98 -0
  45. package/source/js/_app/globals/handles.ts +122 -0
  46. package/source/js/_app/globals/themeColor.ts +64 -0
  47. package/source/js/_app/globals/thirdparty.ts +63 -0
  48. package/source/js/_app/globals/tools.ts +74 -0
  49. package/source/js/_app/library/anime.ts +109 -0
  50. package/source/js/_app/library/declare.d.ts +117 -0
  51. package/source/js/_app/library/dom.ts +26 -0
  52. package/source/js/_app/library/libtype.d.ts +4 -0
  53. package/source/js/_app/library/loadFile.ts +41 -0
  54. package/source/js/_app/library/proto.ts +143 -0
  55. package/source/js/_app/library/scriptPjax.ts +72 -0
  56. package/source/js/_app/library/storage.ts +12 -0
  57. package/source/js/_app/library/vue.ts +60 -0
  58. package/source/js/_app/page/common.ts +42 -0
  59. package/source/js/_app/page/fancybox.ts +70 -0
  60. package/source/js/_app/page/post.ts +265 -0
  61. package/source/js/_app/page/search.ts +129 -0
  62. package/source/js/_app/page/tab.ts +59 -0
  63. package/source/js/_app/pjax/domInit.ts +95 -0
  64. package/source/js/_app/pjax/refresh.ts +75 -0
  65. package/source/js/_app/pjax/siteInit.ts +67 -0
  66. package/source/js/_app/player.ts +798 -0
  67. package/source/js/_app/components/sidebar.js +0 -209
  68. package/source/js/_app/fireworks.js +0 -10
  69. package/source/js/_app/globals/globalVars.js +0 -80
  70. package/source/js/_app/globals/handles.js +0 -98
  71. package/source/js/_app/globals/themeColor.js +0 -62
  72. package/source/js/_app/globals/thirdparty.js +0 -62
  73. package/source/js/_app/globals/tools.js +0 -66
  74. package/source/js/_app/library/anime.js +0 -106
  75. package/source/js/_app/library/dom.js +0 -34
  76. package/source/js/_app/library/loadFile.js +0 -36
  77. package/source/js/_app/library/proto.js +0 -163
  78. package/source/js/_app/library/scriptPjax.js +0 -70
  79. package/source/js/_app/library/storage.js +0 -12
  80. package/source/js/_app/library/vue.js +0 -53
  81. package/source/js/_app/page/comment.js +0 -23
  82. package/source/js/_app/page/common.js +0 -41
  83. package/source/js/_app/page/fancybox.js +0 -65
  84. package/source/js/_app/page/post.js +0 -244
  85. package/source/js/_app/page/search.js +0 -118
  86. package/source/js/_app/page/tab.js +0 -53
  87. package/source/js/_app/pjax/domInit.js +0 -76
  88. package/source/js/_app/pjax/refresh.js +0 -52
  89. package/source/js/_app/pjax/siteInit.js +0 -51
  90. package/source/js/_app/player.js +0 -771
@@ -1,209 +0,0 @@
1
- /* 边栏分区 */
2
- import { Container, diffY, menuToggle, showContents, sideBar } from '../globals/globalVars';
3
- import { clipBoard } from '../globals/tools';
4
- import { pageScroll, transition } from '../library/anime';
5
- import { $dom } from '../library/dom';
6
- export const sideBarToggleHandle = (event, force) => {
7
- if (sideBar.hasClass('on')) {
8
- sideBar.removeClass('on');
9
- menuToggle.removeClass('close');
10
- if (force) {
11
- // @ts-ignore
12
- // noinspection JSConstantReassignment
13
- sideBar.style = '';
14
- }
15
- else {
16
- transition(sideBar, 'slideRightOut');
17
- }
18
- }
19
- else {
20
- if (force) {
21
- // @ts-ignore
22
- // noinspection JSConstantReassignment
23
- sideBar.style = '';
24
- }
25
- else {
26
- transition(sideBar, 'slideRightIn', () => {
27
- sideBar.addClass('on');
28
- menuToggle.addClass('close');
29
- });
30
- }
31
- }
32
- };
33
- export const sideBarTab = () => {
34
- const sideBarInner = sideBar.child('.inner');
35
- if (sideBar.child('.tab')) {
36
- sideBarInner.removeChild(sideBar.child('.tab'));
37
- }
38
- const list = document.createElement('ul');
39
- let active = 'active';
40
- list.className = 'tab';
41
- ['contents', 'related', 'overview'].forEach((item) => {
42
- const element = sideBar.child('.panel.' + item);
43
- if (element.innerHTML.trim().length < 1) {
44
- if (item === 'contents') {
45
- showContents.display('none');
46
- }
47
- return;
48
- }
49
- if (item === 'contents') {
50
- showContents.display('');
51
- }
52
- const tab = document.createElement('li');
53
- const span = document.createElement('span');
54
- const text = document.createTextNode(element.attr('data-title'));
55
- span.appendChild(text);
56
- tab.appendChild(span);
57
- tab.addClass(item + ' item');
58
- if (active) {
59
- element.addClass(active);
60
- tab.addClass(active);
61
- }
62
- else {
63
- element.removeClass('active');
64
- }
65
- tab.addEventListener('click', (event) => {
66
- const target = event.currentTarget;
67
- if (target.hasClass('active'))
68
- return;
69
- sideBar.find('.tab .item').forEach((element) => {
70
- element.removeClass('active');
71
- });
72
- sideBar.find('.panel').forEach((element) => {
73
- element.removeClass('active');
74
- });
75
- sideBar.child('.panel.' + target.className.replace(' item', '')).addClass('active');
76
- target.addClass('active');
77
- });
78
- list.appendChild(tab);
79
- active = '';
80
- });
81
- if (list.childNodes.length > 1) {
82
- sideBarInner.insertBefore(list, sideBarInner.childNodes[0]);
83
- sideBar.child('.panels').style.paddingTop = '';
84
- }
85
- else {
86
- sideBar.child('.panels').style.paddingTop = '.625rem';
87
- }
88
- };
89
- export const sidebarTOC = () => {
90
- const activateNavByIndex = (index) => {
91
- const target = navItems[index];
92
- if (!target)
93
- return;
94
- if (target.hasClass('current')) {
95
- return;
96
- }
97
- $dom.each('.toc .active', (element) => {
98
- element && element.removeClass('active current');
99
- });
100
- sections.forEach((element) => {
101
- element && element.removeClass('active');
102
- });
103
- target.addClass('active current');
104
- sections[index] && sections[index].addClass('active');
105
- let parent = target.parentNode;
106
- while (!parent.matches('.contents')) {
107
- if (parent.matches('li')) {
108
- parent.addClass('active');
109
- const t = $dom(parent.child('a.toc-link').attr('href'));
110
- if (t) {
111
- t.addClass('active');
112
- }
113
- }
114
- parent = parent.parentNode;
115
- }
116
- // Scrolling to center active TOC element if TOC content is taller than viewport.
117
- if (getComputedStyle(sideBar).display !== 'none' && tocElement.hasClass('active')) {
118
- pageScroll(tocElement, target.offsetTop - (tocElement.offsetHeight / 4));
119
- }
120
- };
121
- const navItems = $dom.all('.contents li');
122
- if (navItems.length < 1) {
123
- return;
124
- }
125
- let sections = [...navItems];
126
- let activeLock = null;
127
- sections = sections.map((element, index) => {
128
- const link = element.child('a.toc-link');
129
- const anchor = $dom(decodeURI(link.attr('href')));
130
- if (!anchor)
131
- return null;
132
- const alink = anchor.child('a.anchor');
133
- const anchorScroll = (event) => {
134
- event.preventDefault();
135
- const target = $dom(decodeURI(event.currentTarget.attr('href')));
136
- activeLock = index;
137
- pageScroll(target, null, () => {
138
- activateNavByIndex(index);
139
- activeLock = null;
140
- });
141
- };
142
- // TOC item animation navigate.
143
- link.addEventListener('click', anchorScroll);
144
- alink && alink.addEventListener('click', (event) => {
145
- anchorScroll(event);
146
- clipBoard(CONFIG.hostname + '/' + LOCAL.path + event.currentTarget.attr('href'));
147
- });
148
- return anchor;
149
- });
150
- const tocElement = sideBar.child('.contents.panel');
151
- const findIndex = (entries) => {
152
- let index = 0;
153
- let entry = entries[index];
154
- if (entry.boundingClientRect.top > 0) {
155
- index = sections.indexOf(entry.target);
156
- return index === 0 ? 0 : index - 1;
157
- }
158
- for (; index < entries.length; index++) {
159
- if (entries[index].boundingClientRect.top <= 0) {
160
- entry = entries[index];
161
- }
162
- else {
163
- return sections.indexOf(entry.target);
164
- }
165
- }
166
- return sections.indexOf(entry.target);
167
- };
168
- const createIntersectionObserver = () => {
169
- const observer = new IntersectionObserver((entries) => {
170
- const index = findIndex(entries) + (diffY < 0 ? 1 : 0);
171
- if (activeLock === null) {
172
- activateNavByIndex(index);
173
- }
174
- }, {
175
- rootMargin: '0px 0px -100% 0px', threshold: 0
176
- });
177
- sections.forEach((element) => {
178
- element && observer.observe(element);
179
- });
180
- };
181
- createIntersectionObserver();
182
- };
183
- export const backToTopHandle = () => {
184
- pageScroll(0);
185
- };
186
- export const goToBottomHandle = () => {
187
- pageScroll(parseInt(String(Container.changeOrGetHeight())));
188
- };
189
- export const goToCommentHandle = () => {
190
- pageScroll($dom('#comments'));
191
- };
192
- export const menuActive = () => {
193
- $dom.each('.menu .item:not(.title)', (element) => {
194
- const target = element.child('a[href]');
195
- const parentItem = element.parentNode.parentNode;
196
- if (!target)
197
- return;
198
- const isSamePath = target.pathname === location.pathname || target.pathname === location.pathname.replace('index.html', '');
199
- const isSubPath = !CONFIG.root.startsWith(target.pathname) && location.pathname.startsWith(target.pathname);
200
- const active = target.hostname === location.hostname && (isSamePath || isSubPath);
201
- element.toggleClass('active', active);
202
- if (element.parentNode.child('.active') && parentItem.hasClass('dropdown')) {
203
- parentItem.removeClass('active').addClass('expand');
204
- }
205
- else {
206
- parentItem.removeClass('expand');
207
- }
208
- });
209
- };
@@ -1,10 +0,0 @@
1
- import firework from 'mouse-firework';
2
- /*
3
- * 烟花分区
4
- */
5
- export function initFireworks() {
6
- if (typeof CONFIG.fireworks === 'undefined') {
7
- return;
8
- }
9
- firework(CONFIG.fireworks);
10
- }
@@ -1,80 +0,0 @@
1
- import { $dom } from '../library/dom';
2
- import initProto from '../library/proto';
3
- initProto();
4
- export const statics = CONFIG.statics.indexOf('//') > 0 ? CONFIG.statics : CONFIG.root;
5
- export const scrollAction = { x: 0, y: 0 };
6
- export let diffY = 0;
7
- export let originTitle, titleTime;
8
- export const BODY = document.getElementsByTagName('body')[0];
9
- export const HTML = document.documentElement;
10
- export const Container = $dom('#container');
11
- export const loadCat = $dom('#loading');
12
- export const siteNav = $dom('#nav');
13
- export const siteHeader = $dom('#header');
14
- export const menuToggle = siteNav.child('.toggle');
15
- export const quickBtn = $dom('#quick');
16
- export const sideBar = $dom('#sidebar');
17
- export const siteBrand = $dom('#brand');
18
- export let toolBtn = $dom('#tool');
19
- export let toolPlayer;
20
- export let backToTop;
21
- export let goToComment;
22
- export let showContents;
23
- export let siteSearch = $dom('#search');
24
- export let siteNavHeight, headerHightInner, headerHight;
25
- export let oWinHeight = window.innerHeight;
26
- export let oWinWidth = window.innerWidth;
27
- export let LOCAL_HASH = 0;
28
- export let LOCAL_URL = window.location.href;
29
- export let pjax;
30
- export function setSiteNavHeight(value) {
31
- siteNavHeight = value;
32
- }
33
- export function setHeaderHightInner(value) {
34
- headerHightInner = value;
35
- }
36
- export function setHeaderHight(value) {
37
- headerHight = value;
38
- }
39
- export function setOWinHeight(value) {
40
- oWinHeight = value;
41
- }
42
- export function setOWinWidth(value) {
43
- oWinWidth = value;
44
- }
45
- export function setDiffY(value) {
46
- diffY = value;
47
- }
48
- export function setTitleTime(value) {
49
- titleTime = value;
50
- }
51
- export function setLocalHash(value) {
52
- LOCAL_HASH = value;
53
- }
54
- export function setLocalUrl(value) {
55
- LOCAL_URL = value;
56
- }
57
- export function setPjax(value) {
58
- pjax = value;
59
- }
60
- export function setOriginTitle(value) {
61
- originTitle = value;
62
- }
63
- export function setToolPlayer(value) {
64
- toolPlayer = value;
65
- }
66
- export function setBackToTop(value) {
67
- backToTop = value;
68
- }
69
- export function setGoToComment(value) {
70
- goToComment = value;
71
- }
72
- export function setShowContents(value) {
73
- showContents = value;
74
- }
75
- export function setToolBtn(value) {
76
- toolBtn = value;
77
- }
78
- export function setSiteSearch(value) {
79
- siteSearch = value;
80
- }
@@ -1,98 +0,0 @@
1
- import { sideBarToggleHandle } from '../components/sidebar';
2
- import { $dom, getDocHeight } from '../library/dom';
3
- import { backToTop, diffY, headerHight, headerHightInner, oWinWidth, originTitle, scrollAction, sideBar, siteBrand, siteHeader, siteNav, statics, titleTime, toolBtn, setSiteNavHeight, setHeaderHightInner, setHeaderHight, setOWinHeight, setOWinWidth, setDiffY, setTitleTime } from './globalVars';
4
- import { changeMetaTheme } from './themeColor';
5
- import { Loader } from './thirdparty';
6
- export const resizeHandle = () => {
7
- // 获取 siteNav 的高度
8
- setSiteNavHeight(siteNav.changeOrGetHeight());
9
- // 获取 siteHeader 的高度
10
- setHeaderHightInner(siteHeader.changeOrGetHeight());
11
- // 获取 #waves 的高度
12
- setHeaderHight(headerHightInner + $dom('#waves').changeOrGetHeight());
13
- // 判断窗口宽度是否改变
14
- if (oWinWidth !== window.innerWidth) {
15
- sideBarToggleHandle(null, 1);
16
- }
17
- // 记录窗口高度和宽度
18
- setOWinHeight(window.innerHeight);
19
- setOWinWidth(window.innerWidth);
20
- };
21
- export const scrollHandle = () => {
22
- // 获取窗口高度
23
- const winHeight = window.innerHeight;
24
- // 获取文档高度
25
- const docHeight = getDocHeight();
26
- // 计算可见内容高度
27
- const contentVisibilityHeight = docHeight > winHeight ? docHeight - winHeight : document.body.scrollHeight - winHeight;
28
- // 判断页面是否滚动超过 headerHightInner
29
- const SHOW = window.scrollY > headerHightInner;
30
- // 判断页面是否开始滚动
31
- const startScroll = window.scrollY > 0;
32
- // 根据条件修改 meta theme
33
- if (SHOW) {
34
- changeMetaTheme('#FFF');
35
- }
36
- else {
37
- changeMetaTheme('#222');
38
- }
39
- // 控制导航栏的显示隐藏
40
- siteNav.toggleClass('show', SHOW);
41
- // 控制网站 logo 的显示隐藏
42
- toolBtn.toggleClass('affix', startScroll);
43
- // 控制侧边栏的显示隐藏,当滚动高度大于 headerHight 且窗口宽度大于 991px 时显示
44
- siteBrand.toggleClass('affix', startScroll);
45
- sideBar.toggleClass('affix', window.scrollY > headerHight && document.body.offsetWidth > 991);
46
- // 初始化滚动时导航栏的显示方向
47
- if (typeof scrollAction.y === 'undefined') {
48
- scrollAction.y = window.scrollY;
49
- }
50
- setDiffY(scrollAction.y - window.scrollY);
51
- // 控制滑动时导航栏显示
52
- if (diffY < 0) {
53
- siteNav.removeClass('up');
54
- siteNav.toggleClass('down', SHOW);
55
- }
56
- else if (diffY > 0) {
57
- siteNav.removeClass('down');
58
- siteNav.toggleClass('up', SHOW);
59
- }
60
- else { /* empty */ }
61
- scrollAction.y = window.scrollY;
62
- // 计算滚动百分比
63
- const scrollPercent = Math.round(Math.min(100 * window.scrollY / contentVisibilityHeight, 100)) + '%';
64
- // 更新回到顶部按钮的文字
65
- if (backToTop.child('span').innerText !== scrollPercent) {
66
- backToTop.child('span').innerText = scrollPercent;
67
- }
68
- // 更新百分比进度条的宽度
69
- if ($dom('#sidebar').hasClass('affix') || $dom('#sidebar').hasClass('on')) {
70
- $dom('.percent').changeOrGetWidth(scrollPercent);
71
- }
72
- };
73
- // 可见度监听(离开页面和返回时更改document的title)
74
- export const visibilityListener = () => {
75
- const iconNode = $dom('[rel="icon"]');
76
- document.addEventListener('visibilitychange', () => {
77
- switch (document.visibilityState) {
78
- case 'hidden':
79
- iconNode.attr('href', statics + CONFIG.favicon.hidden);
80
- document.title = LOCAL.favicon.hide;
81
- if (CONFIG.loader.switch) {
82
- Loader.show();
83
- }
84
- clearTimeout(titleTime);
85
- break;
86
- case 'visible':
87
- iconNode.attr('href', statics + CONFIG.favicon.normal);
88
- document.title = LOCAL.favicon.show;
89
- if (CONFIG.loader.switch) {
90
- Loader.hide(1000);
91
- }
92
- setTitleTime(setTimeout(() => {
93
- document.title = originTitle;
94
- }, 2000));
95
- break;
96
- }
97
- });
98
- };
@@ -1,62 +0,0 @@
1
- import { $storage } from '../library/storage';
2
- import { $dom } from '../library/dom';
3
- import { HTML } from './globalVars';
4
- /**
5
- * 更改日夜模式
6
- */
7
- export const changeTheme = (type) => {
8
- const btn = $dom('.theme .ic');
9
- if (type === 'dark') {
10
- HTML.attr('data-theme', type);
11
- btn.removeClass('i-sun');
12
- btn.addClass('i-moon');
13
- }
14
- else {
15
- HTML.attr('data-theme', null);
16
- btn.removeClass('i-moon');
17
- btn.addClass('i-sun');
18
- }
19
- };
20
- /**
21
- * 自动调整黑夜白天
22
- * 优先级: 手动选择>时间>跟随系统
23
- */
24
- export const autoDarkmode = () => {
25
- if (CONFIG.auto_dark.enable) {
26
- if (new Date().getHours() >= CONFIG.auto_dark.start || new Date().getHours() <= CONFIG.auto_dark.end) {
27
- changeTheme('dark');
28
- }
29
- else {
30
- changeTheme();
31
- }
32
- }
33
- };
34
- /**
35
- * 更改主题的meta
36
- */
37
- export const changeMetaTheme = (color) => {
38
- if (HTML.attr('data-theme') === 'dark') {
39
- color = '#222';
40
- }
41
- $dom('meta[name="theme-color"]').attr('content', color);
42
- };
43
- // 记忆日夜模式切换和系统亮暗模式监听
44
- export const themeColorListener = () => {
45
- window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (mediaQueryList) => {
46
- if (mediaQueryList.matches) {
47
- changeTheme('dark');
48
- }
49
- else {
50
- changeTheme();
51
- }
52
- });
53
- const t = $storage.get('theme');
54
- if (t) {
55
- changeTheme(t);
56
- }
57
- else {
58
- if (CONFIG.darkmode) {
59
- changeTheme('dark');
60
- }
61
- }
62
- };
@@ -1,62 +0,0 @@
1
- // 与第三方js的交互或第三方嵌入js
2
- import { loadCat } from './globalVars';
3
- import { transition } from '../library/anime';
4
- // 加载动画
5
- export const Loader = {
6
- timer: undefined,
7
- lock: false,
8
- show() {
9
- clearTimeout(this.timer);
10
- document.body.removeClass('loaded');
11
- loadCat.attr('style', 'display:block');
12
- Loader.lock = false;
13
- },
14
- hide(sec) {
15
- if (!CONFIG.loader.start) {
16
- sec = -1;
17
- }
18
- this.timer = setTimeout(this.vanish, sec || 3000);
19
- },
20
- vanish() {
21
- if (Loader.lock) {
22
- return;
23
- }
24
- if (CONFIG.loader.start) {
25
- transition(loadCat, 0);
26
- }
27
- document.body.addClass('loaded');
28
- Loader.lock = true;
29
- }
30
- };
31
- export const isOutime = () => {
32
- let updateTime;
33
- if (CONFIG.outime.enable && LOCAL.outime) {
34
- const times = document.getElementsByTagName('time');
35
- if (times.length === 0) {
36
- return;
37
- }
38
- const posts = document.getElementsByClassName('body md');
39
- if (posts.length === 0) {
40
- return;
41
- }
42
- const now = Date.now(); // 当前时间戳
43
- const pubTime = new Date(times[0].dateTime); // 文章发布时间戳
44
- if (times.length === 1) {
45
- updateTime = pubTime; // 文章发布时间亦是最后更新时间
46
- }
47
- else {
48
- updateTime = new Date(times[1].dateTime); // 文章最后更新时间戳
49
- }
50
- // @ts-ignore
51
- const interval = parseInt(String(now - updateTime)); // 时间差
52
- const days = parseInt(String(CONFIG.outime.days)) || 30; // 设置时效,默认硬编码 30 天
53
- // 最后一次更新时间超过 days 天(毫秒)
54
- if (interval > (days * 86400000)) {
55
- // @ts-ignore
56
- const publish = parseInt(String((now - pubTime) / 86400000));
57
- const updated = parseInt(String(interval / 86400000));
58
- const template = LOCAL.template.replace('{{publish}}', String(publish)).replace('{{updated}}', String(updated));
59
- posts[0].insertAdjacentHTML('afterbegin', template);
60
- }
61
- }
62
- };
@@ -1,66 +0,0 @@
1
- import { pageScroll } from '../library/anime';
2
- import { $dom } from '../library/dom';
3
- import { $storage } from '../library/storage';
4
- import { BODY, LOCAL_HASH, LOCAL_URL, scrollAction, setLocalHash } from './globalVars';
5
- // 显示提示(现阶段用于版权及复制结果提示)
6
- export const showtip = (msg) => {
7
- if (!msg) {
8
- return;
9
- }
10
- const tipbox = BODY.createChild('div', {
11
- innerHTML: msg,
12
- className: 'tip'
13
- });
14
- setTimeout(() => {
15
- tipbox.addClass('hide');
16
- setTimeout(() => {
17
- BODY.removeChild(tipbox);
18
- }, 300);
19
- }, 3000);
20
- };
21
- export const pagePosition = () => {
22
- // 判断配置项是否开启了自动记录滚动位置
23
- if (CONFIG.auto_scroll) {
24
- // 将当前页面的滚动位置存入本地缓存
25
- $storage.set(LOCAL_URL, String(scrollAction.y));
26
- }
27
- };
28
- export const positionInit = (comment) => {
29
- // 获取页面锚点
30
- const anchor = window.location.hash;
31
- let target = null;
32
- if (LOCAL_HASH) {
33
- $storage.del(LOCAL_URL);
34
- return;
35
- }
36
- if (anchor) {
37
- target = $dom(decodeURI(anchor));
38
- }
39
- else {
40
- target = CONFIG.auto_scroll ? parseInt($storage.get(LOCAL_URL)) : 0;
41
- }
42
- if (target) {
43
- pageScroll(target);
44
- setLocalHash(1);
45
- }
46
- if (comment && anchor && !LOCAL_HASH) {
47
- pageScroll(target);
48
- setLocalHash(1);
49
- }
50
- };
51
- /*
52
- 基于clipboard API的复制功能,仅在https环境下有效
53
- */
54
- export const clipBoard = (str, callback) => {
55
- if (navigator.clipboard && window.isSecureContext) {
56
- navigator.clipboard.writeText(str).then(() => {
57
- callback && callback(true);
58
- }, () => {
59
- callback && callback(false);
60
- });
61
- }
62
- else {
63
- console.error('Too old browser, clipborad API not supported.');
64
- callback && callback(false);
65
- }
66
- };
@@ -1,106 +0,0 @@
1
- import anime from 'theme-shokax-anime';
2
- import { siteNavHeight } from '../globals/globalVars';
3
- /**
4
- * 参数 动画效果
5
- * 0 元素逐渐消失
6
- * 1 元素逐渐出现
7
- * bounceUpIn 元素从下方弹跳出现
8
- * shrinkIn 元素从放大到正常大小出现
9
- * slideRightIn 元素从右侧滑入
10
- * slideRightOut 元素向右侧滑出
11
- * TODO 函数功能过于复杂,需要拆分
12
- */
13
- export const transition = (target, type, complete, begin) => {
14
- let animation;
15
- let display = 'none';
16
- switch (type) {
17
- case 0:
18
- animation = { opacity: [1, 0] };
19
- break;
20
- case 1:
21
- animation = { opacity: [0, 1] };
22
- display = 'block';
23
- break;
24
- case 'bounceUpIn':
25
- animation = {
26
- begin(anim) {
27
- target.display('block');
28
- },
29
- translateY: [
30
- { value: -60, duration: 200 },
31
- { value: 10, duration: 200 },
32
- { value: -5, duration: 200 },
33
- { value: 0, duration: 200 }
34
- ],
35
- opacity: [0, 1]
36
- };
37
- display = 'block';
38
- break;
39
- case 'shrinkIn':
40
- animation = {
41
- begin(anim) {
42
- target.display('block');
43
- },
44
- scale: [
45
- { value: 1.1, duration: 300 },
46
- { value: 1, duration: 200 }
47
- ],
48
- opacity: 1
49
- };
50
- display = 'block';
51
- break;
52
- case 'slideRightIn':
53
- animation = {
54
- begin(anim) {
55
- target.display('block');
56
- },
57
- translateX: ['100%', '0%'],
58
- opacity: [0, 1]
59
- };
60
- display = 'block';
61
- break;
62
- case 'slideRightOut':
63
- animation = {
64
- translateX: ['0%', '100%'],
65
- opacity: [1, 0]
66
- };
67
- break;
68
- default:
69
- // @ts-ignore
70
- animation = type;
71
- // @ts-ignore
72
- display = type.display;
73
- break;
74
- }
75
- anime(Object.assign({
76
- targets: target,
77
- duration: 200,
78
- easing: 'linear',
79
- begin() {
80
- begin && begin();
81
- },
82
- complete() {
83
- target.display(display);
84
- complete && complete();
85
- }
86
- }, animation)).play();
87
- };
88
- export const pageScroll = (target, offset, complete) => {
89
- // target: 滚动到的目标元素或坐标(number)
90
- // offset: 可选的偏移量
91
- // complete: 可选的回调函数,在动画完成时调用
92
- anime({
93
- // 动画目标
94
- targets: typeof offset === 'number' && typeof target !== 'number' ? target.parentNode : document.scrollingElement,
95
- // 动画持续时间
96
- duration: 500,
97
- // 动画缓动函数
98
- easing: 'easeInOutQuad',
99
- // 如果 offset 存在,则滚动到 offset,如果 target 是数字,则滚动到 target,如果 target 是 DOM 元素,则滚动到下述表达式
100
- scrollTop: offset || (typeof target === 'number' ? target : (target ? target.getTop() + document.documentElement.scrollTop - siteNavHeight : 0)),
101
- // 完成回调函数
102
- complete() {
103
- complete && complete();
104
- }
105
- }).play();
106
- };