Repository navigation
Expand file tree
/
Copy pathjs.js
More file actions
154 lines (129 loc) · 4.03 KB
/
Copy pathjs.js
File metadata and controls
154 lines (129 loc) · 4.03 KB
1
2
3
4
5
6
7
8
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// update time 2026/10/06 | version v1.2
/* ================================================================
主题切换
================================================================ */
function loadCSS(href, id = 'theme-css') {
const link = document.createElement('link');
link.rel = 'preload';
link.as = 'style';
link.href = href;
link.dataset.themeLoading = id;
link.onload = function () {
this.rel = 'stylesheet';
this.id = id;
delete this.dataset.themeLoading;
document.querySelectorAll('#' + id).forEach(el => {
if (el !== this) el.remove();
});
};
link.onerror = function () {
console.warn('[loadCSS] failed:', href);
this.remove();
};
document.head.appendChild(link);
}
loadCSS(localStorage.getItem('theme') || 'theme0.css');
document.addEventListener('DOMContentLoaded', () => {
const themeBtns = document.querySelectorAll('.site-header__theme-btn');
const currentTheme = localStorage.getItem('theme') || 'theme0.css';
function updateActiveBtn(href) {
themeBtns.forEach(btn => {
btn.classList.toggle('site-header__theme-btn--active', btn.dataset.theme === href);
});
}
updateActiveBtn(currentTheme);
themeBtns.forEach(btn => {
btn.addEventListener('click', () => {
const href = btn.dataset.theme;
loadCSS(href);
localStorage.setItem('theme', href);
updateActiveBtn(href);
});
});
});
/* ================================================================
标签页标题打字机
================================================================ */
const titles = [
"ARKFUTURE",
"ARK LAB",
"ARKFUTURE STUDIO",
"技术无止,勇于创新",
"以史为镜,洞察未来"
];
const TYPEWRITER = {
idx: 0,
pos: 0,
deleting: false,
cursor: true,
blinking: false,
cursorTimer: null,
timer: null,
TYPE_SPEED: 100,
DELETE_SPEED: 55,
PAUSE_FULL: 1600,
PAUSE_EMPTY: 350,
render() {
const text = titles[this.idx].slice(0, this.pos);
document.title = text + (this.cursor ? '█' : ' ');
},
setCursorSolid() {
clearInterval(this.cursorTimer);
this.blinking = false;
this.cursor = true;
},
setCursorBlink() {
if (this.blinking) return;
this.blinking = true;
this.cursorTimer = setInterval(() => {
this.cursor = !this.cursor;
this.render();
}, 500);
},
step() {
const cur = titles[this.idx];
if (!this.deleting) {
if (this.pos < cur.length) {
this.setCursorSolid();
this.pos++;
this.render();
this.schedule(this.TYPE_SPEED);
} else {
this.setCursorBlink();
this.schedule(this.PAUSE_FULL, () => {
this.deleting = true;
this.step();
});
}
} else {
if (this.pos > 0) {
this.setCursorSolid();
this.pos--;
this.render();
this.schedule(this.DELETE_SPEED);
} else {
this.setCursorBlink();
this.idx = (this.idx + 1) % titles.length;
this.deleting = false;
this.schedule(this.PAUSE_EMPTY);
}
}
},
schedule(delay, fn) {
clearTimeout(this.timer);
this.timer = setTimeout(fn || (() => this.step()), delay);
},
start() {
this.step();
}
};
TYPEWRITER.start();
/* ================================================================
控制台计数器
================================================================ */
let counter = 0;
function incrementCounter() {
const now = new Date();
console.log(`计: ${counter}; 时: ${now.toString()}; UTC: ${now.toUTCString()}; 戳: ${now.getTime()};`);
counter++;
}