-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
322 lines (271 loc) · 11 KB
/
Copy pathscript.js
File metadata and controls
322 lines (271 loc) · 11 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
document.addEventListener('DOMContentLoaded', function() {
// 搜索相关代码
const toolSearch = document.getElementById('toolSearch');
const searchResult = document.getElementById('searchResult');
// 获取所有工具项
const tools = Array.from(document.querySelectorAll('.tool-item')).map(item => ({
element: item,
name: item.querySelector('span').textContent.trim(),
category: item.closest('.tool-category').querySelector('h3').textContent.trim()
}));
// 搜索功能
function performSearch(keyword) {
searchResult.innerHTML = '';
if (!keyword) {
searchResult.classList.remove('active');
return;
}
const matches = tools.filter(tool =>
tool.name.toLowerCase().includes(keyword.toLowerCase()) ||
tool.category.toLowerCase().includes(keyword.toLowerCase())
);
if (matches.length > 0) {
matches.forEach(tool => {
const div = document.createElement('div');
div.className = 'search-result-item';
div.innerHTML = `
<span>${tool.name}</span>
<small style="color: #666; margin-left: 8px;">${tool.category}</small>
`;
div.addEventListener('click', () => {
tool.element.scrollIntoView({ behavior: 'smooth', block: 'center' });
tool.element.classList.add('highlight');
setTimeout(() => tool.element.classList.remove('highlight'), 2000);
searchResult.classList.remove('active');
toolSearch.value = '';
});
searchResult.appendChild(div);
});
searchResult.classList.add('active');
} else {
const noResult = document.createElement('div');
noResult.className = 'search-result-item no-result';
noResult.textContent = '未找到相关工具';
searchResult.appendChild(noResult);
searchResult.classList.add('active');
}
}
// 输入事件监听
let debounceTimer;
toolSearch.addEventListener('input', (e) => {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => {
performSearch(e.target.value.trim());
}, 300);
});
// 点击空白处关闭搜索结果
document.addEventListener('click', (e) => {
if (!toolSearch.contains(e.target) && !searchResult.contains(e.target)) {
searchResult.classList.remove('active');
}
});
// 按下 ESC 键关闭搜索结果
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
searchResult.classList.remove('active');
toolSearch.value = '';
toolSearch.blur();
}
});
// 雪花相关变量
let snowInterval;
let isSnowing = true; // 默认开启
function createSnowflake() {
const snowflake = document.createElement('div');
snowflake.classList.add('snowflake');
snowflake.innerHTML = '❅';
snowflake.style.left = Math.random() * 100 + 'vw';
snowflake.style.fontSize = (Math.random() * 15 + 8) + 'px';
snowflake.style.opacity = Math.random() * 0.8 + 0.2;
const duration = Math.random() * 5 + 8;
snowflake.style.animationDuration = duration + 's';
document.body.appendChild(snowflake);
setTimeout(() => {
snowflake.remove();
}, duration * 1000);
}
function startSnowfall() {
if (!snowInterval) { // 修改判断条件
isSnowing = true;
snowInterval = setInterval(createSnowflake, 300);
document.getElementById('snowToggle').classList.add('active');
}
}
function stopSnowfall() {
if (snowInterval) { // 修改判断条件
isSnowing = false;
clearInterval(snowInterval);
snowInterval = null; // 清除interval引用
document.getElementById('snowToggle').classList.remove('active');
document.querySelectorAll('.snowflake').forEach(snowflake => {
snowflake.remove();
});
}
}
// 页面加载完成后立即启动雪花效果
window.addEventListener('load', function() {
startSnowfall();
});
// 雪花开关按钮点击事件
document.getElementById('snowToggle').addEventListener('click', function() {
if (isSnowing) {
stopSnowfall();
} else {
startSnowfall();
}
});
// 收藏相关代码
const favoriteHearts = document.querySelectorAll('.tool-item .favorite-heart');
const favoriteToggle = document.getElementById('favoriteToggle');
let favoriteList = null;
let favorites = JSON.parse(localStorage.getItem('favorites')) || [];
function updateFavoriteStatus() {
favoriteHearts.forEach(heart => {
const toolItem = heart.closest('.tool-item');
const toolId = toolItem.getAttribute('data-id');
heart.classList.remove('active'); // 先移除所有激活状态
if (favorites.includes(toolId)) {
heart.classList.add('active');
}
});
}
function showFavorites() {
favoriteList = document.createElement('div');
favoriteList.className = 'favorite-list modal';
// 添加标题和关闭按钮
const header = document.createElement('div');
header.className = 'favorite-header';
header.innerHTML = `
<h3>我的收藏</h3>
<button class="close-btn"><i class="fas fa-times"></i></button>
`;
favoriteList.appendChild(header);
// 添加收藏内容容器
const content = document.createElement('div');
content.className = 'favorite-content';
favoriteList.appendChild(content);
updateFavoritesList();
document.body.appendChild(favoriteList);
// 添加关闭按钮事件
const closeBtn = favoriteList.querySelector('.close-btn');
closeBtn.addEventListener('click', hideFavorites);
}
function updateFavoritesList() {
const content = favoriteList.querySelector('.favorite-content');
content.innerHTML = '';
if (favorites.length === 0) {
const emptyMessage = document.createElement('div');
emptyMessage.className = 'empty-favorites';
emptyMessage.textContent = '还没有收藏任何工具';
content.appendChild(emptyMessage);
return;
}
favorites.forEach(id => {
const originalTool = document.querySelector(`.tool-item[data-id="${id}"]`);
if (originalTool) {
const toolItem = document.createElement('div');
toolItem.className = 'favorite-item';
toolItem.innerHTML = `
<i class="${originalTool.querySelector('i:not(.favorite-heart)').className}"></i>
<span>${originalTool.querySelector('span').textContent}</span>
`;
toolItem.addEventListener('click', () => {
window.open(originalTool.href, '_blank');
});
content.appendChild(toolItem);
}
});
}
function hideFavorites() {
if (favoriteList) {
favoriteList.remove();
favoriteList = null;
}
}
// 初始化收藏状态
favoriteHearts.forEach((heart, index) => {
const toolItem = heart.closest('.tool-item');
if (!toolItem.hasAttribute('data-id')) {
toolItem.setAttribute('data-id', `tool-${index}`);
}
// 检查是否在收藏列表中,如果是则添加激活状态
const toolId = toolItem.getAttribute('data-id');
if (favorites.includes(toolId)) {
heart.classList.add('active');
}
});
// 收藏按钮点击事件
favoriteToggle.addEventListener('click', function() {
if (!favoriteList) {
showFavorites();
} else {
hideFavorites();
}
});
// 工具卡片收藏点击事件
favoriteHearts.forEach(heart => {
heart.addEventListener('click', function(e) {
e.stopPropagation();
e.preventDefault();
const toolItem = this.closest('.tool-item');
const toolId = toolItem.getAttribute('data-id');
if (this.classList.contains('active')) {
this.classList.remove('active');
favorites = favorites.filter(id => id !== toolId);
} else {
this.classList.add('active');
favorites.push(toolId);
}
localStorage.setItem('favorites', JSON.stringify(favorites));
if (favoriteList) {
updateFavoritesList();
}
});
});
// 点击其他地方关闭收藏列表
document.addEventListener('click', function(e) {
if (favoriteList && !favoriteList.contains(e.target) && !favoriteToggle.contains(e.target)) {
hideFavorites();
}
});
// 添加滚动隐藏功能
let lastScrollTop = 0;
const sideButtons = document.querySelector('.side-buttons');
function handleScroll() {
const currentScrollTop = window.pageYOffset || document.documentElement.scrollTop;
// 判断滚动方向
if (currentScrollTop > lastScrollTop) {
// 向下滚动
sideButtons.classList.add('hide');
} else {
// 向上滚动
sideButtons.classList.remove('hide');
}
lastScrollTop = currentScrollTop;
}
// 添加滚动事件监听
window.addEventListener('scroll', handleScroll);
});
class MusicPlayer {
constructor() {
this.player = document.getElementById('musicPlayer');
this.icon = document.getElementById('radioIcon');
this.isPlaying = false;
// 添加点击事件监听
this.icon.addEventListener('click', () => this.togglePlay());
}
togglePlay() {
if (this.isPlaying) {
this.player.pause();
this.icon.classList.remove('playing');
} else {
this.player.play();
this.icon.classList.add('playing');
}
this.isPlaying = !this.isPlaying;
}
}
// 初始化音乐播放器
document.addEventListener('DOMContentLoaded', () => {
new MusicPlayer();
});