-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1026 lines (901 loc) · 33.1 KB
/
Copy pathindex.html
File metadata and controls
1026 lines (901 loc) · 33.1 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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JustHTML 只需网页! - 全能工具箱</title>
<script>
/**
* 动态加载(强制去除缓存) CSS 的函数
* @param {string} src - 要加载的 CSS 的 src 链接
* @returns {Promise} 返回一个 Promise 对象,用于处理异步加载
*/
function loadStyle(src) {
return new Promise((resolve, reject) => {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = src + '?v=' + new Date().getTime(); // 使用时间戳避免缓存
link.async = true;
link.onload = resolve;
link.onerror = reject;
document.head.appendChild(link);
});
}
</script>
<script>
loadStyle('./assets/style.css')
</script>
<script src="./package/Vue/code/vue.global.prod.js"></script>
<script src="./package/Marked/code/marked.umd.js"></script>
<script type="module" src="./package/Sober/code/main.js"></script>
<script src="./assets/AutoRun.js"></script>
<script>
/**
* 动态加载(强制去除缓存) JS 的函数
* @param {string} src - 要加载的 JS 的 src 链接
* @returns {Promise} 返回一个 Promise 对象,用于处理异步加载
*/
function loadScript(src) {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = src + '?v=' + new Date().getTime(); // 使用时间戳避免缓存
script.async = true;
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
}
/**
* URL安全的Base64编码器
* 将输入字符串转换为URL安全的Base64编码格式
* @param {string} input - 要编码的字符串
* @returns {string} URL安全的Base64编码字符串
*/
function urlSafeBase64Encode(input) {
// 首先使用标准btoa进行Base64编码
const base64 = btoa(encodeURIComponent(input).replace(/%([0-9A-F]{2})/g, function(match, p1) {
return String.fromCharCode('0x' + p1);
}));
// 替换不安全的字符为URL安全的字符
return base64
.replace(/\+/g, '-') // 将 '+' 替换为 '-'
.replace(/\//g, '_') // 将 '/' 替换为 '_'
.replace(/=/g, ''); // 移除填充字符 '='
}
/**
* URL安全的Base64解码器
* 将URL安全的Base64编码字符串解码回原始字符串
* @param {string} input - URL安全的Base64编码字符串
* @returns {string} 解码后的原始字符串
*/
function urlSafeBase64Decode(input) {
// 先将URL安全的字符转换回标准Base64字符
let base64 = input
.replace(/-/g, '+') // 将 '-' 替换为 '+'
.replace(/_/g, '/'); // 将 '_' 替换为 '/'
// 根据需要添加填充字符
const padding = base64.length % 4;
if (padding !== 0) {
base64 += '='.repeat(4 - padding);
}
// 使用atob解码
return decodeURIComponent(Array.prototype.map.call(atob(base64), function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
// Cookie 操作工具函数
const cookieUtils = {
/**
* 设置Cookie
* @param {string} name - Cookie名称
* @param {string} value - Cookie值
* @param {number} days - 过期天数
*/
setCookie: function(name, value, days) {
const expires = new Date();
expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000));
document.cookie = name + '=' + encodeURIComponent(value) + ';expires=' + expires.toUTCString() + ';path=/';
},
/**
* 获取Cookie
* @param {string} name - Cookie名称
* @returns {string|null} Cookie值或null
*/
getCookie: function(name) {
const nameEQ = name + "=";
const ca = document.cookie.split(';');
for(let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
}
return null;
},
/**
* 删除Cookie
* @param {string} name - Cookie名称
*/
removeCookie: function(name) {
document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/';
}
};
// 收藏工具操作函数
const favoriteUtils = {
FAVORITE_COOKIE_NAME: 'justhtml_favorites',
/**
* 获取收藏的工具列表
* @returns {Array} 收藏的工具链接数组
*/
getFavorites: function() {
const favoritesStr = cookieUtils.getCookie(this.FAVORITE_COOKIE_NAME);
if (!favoritesStr) return [];
try {
return JSON.parse(favoritesStr);
} catch (e) {
console.error('Failed to parse favorites from cookie:', e);
return [];
}
},
/**
* 添加工具到收藏
* @param {string} toolLink - 工具链接
*/
addToFavorites: function(toolLink) {
const favorites = this.getFavorites();
if (!favorites.includes(toolLink)) {
favorites.push(toolLink);
cookieUtils.setCookie(this.FAVORITE_COOKIE_NAME, JSON.stringify(favorites), 365);
}
},
/**
* 从收藏中移除工具
* @param {string} toolLink - 工具链接
*/
removeFromFavorites: function(toolLink) {
const favorites = this.getFavorites();
const index = favorites.indexOf(toolLink);
if (index > -1) {
favorites.splice(index, 1);
cookieUtils.setCookie(this.FAVORITE_COOKIE_NAME, JSON.stringify(favorites), 365);
}
},
/**
* 检查工具是否已被收藏
* @param {string} toolLink - 工具链接
* @returns {boolean} 是否已被收藏
*/
isFavorite: function(toolLink) {
const favorites = this.getFavorites();
return favorites.includes(toolLink);
},
/**
* 获取收藏总数
* @returns {number} 收藏总数
*/
getFavoriteCount: function() {
return this.getFavorites().length;
}
};
</script>
<script src="./assets/AddHeader.js"></script>
<script src="./assets/AddFooter.js"></script>
<script src="./assets/AddIco.js"></script>
<!-- <script>
window.ToolsData = deepcopy(ToolsData);
</script> -->
<style>
.search-container {
margin: 20px auto;
max-width: 600px;
}
.search-box {
width: 100%;
padding: 12px 20px;
border-radius: var(--border-radius);
border: 1px solid var(--bg-tertiary);
background-color: var(--bg-secondary);
color: var(--text-primary);
font-size: 16px;
}
.tags-container {
margin: 20px auto;
max-width: 600px;
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.tag {
padding: 4px 12px;
background-color: var(--bg-secondary);
border: 1px solid var(--bg-tertiary);
border-radius: 20px;
cursor: pointer;
font-size: 14px;
transition: var(--transition);
}
.tag:hover {
background-color: var(--accent-color);
color: white;
}
.tag.active {
background-color: var(--accent-color);
color: white;
}
.categories {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
}
.category {
background-color: var(--bg-secondary);
border-radius: var(--border-radius);
padding: 20px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.category h2 {
color: var(--accent-color);
margin-bottom: 15px;
padding-bottom: 10px;
border-bottom: 1px solid var(--bg-tertiary);
}
.tools-list {
list-style: none;
}
.tools-list li {
padding: 8px 0;
border-bottom: 1px solid var(--bg-tertiary);
display: flex;
align-items: center;
justify-content: space-between;
}
.tools-list li:last-child {
border-bottom: none;
}
.tool-link {
color: var(--text-primary);
text-decoration: none;
flex-grow: 1;
transition: var(--transition);
padding: 5px 10px;
border-radius: 4px;
}
.tool-link:hover {
background-color: var(--bg-tertiary);
color: var(--accent-color);
}
.favorite-btn {
background: none;
border: none;
cursor: pointer;
color: #ccc;
font-size: 18px;
margin-left: 10px;
padding: 5px;
border-radius: 4px;
transition: color 0.3s;
}
.favorite-btn.favorited {
color: #ffcc00;
}
.favorite-btn:hover {
background-color: var(--bg-tertiary);
}
.highlight {
background-color: rgba(74, 158, 255, 0.2);
}
.subcategory-title {
font-weight: bold;
color: #6c757d;
margin-top: 15px;
margin-bottom: 10px;
padding-bottom: 5px;
border-bottom: 1px dashed var(--bg-tertiary);
}
.no-results {
text-align: center;
color: var(--text-secondary);
padding: 40px;
grid-column: 1 / -1;
}
.favorites-section {
margin: 20px auto;
max-width: 1200px;
background-color: var(--bg-secondary);
border-radius: var(--border-radius);
padding: 20px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
display: none;
}
.favorites-section.active {
display: block;
}
.favorites-section h2 {
color: var(--accent-color);
margin-bottom: 15px;
padding-bottom: 10px;
border-bottom: 1px solid var(--bg-tertiary);
}
.favorites-list {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 10px;
}
.favorite-item {
display: flex;
align-items: center;
justify-content: space-between;
background-color: var(--bg-primary);
padding: 10px 15px;
border-radius: 4px;
border: 1px solid var(--bg-tertiary);
}
.favorite-link {
color: var(--text-primary);
text-decoration: none;
flex-grow: 1;
}
.favorite-link:hover {
color: var(--accent-color);
}
.favorites-empty {
text-align: center;
color: var(--text-secondary);
padding: 20px;
}
.favorites-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.favorites-count {
font-size: 14px;
color: var(--text-secondary);
}
.clear-favorites-btn {
background-color: #dc3545;
color: white;
border: none;
padding: 6px 12px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
.clear-favorites-btn:hover {
background-color: #c82333;
}
.favorites-toggle {
float: right;
margin-top: 10px;
background-color: var(--accent-color);
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
}
.favorites-toggle:hover {
opacity: 0.9;
}
</style>
</head>
<body>
<div id="app">
<div class="container">
<button onclick="showVHDialog()"> 版本历史记录 </button>
<button onclick="showREDialog()"> README 文件 </button>
<button class="favorites-toggle" @click="toggleFavoritesView" v-if="!showingFavorites">查看收藏 ({{ favoriteCount }})</button>
<button class="favorites-toggle" @click="toggleFavoritesView" v-else>返回工具列表</button>
<div class="favorites-section" :class="{ active: showingFavorites }">
<div class="favorites-header">
<h2>我的收藏</h2>
<div class="favorites-count">共 {{ filteredFavoriteTools.length }} / {{ favoriteCount }} 个工具</div>
</div>
<div class="search-container">
<input type="text" v-model="favoriteSearchQuery" class="search-box" placeholder="搜索收藏的工具...">
</div>
<div class="favorites-list" v-if="filteredFavoriteTools.length > 0">
<div v-for="tool in filteredFavoriteTools" :key="tool.link" class="favorite-item">
<a :href="tool.link" class="favorite-link">{{ tool.content.replace(/^[^-]* - /, '') }}</a>
<button
@click.prevent="removeFromFavorites(tool.link)"
class="favorite-btn favorited"
title="取消收藏此工具">
★
</button>
</div>
</div>
<div v-else class="favorites-empty">
<p v-if="favoriteTools.length === 0">暂无收藏的工具</p>
<p v-else>没有找到匹配的收藏工具</p>
</div>
<div style="margin-top: 15px; text-align: right;" v-if="favoriteTools.length > 0">
<button @click="clearFavorites" class="clear-favorites-btn">清空收藏</button>
</div>
</div>
<div class="search-container" v-if="!showingFavorites">
<input type="text" id="searchBox" v-model="searchQuery" class="search-box" placeholder="搜索工具...">
</div>
<div class="tags-container" v-if="!showingFavorites && allTags.length > 0">
<div
v-for="tag in allTags"
:key="tag"
:class="['tag', { active: selectedTags.includes(tag) }]"
@click="toggleTag(tag)"
>
{{ tag }}
</div>
</div>
<div ref="cate" class="categories" v-if="!showingFavorites">
<!-- 使用 Vue v-for 循环生成工具分类 -->
<div v-for="(category, catIndex) in filteredCategories" :key="catIndex" class="category"
v-show="category.totalTools > 0">
<h2>{{ category.title }}</h2>
<ul class="tools-list">
<!-- 遍历每个分类下的子项目 -->
<template v-for="item in category.items">
<!-- 如果子项目有 items 数组,说明是分组结构 -->
<template v-if="item.items">
<li class="subcategory-title">{{ item.name }}</li>
<li v-for="subItem in item.items" :key="subItem.link"
:class="{ highlight: isHighlighted(subItem.content) }">
<a :href="subItem.link" class="tool-link">
{{ subItem.content.replace(/^[^-]* - /, '') }}
</a>
<button
@click.prevent="toggleFavorite(subItem.link)"
:class="['favorite-btn', { favorited: isFavorite(subItem.link) }]"
title="收藏/取消收藏此工具">
★
</button>
</li>
</template>
<!-- 如果子项目直接有 link 和 content,说明是单个工具 -->
<li v-else :key="item.link" :class="{ highlight: isHighlighted(item.content) }">
<a :href="item.link" class="tool-link">
{{ item.content.replace(/^[^-]* - /, '') }}
</a>
<button
@click.prevent="toggleFavorite(item.link)"
:class="['favorite-btn', { favorited: isFavorite(item.link) }]"
title="收藏/取消收藏此工具">
★
</button>
</li>
</template>
</ul>
</div>
<!-- 显示无结果提示 -->
<div v-if="!loading && ToolsData.length === 0" class="no-results">
<p>没有获取到工具</p>
</div>
<!-- 显示无结果提示 -->
<div v-if="!loading && searchQuery !== '' && filteredCategories.length === 0" class="no-results">
<p>没有找到匹配的工具</p>
</div>
<!-- 添加加载状态 -->
<div v-if="loading && searchQuery === ''" class="no-results">
<p>加载中...</p>
</div>
</div>
</div>
</div>
<dialog id="VersionHistoryDialog">
<div class="dialog-content">
<h2>版本历史</h2>
<pre id="VersionHistory"></pre>
<div class="dialog-actions">
<button class="btn" id="closeDialog_VerHis">关闭</button>
</div>
</div>
</dialog>
<dialog id="READMEDialog">
<div class="dialog-content">
<h2>README</h2>
<pre id="README"></pre>
<div class="dialog-actions">
<button class="btn" id="closeDialog_README">关闭</button>
</div>
</div>
</dialog>
<h1 id="wait">请等待</h1>
<script>
document.addEventListener('DOMContentLoaded', () => {
var dialog = document.getElementById('VersionHistoryDialog');
var closeDialogBtn = document.getElementById('closeDialog_VerHis');
// 添加打开对话框的方法到 全局 中
showVHDialog = function() {
dialog.showModal();
};
window.showVHDialog = showVHDialog
// 关闭对话框事件
closeDialogBtn.addEventListener('click', () => {
dialog.close();
});
// 点击对话框外部关闭对话框
dialog.addEventListener('click', (event) => {
if (event.target === dialog) {
dialog.close();
}
});
});
document.addEventListener('DOMContentLoaded', () => {
var dialog = document.getElementById('READMEDialog');
var closeDialogBtn = document.getElementById('closeDialog_README');
// 添加打开对话框的方法到 全局 中
showREDialog = function() {
const dialog_info = document.getElementById('infoDialog');
if (dialog_info) {
dialog_info.close();
}
dialog.showModal();
};
window.showREDialog = showREDialog
// 关闭对话框事件
closeDialogBtn.addEventListener('click', () => {
dialog.close();
});
// 点击对话框外部关闭对话框
dialog.addEventListener('click', (event) => {
if (event.target === dialog) {
dialog.close();
}
});
});
const { onMounted, createApp, ref, computed } = Vue;
const cate = ref()
let App = null;
// 创建一个延迟加载的函数
function initApp() {
App = createApp({
setup() {
// 初始化搜索查询
const searchQuery = ref('');
const favoriteSearchQuery = ref(''); // 为收藏列表新增搜索查询
const selectedTags = ref([]);
const loading = ref(true);
const isSearching = ref(false);
const showingFavorites = ref(false); // 控制是否显示收藏列表
// 获取收藏工具列表
const favoriteTools = ref([]);
const favoriteCount = ref(0);
// 切换显示收藏列表或工具列表
function toggleFavoritesView() {
showingFavorites.value = !showingFavorites.value;
}
// 计算属性:根据搜索词过滤收藏的工具
const filteredFavoriteTools = computed(() => {
if (!favoriteSearchQuery.value.trim()) {
return favoriteTools.value;
}
const query = favoriteSearchQuery.value.toLowerCase();
return favoriteTools.value.filter(tool =>
tool.content.toLowerCase().includes(query) ||
tool.link.toLowerCase().includes(query)
);
});
// 更新收藏工具列表
function updateFavoriteTools() {
const allTools = [];
const toolsData = window.ToolsData || [];
toolsData.forEach(category => {
if (category.items && Array.isArray(category.items)) {
category.items.forEach(item => {
if (item.items && Array.isArray(item.items)) {
// 存在嵌套的items,遍历内部items
item.items.forEach(subItem => {
if (subItem.link) {
allTools.push(subItem);
}
});
} else {
// 直接在items中有link
if (item.link) {
allTools.push(item);
}
}
});
}
});
// 筛选出收藏的工具
const favorites = favoriteUtils.getFavorites();
favoriteTools.value = allTools.filter(tool => favorites.includes(tool.link));
favoriteCount.value = favoriteTools.value.length;
}
// 获取工具数据并处理
const toolsData = window.ToolsData || [];
// 如果工具数据不存在,返回空数组
if (!toolsData || toolsData.length === 0) {
loading.value = false;
return {
searchQuery,
selectedTags,
loading,
isSearching,
allTags: [],
toggleTag: () => {},
filteredCategories: computed(() => []),
isHighlighted: () => false,
ToolsData: toolsData,
showingFavorites,
toggleFavoritesView,
favoriteTools,
favoriteCount,
isFavorite: () => false,
toggleFavorite: () => {},
removeFromFavorites: () => {},
clearFavorites: () => {}
};
}
// 提取所有唯一标签
const allTagsSet = new Set();
// 提取标签函数,从content中自动提取标签
function extractTagsFromContent(content) {
const lowerContent = content.toLowerCase();
const tags = [];
// 基于关键词提取标签
if (lowerContent.includes('text') || lowerContent.includes('文本')) tags.push('文本处理');
if (lowerContent.includes('convert') || lowerContent.includes('转换')) tags.push('格式转换');
if (lowerContent.includes('encode') || lowerContent.includes('编码') || lowerContent.includes('decode')) tags.push('编码解码');
if (lowerContent.includes('image') || lowerContent.includes('图片')) tags.push('图像处理');
if (lowerContent.includes('color') || lowerContent.includes('颜色')) tags.push('颜色工具');
if (lowerContent.includes('json') || lowerContent.includes('xml') || lowerContent.includes('yaml')) tags.push('数据格式');
if (lowerContent.includes('css') || lowerContent.includes('样式')) tags.push('CSS工具');
if (lowerContent.includes('js') || lowerContent.includes('javascript')) tags.push('JavaScript工具');
if (lowerContent.includes('html')) tags.push('HTML工具');
if (lowerContent.includes('calc') || lowerContent.includes('计算') || lowerContent.includes('calculator')) tags.push('计算器');
if (lowerContent.includes('encrypt') || lowerContent.includes('cipher') || lowerContent.includes('加密')) tags.push('加密解密');
if (lowerContent.includes('hash') || lowerContent.includes('签名')) tags.push('哈希生成');
if (lowerContent.includes('qr') || lowerContent.includes('二维码')) tags.push('二维码');
if (lowerContent.includes('password') || lowerContent.includes('密码')) tags.push('密码工具');
if (lowerContent.includes('date') || lowerContent.includes('时间')) tags.push('日期时间');
if (lowerContent.includes('url') || lowerContent.includes('链接')) tags.push('URL工具');
if (lowerContent.includes('sql') || lowerContent.includes('数据库')) tags.push('数据库工具');
if (lowerContent.includes('regex') || lowerContent.includes('正则')) tags.push('正则表达式');
if (lowerContent.includes('binary') || lowerContent.includes('二进制')) tags.push('二进制工具');
if (lowerContent.includes('number') || lowerContent.includes('数字')) tags.push('数字工具');
if (lowerContent.includes('unit') || lowerContent.includes('单位')) tags.push('单位转换');
if (lowerContent.includes('game') || lowerContent.includes('游戏')) tags.push('游戏工具');
if (lowerContent.includes('generator') || lowerContent.includes('生成')) tags.push('生成器');
if (lowerContent.includes('validator') || lowerContent.includes('验证')) tags.push('验证器');
if (lowerContent.includes('formatter') || lowerContent.includes('格式化')) tags.push('格式化');
if (lowerContent.includes('minifier') || lowerContent.includes('压缩')) tags.push('压缩工具');
if (lowerContent.includes('cron') || lowerContent.includes('定时')) tags.push('Cron工具');
if (lowerContent.includes('jwt') || lowerContent.includes('令牌')) tags.push('JWT工具');
if (lowerContent.includes('git') || lowerContent.includes('ignore')) tags.push('Git工具');
if (lowerContent.includes('sitemap') || lowerContent.includes('站点地图')) tags.push('网站工具');
if (lowerContent.includes('random') || lowerContent.includes('随机')) tags.push('随机工具');
// 添加默认标签
tags.push('实用工具');
return [...new Set(tags)]; // 去重
}
// 处理数据,为每个工具添加标签
const processedToolsDataWithTags = toolsData.map(category => {
const itemsWithTags = category.items.map(item => {
if (item.items) {
// 分组项目
const itemsWithTagged = item.items.map(subItem => {
const tags = extractTagsFromContent(subItem.content);
tags.forEach(tag => allTagsSet.add(tag)); // 收集所有标签
return {
...subItem,
tags: tags
};
});
return {
...item,
items: itemsWithTagged
};
} else {
// 单个项目
const tags = extractTagsFromContent(item.content);
tags.forEach(tag => allTagsSet.add(tag)); // 收集所有标签
return {
...item,
tags: tags
};
}
});
return {
...category,
items: itemsWithTags
};
});
// 所有唯一标签列表
const allTags = [...allTagsSet].sort();
// 切换标签选择
function toggleTag(tag) {
const index = selectedTags.value.indexOf(tag);
if (index > -1) {
selectedTags.value.splice(index, 1); // 取消选择
} else {
selectedTags.value.push(tag); // 选择标签
}
}
// 计算属性:根据搜索词和标签过滤工具
const filteredCategories = computed(() => {
// 如果没有搜索词和标签筛选,则返回原数据
if (!searchQuery.value.trim() && selectedTags.value.length === 0) {
return processedToolsDataWithTags.map(category => {
let totalTools = 0;
const itemsWithCounts = category.items.map(item => {
if (item.items) {
// 分组项目
totalTools += item.items.length;
return {
...item,
count: item.items.length
};
} else {
// 单个项目
totalTools++;
return item;
}
});
return {
...category,
items: itemsWithCounts,
totalTools: totalTools
};
});
}
const query = searchQuery.value.toLowerCase();
return processedToolsDataWithTags.map(category => {
let totalTools = 0;
const filteredItems = category.items.flatMap(item => {
if (item.items) {
// 处理分组项目
const filteredSubItems = item.items.filter(subItem => {
// 检查搜索词匹配
const matchesSearch = !query || subItem.content.toLowerCase().includes(query);
// 检查标签匹配
const matchesTags = selectedTags.value.length === 0 ||
selectedTags.value.every(tag => subItem.tags.includes(tag));
return matchesSearch && matchesTags;
});
if (filteredSubItems.length > 0) {
totalTools += filteredSubItems.length;
return [{
...item,
items: filteredSubItems
}];
}
} else {
// 处理单个项目
const matchesSearch = !query || item.content.toLowerCase().includes(query);
const matchesTags = selectedTags.value.length === 0 ||
selectedTags.value.every(tag => item.tags.includes(tag));
if (matchesSearch && matchesTags) {
totalTools++;
return [item];
}
}
return [];
});
return {
...category,
items: filteredItems,
totalTools: totalTools
};
}).filter(category => category.totalTools > 0); // 只显示有匹配工具的分类
});
// 判断工具是否已被收藏
const isFavorite = (toolLink) => {
return favoriteUtils.isFavorite(toolLink);
};
// 切换收藏状态
const toggleFavorite = (toolLink) => {
if (isFavorite(toolLink)) {
favoriteUtils.removeFromFavorites(toolLink);
} else {
favoriteUtils.addToFavorites(toolLink);
}
updateFavoriteTools(); // 更新收藏列表
};
// 从收藏中移除
const removeFromFavorites = (toolLink) => {
favoriteUtils.removeFromFavorites(toolLink);
updateFavoriteTools(); // 更新收藏列表
};
// 清空收藏
const clearFavorites = () => {
if (confirm('确定要清空所有收藏吗?此操作不可撤销。')) {
cookieUtils.removeCookie('justhtml_favorites');
updateFavoriteTools(); // 更新收藏列表
}
};
// 判断工具名称是否高亮显示
const isHighlighted = (toolContent) => {
if (!searchQuery.value.trim()) {
return false;
}
return toolContent.toLowerCase().includes(searchQuery.value.toLowerCase());
};
// 初始化收藏工具列表
updateFavoriteTools();
loading.value = false;
return {
searchQuery,
favoriteSearchQuery, // 返回收藏搜索查询
selectedTags,
loading,
isSearching,
allTags,
toggleTag,
filteredCategories,
isHighlighted,
ToolsData: processedToolsDataWithTags,
showingFavorites,
toggleFavoritesView,
favoriteTools,
favoriteCount,
filteredFavoriteTools, // 返回过滤后的收藏工具
isFavorite,
toggleFavorite,
removeFromFavorites,
clearFavorites
};
}
})
window.vueApp = App
App.mount('#app');
}
document.getElementById('app').style.opacity = '0';
document.getElementById('wait').style.opacity = '1';
// 等待所有脚本加载完成后初始化应用
Promise.all([
loadScript('./assets/Tools.js'),
loadScript('./assets/ToolsData.js')
])
.then(() => {
// 复制数据
window.ToolsData = deepcopy(ToolsData);
window.Tools = [];
function extractLinks(data) {
data.forEach(category => {
if (category.items && Array.isArray(category.items)) {
category.items.forEach(item => {
if (item.items && Array.isArray(item.items)) {
// 存在嵌套的items,遍历内部items
item.items.forEach(subItem => {
if (subItem.link) {
window.Tools.push(subItem.link);
}
});
} else {
// 直接在items中有link
if (item.link) {
window.Tools.push(item.link);
}
}
});
}
});
}
extractLinks(window.ToolsData);
// 等待README和VersionHistory加载完成
return Promise.all([