hexo-theme-shokax 0.3.10 → 0.3.12
Sign up to get free protection for your applications and to get access to all the features.
- package/_config.yml +47 -57
- package/layout/_mixin/comment.pug +1 -1
- package/layout/_partials/head/head.pug +2 -7
- package/layout/_partials/layout.pug +5 -5
- package/package.json +16 -21
- package/scripts/filters/locals.js +6 -0
- package/scripts/filters/post.js +2 -0
- package/scripts/generaters/archive.js +13 -1
- package/scripts/generaters/config.js +4 -1
- package/scripts/generaters/images.js +2 -0
- package/scripts/generaters/index.js +2 -0
- package/scripts/generaters/pages.js +0 -2
- package/scripts/generaters/script.js +37 -11
- package/scripts/helpers/asset.js +17 -71
- package/scripts/helpers/engine.js +24 -1
- package/scripts/helpers/list_categories.js +4 -0
- package/scripts/helpers/summary_ai.js +4 -0
- package/scripts/helpers/symbols_count_time.js +14 -8
- package/scripts/plugin/check.js +5 -3
- package/scripts/plugin/index.js +39 -23
- package/scripts/plugin/lib/injects.js +15 -0
- package/scripts/tags/media.js +1 -0
- package/scripts/utils.js +14 -0
- package/source/js/_app/components/sidebar.js +54 -56
- package/source/js/_app/fireworks.js +6 -137
- package/source/js/_app/globals/globalVars.js +80 -96
- package/source/js/_app/globals/handles.js +81 -60
- package/source/js/_app/globals/themeColor.js +30 -26
- package/source/js/_app/globals/thirdparty.js +25 -24
- package/source/js/_app/globals/tools.js +36 -30
- package/source/js/_app/library/anime.js +30 -15
- package/source/js/_app/library/dom.js +12 -5
- package/source/js/_app/library/loadFile.js +10 -12
- package/source/js/_app/library/proto.js +59 -7
- package/source/js/_app/library/scriptPjax.js +14 -9
- package/source/js/_app/library/storage.js +2 -4
- package/source/js/_app/library/vue.js +16 -19
- package/source/js/_app/page/comment.js +10 -11
- package/source/js/_app/page/common.js +8 -12
- package/source/js/_app/page/fancybox.js +14 -14
- package/source/js/_app/page/post.js +43 -45
- package/source/js/_app/page/search.js +20 -20
- package/source/js/_app/page/tab.js +7 -10
- package/source/js/_app/pjax/domInit.js +29 -29
- package/source/js/_app/pjax/refresh.js +44 -50
- package/source/js/_app/pjax/siteInit.js +27 -31
- package/source/js/_app/player.js +44 -27
- package/test/dom.test.js +0 -86
@@ -1,141 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
exports.initFireworks = void 0;
|
7
|
-
const theme_shokax_anime_1 = __importDefault(require("theme-shokax-anime"));
|
8
|
-
const canvasEl = document.createElement('canvas');
|
9
|
-
canvasEl.style.cssText = 'position:fixed;top:0;left:0;pointer-events:none;z-index:9999999';
|
10
|
-
document.body.appendChild(canvasEl);
|
11
|
-
const ctx = canvasEl.getContext('2d');
|
12
|
-
const numberOfParticles = 30;
|
13
|
-
let pointerX = 0;
|
14
|
-
let pointerY = 0;
|
15
|
-
const tap = 'click';
|
16
|
-
const colors = CONFIG.fireworks;
|
17
|
-
function setCanvasSize() {
|
18
|
-
canvasEl.width = window.innerWidth * 2;
|
19
|
-
canvasEl.height = window.innerHeight * 2;
|
20
|
-
canvasEl.style.width = window.innerWidth + 'px';
|
21
|
-
canvasEl.style.height = window.innerHeight + 'px';
|
22
|
-
canvasEl.getContext('2d').scale(2, 2);
|
23
|
-
}
|
24
|
-
function updateCoords(e) {
|
25
|
-
pointerX = e.clientX || (e.touches && e.touches[0].clientX);
|
26
|
-
pointerY = e.clientY || (e.touches && e.touches[0].clientY);
|
27
|
-
}
|
28
|
-
function setParticleDirection(p) {
|
29
|
-
const angle = theme_shokax_anime_1.default.random(0, 360) * Math.PI / 180;
|
30
|
-
const value = theme_shokax_anime_1.default.random(50, 180);
|
31
|
-
const radius = [-1, 1][theme_shokax_anime_1.default.random(0, 1)] * value;
|
32
|
-
return {
|
33
|
-
x: p.x + radius * Math.cos(angle),
|
34
|
-
y: p.y + radius * Math.sin(angle)
|
35
|
-
};
|
36
|
-
}
|
37
|
-
function createParticle(x, y) {
|
38
|
-
const p = {
|
39
|
-
x,
|
40
|
-
y,
|
41
|
-
color: undefined,
|
42
|
-
radius: undefined,
|
43
|
-
endPos: undefined,
|
44
|
-
draw() {
|
45
|
-
ctx.beginPath();
|
46
|
-
ctx.arc(p.x, p.y, p.radius, 0, 2 * Math.PI, true);
|
47
|
-
ctx.fillStyle = p.color;
|
48
|
-
ctx.fill();
|
49
|
-
}
|
50
|
-
};
|
51
|
-
p.color = colors[theme_shokax_anime_1.default.random(0, colors.length - 1)];
|
52
|
-
p.radius = theme_shokax_anime_1.default.random(16, 32);
|
53
|
-
p.endPos = setParticleDirection(p);
|
54
|
-
return p;
|
55
|
-
}
|
56
|
-
function createCircle(x, y) {
|
57
|
-
const p = {
|
58
|
-
x,
|
59
|
-
y,
|
60
|
-
color: '#FFF',
|
61
|
-
radius: 0.1,
|
62
|
-
endPos: undefined,
|
63
|
-
alpha: 0.5,
|
64
|
-
lineWidth: 6,
|
65
|
-
draw() {
|
66
|
-
ctx.globalAlpha = p.alpha;
|
67
|
-
ctx.beginPath();
|
68
|
-
ctx.arc(p.x, p.y, p.radius, 0, 2 * Math.PI, true);
|
69
|
-
ctx.lineWidth = p.lineWidth;
|
70
|
-
ctx.strokeStyle = p.color;
|
71
|
-
ctx.stroke();
|
72
|
-
ctx.globalAlpha = 1;
|
73
|
-
}
|
74
|
-
};
|
75
|
-
return p;
|
76
|
-
}
|
77
|
-
function renderParticle(targets) {
|
78
|
-
for (const target of targets) {
|
79
|
-
target.draw();
|
80
|
-
}
|
81
|
-
}
|
82
|
-
function animateParticles(x, y) {
|
83
|
-
const circle = createCircle(x, y);
|
84
|
-
const particles = [];
|
85
|
-
for (let i = 0; i < numberOfParticles; i++) {
|
86
|
-
particles.push(createParticle(x, y));
|
87
|
-
}
|
88
|
-
(0, theme_shokax_anime_1.default)().timeline().add({
|
89
|
-
targets: particles,
|
90
|
-
duration: theme_shokax_anime_1.default.random(1200, 1800),
|
91
|
-
easing: 'easeOutExpo',
|
92
|
-
update: renderParticle,
|
93
|
-
x: p => p.endPos.x,
|
94
|
-
y: p => p.endPos.y,
|
95
|
-
radius: 0.1
|
96
|
-
}).add({
|
97
|
-
targets: circle,
|
98
|
-
duration: theme_shokax_anime_1.default.random(1200, 1800),
|
99
|
-
easing: 'easeOutExpo',
|
100
|
-
update: renderParticle,
|
101
|
-
radius: theme_shokax_anime_1.default.random(80, 160),
|
102
|
-
lineWidth: 0,
|
103
|
-
alpha: {
|
104
|
-
value: 0,
|
105
|
-
easing: 'linear',
|
106
|
-
duration: theme_shokax_anime_1.default.random(600, 800)
|
107
|
-
}
|
108
|
-
}).play();
|
109
|
-
}
|
110
|
-
const render = (0, theme_shokax_anime_1.default)({
|
111
|
-
duration: Infinity,
|
112
|
-
update() {
|
113
|
-
ctx.clearRect(0, 0, canvasEl.width, canvasEl.height);
|
114
|
-
}
|
115
|
-
});
|
116
|
-
const hasAncestor = (node, name) => {
|
117
|
-
name = name.toUpperCase();
|
118
|
-
do {
|
119
|
-
if (node === null || node === undefined)
|
120
|
-
break;
|
121
|
-
if (node.nodeName === name)
|
122
|
-
return true;
|
123
|
-
} while ((node = node.parentNode) !== null);
|
124
|
-
return false;
|
125
|
-
};
|
126
|
-
function initFireworks() {
|
1
|
+
import firework from 'mouse-firework';
|
2
|
+
/*
|
3
|
+
* 烟花分区
|
4
|
+
*/
|
5
|
+
export function initFireworks() {
|
127
6
|
if (typeof CONFIG.fireworks === 'undefined') {
|
128
7
|
return;
|
129
8
|
}
|
130
|
-
|
131
|
-
if (hasAncestor(e.target, 'a')) {
|
132
|
-
return;
|
133
|
-
}
|
134
|
-
render.play();
|
135
|
-
updateCoords(e);
|
136
|
-
animateParticles(pointerX, pointerY);
|
137
|
-
}, false);
|
138
|
-
setCanvasSize();
|
139
|
-
window.addEventListener('resize', setCanvasSize, false);
|
9
|
+
firework(CONFIG.fireworks);
|
140
10
|
}
|
141
|
-
exports.initFireworks = initFireworks;
|
@@ -1,96 +1,80 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
const
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
function setHeaderHightInner(value) {
|
34
|
-
|
35
|
-
}
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
function
|
46
|
-
|
47
|
-
}
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
function
|
58
|
-
|
59
|
-
}
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
function
|
70
|
-
|
71
|
-
}
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
function setGoToComment(value) {
|
82
|
-
exports.goToComment = value;
|
83
|
-
}
|
84
|
-
exports.setGoToComment = setGoToComment;
|
85
|
-
function setShowContents(value) {
|
86
|
-
exports.showContents = value;
|
87
|
-
}
|
88
|
-
exports.setShowContents = setShowContents;
|
89
|
-
function setToolBtn(value) {
|
90
|
-
exports.toolBtn = value;
|
91
|
-
}
|
92
|
-
exports.setToolBtn = setToolBtn;
|
93
|
-
function setSiteSearch(value) {
|
94
|
-
exports.siteSearch = value;
|
95
|
-
}
|
96
|
-
exports.setSiteSearch = setSiteSearch;
|
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,80 +1,102 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
const
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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);
|
15
16
|
}
|
16
|
-
|
17
|
-
(
|
17
|
+
// 记录窗口高度和宽度
|
18
|
+
setOWinHeight(window.innerHeight);
|
19
|
+
setOWinWidth(window.innerWidth);
|
18
20
|
};
|
19
|
-
|
20
|
-
|
21
|
+
export const scrollHandle = () => {
|
22
|
+
// 获取窗口高度
|
21
23
|
const winHeight = window.innerHeight;
|
22
|
-
|
24
|
+
// 获取文档高度
|
25
|
+
const docHeight = getDocHeight();
|
26
|
+
// 计算可见内容高度
|
23
27
|
const contentVisibilityHeight = docHeight > winHeight ? docHeight - winHeight : document.body.scrollHeight - winHeight;
|
24
|
-
|
28
|
+
// 判断页面是否滚动超过 headerHightInner
|
29
|
+
const SHOW = window.scrollY > headerHightInner;
|
30
|
+
// 判断页面是否开始滚动
|
25
31
|
const startScroll = window.scrollY > 0;
|
32
|
+
// 根据条件修改 meta theme
|
26
33
|
if (SHOW) {
|
27
|
-
|
34
|
+
changeMetaTheme('#FFF');
|
28
35
|
}
|
29
36
|
else {
|
30
|
-
|
37
|
+
changeMetaTheme('#222');
|
31
38
|
}
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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;
|
38
49
|
}
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
50
|
+
setDiffY(scrollAction.y - window.scrollY);
|
51
|
+
// 控制滑动时导航栏显示
|
52
|
+
if (diffY < 0) {
|
53
|
+
siteNav.removeClass('up');
|
54
|
+
siteNav.toggleClass('down', SHOW);
|
43
55
|
}
|
44
|
-
else if (
|
45
|
-
|
46
|
-
|
56
|
+
else if (diffY > 0) {
|
57
|
+
siteNav.removeClass('down');
|
58
|
+
siteNav.toggleClass('up', SHOW);
|
47
59
|
}
|
48
|
-
else { }
|
49
|
-
|
60
|
+
else { /* empty */ }
|
61
|
+
scrollAction.y = window.scrollY;
|
62
|
+
// 计算滚动百分比
|
50
63
|
const scrollPercent = Math.round(Math.min(100 * window.scrollY / contentVisibilityHeight, 100)) + '%';
|
51
|
-
|
52
|
-
|
64
|
+
// 更新回到顶部按钮的文字
|
65
|
+
if (backToTop.child('span').innerText !== scrollPercent) {
|
66
|
+
backToTop.child('span').innerText = scrollPercent;
|
53
67
|
}
|
54
|
-
|
55
|
-
|
68
|
+
// 更新百分比进度条的宽度
|
69
|
+
if ($dom('#sidebar').hasClass('affix') || $dom('#sidebar').hasClass('on')) {
|
70
|
+
$dom('.percent').changeOrGetWidth(scrollPercent);
|
56
71
|
}
|
57
72
|
};
|
58
|
-
|
59
|
-
|
60
|
-
|
73
|
+
/**
|
74
|
+
* 此函数用于修改右键点击显示菜单 <br/>
|
75
|
+
* 需要在document下存在如下元素:
|
76
|
+
* - id为clickMenu的容器(右键菜单容器)
|
77
|
+
* - class为clickSubmenu的容器(可以有0到无限个)(子菜单容器)
|
78
|
+
* CSS应有如下class:
|
79
|
+
* - clickMenu的active类(控制显示)
|
80
|
+
*/
|
81
|
+
export const clickMenu = () => {
|
82
|
+
const menuElement = $dom('#clickMenu');
|
61
83
|
window.oncontextmenu = function (event) {
|
62
|
-
if (event.ctrlKey) {
|
84
|
+
if (event.ctrlKey) { // 当按下ctrl键时不触发自定义菜单
|
63
85
|
return;
|
64
86
|
}
|
65
87
|
event.preventDefault();
|
66
|
-
let x = event.offsetX;
|
88
|
+
let x = event.offsetX; // 触发点到页面窗口左边的距离
|
67
89
|
let y = event.offsetY;
|
68
|
-
const winWidth = window.innerWidth;
|
90
|
+
const winWidth = window.innerWidth; // 窗口的内部宽度(包括滚动条)
|
69
91
|
const winHeight = window.innerHeight;
|
70
|
-
const menuWidth = menuElement.offsetWidth;
|
92
|
+
const menuWidth = menuElement.offsetWidth; // 菜单宽度
|
71
93
|
const menuHeight = menuElement.offsetHeight;
|
72
94
|
x = winWidth - menuWidth >= x ? x : winWidth - menuWidth;
|
73
95
|
y = winHeight - menuHeight >= y ? y : winHeight - menuHeight;
|
74
96
|
menuElement.style.top = y + 'px';
|
75
97
|
menuElement.style.left = x + 'px';
|
76
98
|
menuElement.classList.add('active');
|
77
|
-
|
99
|
+
$dom.each('.clickSubmenu', (submenu) => {
|
78
100
|
if (x > (winWidth - menuWidth - submenu.offsetWidth)) {
|
79
101
|
submenu.style.left = '-200px';
|
80
102
|
}
|
@@ -88,30 +110,29 @@ const clickMenu = () => {
|
|
88
110
|
menuElement.classList.remove('active');
|
89
111
|
});
|
90
112
|
};
|
91
|
-
|
92
|
-
const visibilityListener = () => {
|
93
|
-
const iconNode =
|
113
|
+
// 可见度监听(离开页面和返回时更改document的title)
|
114
|
+
export const visibilityListener = () => {
|
115
|
+
const iconNode = $dom('[rel="icon"]');
|
94
116
|
document.addEventListener('visibilitychange', () => {
|
95
117
|
switch (document.visibilityState) {
|
96
118
|
case 'hidden':
|
97
|
-
iconNode.attr('href',
|
119
|
+
iconNode.attr('href', statics + CONFIG.favicon.hidden);
|
98
120
|
document.title = LOCAL.favicon.hide;
|
99
121
|
if (CONFIG.loader.switch) {
|
100
|
-
|
122
|
+
Loader.show();
|
101
123
|
}
|
102
|
-
clearTimeout(
|
124
|
+
clearTimeout(titleTime);
|
103
125
|
break;
|
104
126
|
case 'visible':
|
105
|
-
iconNode.attr('href',
|
127
|
+
iconNode.attr('href', statics + CONFIG.favicon.normal);
|
106
128
|
document.title = LOCAL.favicon.show;
|
107
129
|
if (CONFIG.loader.switch) {
|
108
|
-
|
130
|
+
Loader.hide(1000);
|
109
131
|
}
|
110
|
-
|
111
|
-
document.title =
|
132
|
+
setTitleTime(setTimeout(() => {
|
133
|
+
document.title = originTitle;
|
112
134
|
}, 2000));
|
113
135
|
break;
|
114
136
|
}
|
115
137
|
});
|
116
138
|
};
|
117
|
-
exports.visibilityListener = visibilityListener;
|
@@ -1,58 +1,62 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
const changeTheme = (type) => {
|
8
|
-
const btn =
|
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
9
|
if (type === 'dark') {
|
10
|
-
|
10
|
+
HTML.attr('data-theme', type);
|
11
11
|
btn.removeClass('i-sun');
|
12
12
|
btn.addClass('i-moon');
|
13
13
|
}
|
14
14
|
else {
|
15
|
-
|
15
|
+
HTML.attr('data-theme', null);
|
16
16
|
btn.removeClass('i-moon');
|
17
17
|
btn.addClass('i-sun');
|
18
18
|
}
|
19
19
|
};
|
20
|
-
|
21
|
-
|
20
|
+
/**
|
21
|
+
* 自动调整黑夜白天
|
22
|
+
* 优先级: 手动选择>时间>跟随系统
|
23
|
+
*/
|
24
|
+
export const autoDarkmode = () => {
|
22
25
|
if (CONFIG.auto_dark.enable) {
|
23
26
|
if (new Date().getHours() >= CONFIG.auto_dark.start || new Date().getHours() <= CONFIG.auto_dark.end) {
|
24
|
-
|
27
|
+
changeTheme('dark');
|
25
28
|
}
|
26
29
|
else {
|
27
|
-
|
30
|
+
changeTheme();
|
28
31
|
}
|
29
32
|
}
|
30
33
|
};
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
/**
|
35
|
+
* 更改主题的meta
|
36
|
+
*/
|
37
|
+
export const changeMetaTheme = (color) => {
|
38
|
+
if (HTML.attr('data-theme') === 'dark') {
|
34
39
|
color = '#222';
|
35
40
|
}
|
36
|
-
|
41
|
+
$dom('meta[name="theme-color"]').attr('content', color);
|
37
42
|
};
|
38
|
-
|
39
|
-
const themeColorListener = () => {
|
43
|
+
// 记忆日夜模式切换和系统亮暗模式监听
|
44
|
+
export const themeColorListener = () => {
|
40
45
|
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (mediaQueryList) => {
|
41
46
|
if (mediaQueryList.matches) {
|
42
|
-
|
47
|
+
changeTheme('dark');
|
43
48
|
}
|
44
49
|
else {
|
45
|
-
|
50
|
+
changeTheme();
|
46
51
|
}
|
47
52
|
});
|
48
|
-
const t =
|
53
|
+
const t = $storage.get('theme');
|
49
54
|
if (t) {
|
50
|
-
|
55
|
+
changeTheme(t);
|
51
56
|
}
|
52
57
|
else {
|
53
58
|
if (CONFIG.darkmode) {
|
54
|
-
|
59
|
+
changeTheme('dark');
|
55
60
|
}
|
56
61
|
}
|
57
62
|
};
|
58
|
-
exports.themeColorListener = themeColorListener;
|