hexo-theme-shokax 0.2.10 → 0.3.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 (40) hide show
  1. package/LICENSE +68 -81
  2. package/README.md +17 -6
  3. package/UsageRestrictions.md +21 -0
  4. package/_config.yml +5 -12
  5. package/layout/_mixin/comment.pug +1 -2
  6. package/layout/_mixin/widgets.pug +2 -1
  7. package/layout/_partials/layout.pug +23 -23
  8. package/package.json +16 -12
  9. package/scripts/generaters/script.js +29 -8
  10. package/scripts/helpers/summary_ai.js +0 -1
  11. package/scripts/plugin/check.js +30 -0
  12. package/scripts/plugin/index.js +5 -0
  13. package/source/css/_common/components/tags/tabs.styl +0 -2
  14. package/source/css/_common/scaffolding/normalize.styl +165 -180
  15. package/source/js/_app/globals/globalVars.js +26 -0
  16. package/source/js/_app/globals/handles.js +105 -0
  17. package/source/js/_app/globals/themeColor.js +48 -0
  18. package/source/js/_app/globals/thirdparty.js +60 -0
  19. package/source/js/_app/globals/tools.js +75 -0
  20. package/source/js/_app/library/anime.js +85 -0
  21. package/source/js/_app/library/dom.js +22 -0
  22. package/source/js/_app/library/loadFile.js +32 -0
  23. package/source/js/_app/library/proto.js +105 -0
  24. package/source/js/_app/library/scriptPjax.js +57 -0
  25. package/source/js/_app/library/storage.js +11 -0
  26. package/source/js/_app/page/comment.js +19 -0
  27. package/source/js/_app/page/common.js +57 -0
  28. package/source/js/_app/page/fancybox.js +59 -0
  29. package/source/js/_app/page/post.js +232 -0
  30. package/source/js/_app/page/search.js +111 -0
  31. package/source/js/_app/page/tab.js +50 -0
  32. package/source/js/_app/pjax/domInit.js +68 -0
  33. package/source/js/_app/pjax/refresh.js +42 -0
  34. package/source/js/_app/pjax/siteInit.js +34 -0
  35. package/source/js/_app/player.js +1 -1
  36. package/source/js/_app/global.js +0 -314
  37. package/source/js/_app/library.js +0 -312
  38. package/source/js/_app/page.js +0 -673
  39. /package/source/js/_app/{components.js → components/sidebar.js} +0 -0
  40. /package/source/js/_app/{vue.js → library/vue.js} +0 -0
@@ -1,314 +0,0 @@
1
- const statics = CONFIG.statics.indexOf('//') > 0 ? CONFIG.statics : CONFIG.root;
2
- const scrollAction = { x: 0, y: 0 };
3
- let diffY = 0;
4
- let originTitle, titleTime;
5
- const BODY = document.getElementsByTagName('body')[0];
6
- const HTML = document.documentElement;
7
- const Container = $dom('#container');
8
- const loadCat = $dom('#loading');
9
- const siteNav = $dom('#nav');
10
- const siteHeader = $dom('#header');
11
- const menuToggle = siteNav.child('.toggle');
12
- const quickBtn = $dom('#quick');
13
- const sideBar = $dom('#sidebar');
14
- const siteBrand = $dom('#brand');
15
- let toolBtn = $dom('#tool');
16
- let toolPlayer;
17
- let backToTop;
18
- let goToComment;
19
- let showContents;
20
- let siteSearch = $dom('#search');
21
- let siteNavHeight, headerHightInner, headerHight;
22
- let oWinHeight = window.innerHeight;
23
- let oWinWidth = window.innerWidth;
24
- let LOCAL_HASH = 0;
25
- let LOCAL_URL = window.location.href;
26
- let pjax;
27
- const changeTheme = (type) => {
28
- const btn = $dom('.theme .ic');
29
- if (type === 'dark') {
30
- HTML.attr('data-theme', type);
31
- btn.removeClass('i-sun');
32
- btn.addClass('i-moon');
33
- }
34
- else {
35
- HTML.attr('data-theme', null);
36
- btn.removeClass('i-moon');
37
- btn.addClass('i-sun');
38
- }
39
- };
40
- const autoDarkmode = () => {
41
- if (CONFIG.auto_dark.enable) {
42
- if (new Date().getHours() >= CONFIG.auto_dark.start || new Date().getHours() <= CONFIG.auto_dark.end) {
43
- changeTheme('dark');
44
- }
45
- else {
46
- changeTheme();
47
- }
48
- }
49
- };
50
- const lazyload = lozad('img, [data-background-image]', {
51
- loaded(el) {
52
- el.addClass('lozaded');
53
- }
54
- });
55
- const Loader = {
56
- timer: undefined,
57
- lock: false,
58
- show() {
59
- clearTimeout(this.timer);
60
- document.body.removeClass('loaded');
61
- loadCat.attr('style', 'display:block');
62
- Loader.lock = false;
63
- },
64
- hide(sec) {
65
- if (!CONFIG.loader.start) {
66
- sec = -1;
67
- }
68
- this.timer = setTimeout(this.vanish, sec || 3000);
69
- },
70
- vanish() {
71
- if (Loader.lock) {
72
- return;
73
- }
74
- if (CONFIG.loader.start) {
75
- transition(loadCat, 0);
76
- }
77
- document.body.addClass('loaded');
78
- Loader.lock = true;
79
- }
80
- };
81
- const changeMetaTheme = (color) => {
82
- if (HTML.attr('data-theme') === 'dark') {
83
- color = '#222';
84
- }
85
- $dom('meta[name="theme-color"]').attr('content', color);
86
- };
87
- const themeColorListener = () => {
88
- window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (mediaQueryList) => {
89
- if (mediaQueryList.matches) {
90
- changeTheme('dark');
91
- }
92
- else {
93
- changeTheme();
94
- }
95
- });
96
- const t = $storage.get('theme');
97
- if (t) {
98
- changeTheme(t);
99
- }
100
- else {
101
- if (CONFIG.darkmode) {
102
- changeTheme('dark');
103
- }
104
- }
105
- };
106
- const visibilityListener = () => {
107
- const iconNode = $dom('[rel="icon"]');
108
- document.addEventListener('visibilitychange', () => {
109
- switch (document.visibilityState) {
110
- case 'hidden':
111
- iconNode.attr('href', statics + CONFIG.favicon.hidden);
112
- document.title = LOCAL.favicon.hide;
113
- if (CONFIG.loader.switch) {
114
- Loader.show();
115
- }
116
- clearTimeout(titleTime);
117
- break;
118
- case 'visible':
119
- iconNode.attr('href', statics + CONFIG.favicon.normal);
120
- document.title = LOCAL.favicon.show;
121
- if (CONFIG.loader.switch) {
122
- Loader.hide(1000);
123
- }
124
- titleTime = setTimeout(() => {
125
- document.title = originTitle;
126
- }, 2000);
127
- break;
128
- }
129
- });
130
- };
131
- const showtip = (msg) => {
132
- if (!msg) {
133
- return;
134
- }
135
- const tipbox = BODY.createChild('div', {
136
- innerHTML: msg,
137
- className: 'tip'
138
- });
139
- setTimeout(() => {
140
- tipbox.addClass('hide');
141
- setTimeout(() => {
142
- BODY.removeChild(tipbox);
143
- }, 300);
144
- }, 3000);
145
- };
146
- const resizeHandle = (event) => {
147
- siteNavHeight = siteNav.changeOrGetHeight();
148
- headerHightInner = siteHeader.changeOrGetHeight();
149
- headerHight = headerHightInner + $dom('#waves').changeOrGetHeight();
150
- if (oWinWidth !== window.innerWidth) {
151
- sideBarToggleHandle(null, 1);
152
- }
153
- oWinHeight = window.innerHeight;
154
- oWinWidth = window.innerWidth;
155
- };
156
- const scrollHandle = (event) => {
157
- const winHeight = window.innerHeight;
158
- const docHeight = getDocHeight();
159
- const contentVisibilityHeight = docHeight > winHeight ? docHeight - winHeight : document.body.scrollHeight - winHeight;
160
- const SHOW = window.scrollY > headerHightInner;
161
- const startScroll = window.scrollY > 0;
162
- if (SHOW) {
163
- changeMetaTheme('#FFF');
164
- }
165
- else {
166
- changeMetaTheme('#222');
167
- }
168
- siteNav.toggleClass('show', SHOW);
169
- toolBtn.toggleClass('affix', startScroll);
170
- siteBrand.toggleClass('affix', startScroll);
171
- sideBar.toggleClass('affix', window.scrollY > headerHight && document.body.offsetWidth > 991);
172
- if (typeof scrollAction.y === 'undefined') {
173
- scrollAction.y = window.scrollY;
174
- }
175
- diffY = scrollAction.y - window.scrollY;
176
- if (diffY < 0) {
177
- siteNav.removeClass('up');
178
- siteNav.toggleClass('down', SHOW);
179
- }
180
- else if (diffY > 0) {
181
- siteNav.removeClass('down');
182
- siteNav.toggleClass('up', SHOW);
183
- }
184
- else { }
185
- scrollAction.y = window.scrollY;
186
- const scrollPercent = Math.round(Math.min(100 * window.scrollY / contentVisibilityHeight, 100)) + '%';
187
- if (backToTop.child('span').innerText !== scrollPercent) {
188
- backToTop.child('span').innerText = scrollPercent;
189
- }
190
- if ($dom('#sidebar').hasClass('affix') || $dom('#sidebar').hasClass('on')) {
191
- $dom('.percent').changeOrGetWidth(scrollPercent);
192
- }
193
- };
194
- const pagePosition = () => {
195
- if (CONFIG.auto_scroll) {
196
- $storage.set(LOCAL_URL, String(scrollAction.y));
197
- }
198
- };
199
- const positionInit = (comment) => {
200
- const anchor = window.location.hash;
201
- let target = null;
202
- if (LOCAL_HASH) {
203
- $storage.del(LOCAL_URL);
204
- return;
205
- }
206
- if (anchor) {
207
- target = $dom(decodeURI(anchor));
208
- }
209
- else {
210
- target = CONFIG.auto_scroll ? parseInt($storage.get(LOCAL_URL)) : 0;
211
- }
212
- if (target) {
213
- pageScroll(target);
214
- LOCAL_HASH = 1;
215
- }
216
- if (comment && anchor && !LOCAL_HASH) {
217
- pageScroll(target);
218
- LOCAL_HASH = 1;
219
- }
220
- };
221
- const clipBoard = (str, callback) => {
222
- if (navigator.clipboard && window.isSecureContext) {
223
- navigator.clipboard.writeText(str).then(() => {
224
- callback && callback(true);
225
- }, () => {
226
- callback && callback(false);
227
- });
228
- }
229
- else {
230
- const ta = BODY.createChild('textarea', {
231
- style: {
232
- top: window.scrollY + 'px',
233
- position: 'absolute',
234
- opacity: '0'
235
- },
236
- readOnly: true,
237
- value: str
238
- });
239
- const selection = document.getSelection();
240
- const selected = selection.rangeCount > 0 ? selection.getRangeAt(0) : false;
241
- ta.select();
242
- ta.setSelectionRange(0, str.length);
243
- ta.readOnly = false;
244
- const result = document.execCommand('copy');
245
- callback && callback(result);
246
- ta.blur();
247
- if (selected) {
248
- selection.removeAllRanges();
249
- selection.addRange(selected);
250
- }
251
- BODY.removeChild(ta);
252
- }
253
- };
254
- const isOutime = () => {
255
- let updateTime;
256
- if (CONFIG.outime.enable && LOCAL.outime) {
257
- const times = document.getElementsByTagName('time');
258
- if (times.length === 0) {
259
- return;
260
- }
261
- const posts = document.getElementsByClassName('body md');
262
- if (posts.length === 0) {
263
- return;
264
- }
265
- const now = Date.now();
266
- const pubTime = new Date(times[0].dateTime);
267
- if (times.length === 1) {
268
- updateTime = pubTime;
269
- }
270
- else {
271
- updateTime = new Date(times[1].dateTime);
272
- }
273
- const interval = parseInt(String(now - updateTime));
274
- const days = parseInt(String(CONFIG.outime.days)) || 30;
275
- if (interval > (days * 86400000)) {
276
- const publish = parseInt(String((now - pubTime) / 86400000));
277
- const updated = parseInt(String(interval / 86400000));
278
- const template = LOCAL.template.replace('{{publish}}', String(publish)).replace('{{updated}}', String(updated));
279
- posts[0].insertAdjacentHTML('afterbegin', template);
280
- }
281
- }
282
- };
283
- const clickMenu = () => {
284
- const menuElement = $dom('#clickMenu');
285
- window.oncontextmenu = function (event) {
286
- if (event.ctrlKey) {
287
- return;
288
- }
289
- event.preventDefault();
290
- let x = event.offsetX;
291
- let y = event.offsetY;
292
- const winWidth = window.innerWidth;
293
- const winHeight = window.innerHeight;
294
- const menuWidth = menuElement.offsetWidth;
295
- const menuHeight = menuElement.offsetHeight;
296
- x = winWidth - menuWidth >= x ? x : winWidth - menuWidth;
297
- y = winHeight - menuHeight >= y ? y : winHeight - menuHeight;
298
- menuElement.style.top = y + 'px';
299
- menuElement.style.left = x + 'px';
300
- menuElement.classList.add('active');
301
- $dom.each('.clickSubmenu', (submenu) => {
302
- if (x > (winWidth - menuWidth - submenu.offsetWidth)) {
303
- submenu.style.left = '-200px';
304
- }
305
- else {
306
- submenu.style.left = '';
307
- submenu.style.right = '-200px';
308
- }
309
- });
310
- };
311
- window.addEventListener('click', () => {
312
- menuElement.classList.remove('active');
313
- });
314
- };
@@ -1,312 +0,0 @@
1
- const getDocHeight = () => $dom('main > .inner').offsetHeight;
2
- const $dom = (selector, element = document) => {
3
- if (selector[0] === '#') {
4
- return element.getElementById(selector.substring(1));
5
- }
6
- return element.querySelector(selector);
7
- };
8
- $dom.all = (selector, element = document) => {
9
- return element.querySelectorAll(selector);
10
- };
11
- $dom.each = (selector, callback, element) => {
12
- $dom.all(selector, element).forEach(callback);
13
- };
14
- $dom.asyncify = async (selector, element = document) => {
15
- if (selector[0] === '#') {
16
- return element.getElementById(selector.substring(1));
17
- }
18
- return element.querySelector(selector);
19
- };
20
- $dom.asyncifyEach = (selector, callback, element) => {
21
- $dom.all(selector, element).forEach(callback);
22
- };
23
- Object.assign(HTMLElement.prototype, {
24
- createChild(tag, obj, positon) {
25
- const child = document.createElement(tag);
26
- Object.assign(child, obj);
27
- switch (positon) {
28
- case 'after':
29
- this.insertAfter(child);
30
- break;
31
- case 'replace':
32
- this.innerHTML = '';
33
- this.appendChild(child);
34
- break;
35
- default:
36
- this.appendChild(child);
37
- }
38
- return child;
39
- },
40
- wrapObject(obj) {
41
- const box = document.createElement('div');
42
- Object.assign(box, obj);
43
- this.parentNode.insertBefore(box, this);
44
- this.parentNode.removeChild(this);
45
- box.appendChild(this);
46
- },
47
- changeOrGetHeight(h) {
48
- if (h) {
49
- this.style.height = typeof h === 'number' ? h + 'rem' : h;
50
- }
51
- return this.getBoundingClientRect().height;
52
- },
53
- changeOrGetWidth(w) {
54
- if (w) {
55
- this.style.width = typeof w === 'number' ? w + 'rem' : w;
56
- }
57
- return this.getBoundingClientRect().width;
58
- },
59
- getTop() {
60
- return this.getBoundingClientRect().top;
61
- },
62
- left() {
63
- return this.getBoundingClientRect().left;
64
- },
65
- attr(type, value) {
66
- if (value === null) {
67
- return this.removeAttribute(type);
68
- }
69
- if (value) {
70
- this.setAttribute(type, value);
71
- return this;
72
- }
73
- else {
74
- return this.getAttribute(type);
75
- }
76
- },
77
- insertAfter(element) {
78
- const parent = this.parentNode;
79
- if (parent.lastChild === this) {
80
- parent.appendChild(element);
81
- }
82
- else {
83
- parent.insertBefore(element, this.nextSibling);
84
- }
85
- },
86
- display(d) {
87
- if (d == null) {
88
- return this.style.display;
89
- }
90
- else {
91
- this.style.display = d;
92
- return this;
93
- }
94
- },
95
- child(selector) {
96
- return $dom(selector, this);
97
- },
98
- find(selector) {
99
- return $dom.all(selector, this);
100
- },
101
- _class(type, className, display) {
102
- const classNames = className.indexOf(' ') ? className.split(' ') : [className];
103
- classNames.forEach((name) => {
104
- if (type === 'toggle') {
105
- this.classList.toggle(name, display);
106
- }
107
- else {
108
- this.classList[type](name);
109
- }
110
- });
111
- },
112
- addClass(className) {
113
- this._class('add', className);
114
- return this;
115
- },
116
- removeClass(className) {
117
- this._class('remove', className);
118
- return this;
119
- },
120
- toggleClass(className, display) {
121
- this._class('toggle', className, display);
122
- return this;
123
- },
124
- hasClass(className) {
125
- return this.classList.contains(className);
126
- }
127
- });
128
- const $storage = {
129
- set(key, value) {
130
- localStorage.setItem(key, value);
131
- },
132
- get(key) {
133
- return localStorage.getItem(key);
134
- },
135
- del(key) {
136
- localStorage.removeItem(key);
137
- }
138
- };
139
- const getScript = (url, callback, condition) => {
140
- if (condition) {
141
- callback();
142
- }
143
- else {
144
- let script = document.createElement('script');
145
- script.onload = function (_, isAbort) {
146
- if (isAbort || !script.readyState) {
147
- console.log('abort!');
148
- script.onload = null;
149
- script = undefined;
150
- if (!isAbort && callback)
151
- setTimeout(callback, 0);
152
- }
153
- };
154
- script.src = url;
155
- document.head.appendChild(script);
156
- }
157
- };
158
- const assetUrl = (asset, type) => {
159
- const str = CONFIG[asset][type];
160
- if (str.includes('gh') || str.includes('combine')) {
161
- return `https://cdn.jsdelivr.net/${str}`;
162
- }
163
- if (str.includes('npm')) {
164
- return `https://cdn.jsdelivr.net/${str}`;
165
- }
166
- if (str.includes('http')) {
167
- return str;
168
- }
169
- return `/${str}`;
170
- };
171
- const vendorJs = (type, callback, condition) => {
172
- if (LOCAL[type]) {
173
- getScript(assetUrl('js', type), callback || function () {
174
- window[type] = true;
175
- }, condition || window[type]);
176
- }
177
- };
178
- const vendorCss = (type, condition) => {
179
- if (window['css' + type]) {
180
- return;
181
- }
182
- if (LOCAL[type]) {
183
- document.head.createChild('link', {
184
- rel: 'stylesheet',
185
- href: assetUrl('css', type)
186
- });
187
- window['css' + type] = true;
188
- }
189
- };
190
- const transition = (target, type, complete, begin) => {
191
- let animation;
192
- let display = 'none';
193
- switch (type) {
194
- case 0:
195
- animation = { opacity: [1, 0] };
196
- break;
197
- case 1:
198
- animation = { opacity: [0, 1] };
199
- display = 'block';
200
- break;
201
- case 'bounceUpIn':
202
- animation = {
203
- begin(anim) {
204
- target.display('block');
205
- },
206
- translateY: [
207
- { value: -60, duration: 200 },
208
- { value: 10, duration: 200 },
209
- { value: -5, duration: 200 },
210
- { value: 0, duration: 200 }
211
- ],
212
- opacity: [0, 1]
213
- };
214
- display = 'block';
215
- break;
216
- case 'shrinkIn':
217
- animation = {
218
- begin(anim) {
219
- target.display('block');
220
- },
221
- scale: [
222
- { value: 1.1, duration: 300 },
223
- { value: 1, duration: 200 }
224
- ],
225
- opacity: 1
226
- };
227
- display = 'block';
228
- break;
229
- case 'slideRightIn':
230
- animation = {
231
- begin(anim) {
232
- target.display('block');
233
- },
234
- translateX: ['100%', '0%'],
235
- opacity: [0, 1]
236
- };
237
- display = 'block';
238
- break;
239
- case 'slideRightOut':
240
- animation = {
241
- translateX: ['0%', '100%'],
242
- opacity: [1, 0]
243
- };
244
- break;
245
- default:
246
- animation = type;
247
- display = type.display;
248
- break;
249
- }
250
- anime(Object.assign({
251
- targets: target,
252
- duration: 200,
253
- easing: 'linear',
254
- begin() {
255
- begin && begin();
256
- },
257
- complete() {
258
- target.display(display);
259
- complete && complete();
260
- }
261
- }, animation)).play();
262
- };
263
- const pjaxScript = (element) => {
264
- const { text, parentNode, id, className, type, src, dataset } = element;
265
- const code = text || element.textContent || element.innerHTML || '';
266
- parentNode.removeChild(element);
267
- const script = document.createElement('script');
268
- if (id) {
269
- script.id = id;
270
- }
271
- if (className) {
272
- script.className = className;
273
- }
274
- if (type) {
275
- script.type = type;
276
- }
277
- if (src) {
278
- script.src = src;
279
- script.async = false;
280
- }
281
- if (dataset.pjax !== undefined) {
282
- script.dataset.pjax = '';
283
- }
284
- if (code !== '') {
285
- script.appendChild(document.createTextNode(code));
286
- }
287
- parentNode.appendChild(script);
288
- };
289
- const pageScroll = (target, offset, complete) => {
290
- const opt = {
291
- targets: typeof offset === 'number' ? target.parentNode : document.scrollingElement,
292
- duration: 500,
293
- easing: 'easeInOutQuad',
294
- scrollTop: offset || (typeof target === 'number' ? target : (target ? target.getTop() + document.documentElement.scrollTop - siteNavHeight : 0)),
295
- complete() {
296
- complete && complete();
297
- }
298
- };
299
- anime(opt).play();
300
- };
301
- let inCloudFlare = true;
302
- window.addEventListener('DOMContentLoaded', function () {
303
- inCloudFlare = false;
304
- });
305
- if (document.readyState === 'loading') {
306
- window.addEventListener('load', function () {
307
- if (inCloudFlare) {
308
- window.dispatchEvent(new Event('DOMContentLoaded'));
309
- console.log('%c ☁️cloudflare patch ' + '%c running(rocket & minify)', 'color: white; background: #ff8c00; padding: 5px 3px;', 'padding: 4px;border:1px solid #ff8c00');
310
- }
311
- });
312
- }