-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
464 lines (366 loc) · 13.6 KB
/
index.html
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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title>插件说明文档</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
</head>
<style>
html,
body {
height: 100%;
width: 100%;
overflow-y: hidden;
overflow-x: hidden;
background-color: #141520;
}
img {
height: 100%;
width: 100%;
object-fit: cover;
/* 高度自动调整以保持图片的原始宽高比 */
}
/* 只指定md中的链接 */
p a:-webkit-any-link {
color: white;
cursor: pointer;
text-decoration: underline;
}
p {
display: block;
margin-block-start: 1em;
margin-block-end: 1em;
margin-inline-start: 0px;
margin-inline-end: 0px;
unicode-bidi: isolate;
word-wrap: break-word;
/* 或使用 overflow-wrap: break-word; */
}
blockquote {
display: block;
/* 使块级元素可设置宽高 */
margin-block-start: 1em;
/* 增加顶部外边距 */
margin-block-end: 1em;
/* 增加底部外边距 */
margin-inline-start: 40px;
/* 增加左侧外边距 */
margin-inline-end: 40px;
/* 增加右侧外边距 */
unicode-bidi: isolate;
/* 防止换行 */
margin-left: 20px;
/* 减少左边距,使元素向左移动 */
padding-left: 20px;
/* 增加内边距,保持内容的位置 */
border-left: 5px solid #7854bc;
/* 设置左边框为5px宽,实线 ,颜色*/
background-color: #242432;
/* 设置背景色 */
}
.author {
display: block;
/* 使块级元素可设置宽高 */
margin-block-start: 0;
/* 增加顶部外边距 */
margin-block-end: 0;
/* 增加底部外边距 */
margin-inline-start: 0;
/* 增加左侧外边距 */
margin-inline-end: 0;
/* 增加右侧外边距 */
unicode-bidi: isolate;
/* 防止换行 */
margin-left: 0;
/* 减少左边距,使元素向左移动 */
padding-left: 16px;
/* 增加内边距,保持内容的位置 */
margin-bottom: 15%;
box-sizing: border-box;
/* 防止子元素影响边框 */
border-left: 2px solid #81818b;
/* 设置左边框为5px宽,实线 ,颜色*/
background-color: #43435600;
/* 设置背景色 */
transition: border-left 0.5s ease;
}
/* 作者作品旁的直线的选择状态*/
.authorSelected {
border-left: 2px solid #ffffff;
}
.authorhref {
text-align: left;
/* 左对齐 */
color: #81818b;
/* 字体颜色 */
font-size: xx-small;
/* 字体大小 */
text-decoration: none;
/* 去掉下划线 */
transition: color 0.5s;
/* 增加过渡效果 */
}
.authorhref:hover {
color: #ffffff;
}
.index {
position: fixed;
/* 将目录栏设置为固定位置 */
top: 0;
left: 0;
width: 15%;
height: 100%;
/* 设置高度和宽度 */
/* 设置目录栏的宽度 */
overflow-y: auto;
/* 如果内容超出目录栏高度,添加滚动条 */
background-color: #232538;
/* 设置背景颜色 */
}
.indextcontent {
padding: 10%;
/* 增加内边距 */
}
.indextitle {
width: 100%;
/* 宽度填充满 */
font-weight: bold;
font-size: xx-large;
color: #fff;
margin-bottom: 10%;
}
.works {
background-color: #ffffff00;
border: 1px solid #ffffff00;
width: 100%;
margin-bottom: 0;
/* 增加底部外边距 */
border-radius: 0;
/* 圆角 */
padding-top: 5%;
padding-bottom: 5%;
/* 增加内边距 */
text-align: left;
color: #81818b;
transition: border 0.5s, color 0.5s;
/* 增加过渡效果 */
}
.works:hover {
color: #e9e9e9;
}
/* 按钮的选择状态*/
.selected {
font-weight: bold;
color: #ffffff;
}
.contant {
height: 100%;
width: 85%;
right: 0;
position: fixed;
top: 0;
display: flex;
/* 添加Flexbox布局 */
justify-content: center;
/* 水平居中 */
align-items: flex-end;
/* 垂直靠下 */
}
#inspection {
height: 95%;
width: 70%;
overflow-y: auto;
color: #fff;
}
/* 隐藏滑动条轨道 */
::-webkit-scrollbar {
width: 0;
height: 0;
}
/* 隐藏滑动条滑块以外的部分 */
::-webkit-scrollbar-thumb {
background-color: #24243200;
}
/* 隐藏滑动条轨道 */
::-webkit-scrollbar-track {
background-color: #24243200;
}
</style>
<body>
<div class="index">
<!-- 目录栏 -->
<div class="indextcontent">
<div class="indextitle">
<!-- 目录栏标题 -->
目录
</div>
<div class="indexinspection"></div>
</div>
</div>
<div class="contant">
<div id="inspection"></div>
</div>
</body>
<script>
// 显示markdown文件内容
function MdShow(path) {
fetch(path)
.then(response => response.text())
.then(text => {
var inspectionElement = document.getElementById('inspection');
inspectionElement.innerHTML = marked.parse(text);// 解析markdown文本并显示
})
.catch(error => console.error('Error loading the Markdown file:', error));// 捕获错误并打印到控制台
}
async function getAuthorWorks() {
var authorDictionary = {}
return new Promise((resolve, reject) => {
fetch('mds.txt')
.then(response => response.text())
.then(text => {
let lines = text.split('\n');// 按行分割文本
// 定义一个字典,用于存储作者和文件名,结构为{作者:文件名数组}
// 遍历文本行列表
for (let i = 0; i < lines.length; i++) {
// 跳过空行
if (lines[i] != '') {
var name = lines[i].split('.')[0];//获取文件名
var author = lines[i].split('#')[1];//获取作者
if (author in authorDictionary) {
// 如果作者已经在字典中,将文件名添加到对应的数组中
authorDictionary[author].push(name);
} else {
// 如果作者不在字典中,创建一个新的数组来存储文件名,并将作者作为键
authorDictionary[author] = [name];
}
};
}
for (let author in authorDictionary) {
// 创建一个新的元素,作为目录栏的子元素
var authorhref = author.split('@')[1];//匹配链接)
var newElement = document.createElement("blockquote");
newElement.className = "author";
newElement.innerHTML = `<a class="authorhref" href=${authorhref}> ${author.split('@')[0]}</a>`;//设置作者名
// 获取父元素
var parentElement = document.getElementsByClassName("indexinspection")[0];
// 将新元素添加为父元素的子元素
parentElement.appendChild(newElement);
parentElement = newElement;
// 创建n个新的子元素,作为目录栏的子元素
for (let j = 0; j < authorDictionary[author].length; j++) {
var newElement = document.createElement("button");
newElement.className = "works";
newElement.textContent = authorDictionary[author][j].split('.')[0];
console.log(authorDictionary[author][j] + '.md');//匹配文件名,并设置文本内容
newElement.onclick = function () {
MdShow('mdDocumentation/' + authorDictionary[author][j] + '.md');//匹配文件名,并设置路径,调用显示md函数
}
// 将新元素添加为父元素的子元素
parentElement.appendChild(newElement);
}
};
// 获取按钮元素
const myButtons = document.getElementsByClassName('works');
// 获取子元素的父元素
var previousButton = null;//记录上一个被点击的按钮
var previousParent = null;//记录上一个按钮的父元素
// 点击后切换按钮样式
// 添加点击事件监听器
for (let i = 0; i < myButtons.length; i++) {
myButtons[i].addEventListener('click', function () {
if (previousButton != myButtons[i]) {
var parentElement = this.parentNode;
// 切换按钮的选择状态
this.classList.toggle('selected'); // 使用this来引用当前被点击的按钮
if (previousButton != null) {
previousButton.classList.remove('selected');// 取消上一个按钮的选择状态
var inspectionElement = document.getElementById('inspection');
inspectionElement.scrollTop = 0; // 页面回到顶部
}
previousButton = this; // 记录上一个被点击的按钮
// 切换父元素的选择状态
if (parentElement != previousParent) {
// 切换按钮的选择状态
parentElement.classList.toggle('authorSelected'); // 使用this来引用当前被点击的按钮
if (previousParent != null) {
previousParent.classList.remove('authorSelected'); // 取消上一个按钮的选择状态
}
}
previousParent = this.parentNode; // 记录上一个被点击的按钮
}
}
);
}
resolve();// 异步函数结束,通知调用者
})
.catch(error => console.error('Error loading the Markdown file:', error));// 捕获错误并打印到控制台
})
}
// 获取URL参数
function getParams() {
const currentUrl = window.location.href;
var startIndex = currentUrl.indexOf('#');
if (startIndex === -1) {
console.log('未找到查询参数');
return 0;
}
var paramsStr = currentUrl.substr(startIndex + 1);
var params = new URLSearchParams(paramsStr);
console.log(params);
try {
// 检查是否存在自定义设置
if (params.has('selection')) {
var selected = params.get('selection');
console.log(selected);
// 在这里执行自定义初始化操作
console.log('使用自定义设置初始化网站');
return selected;
} else {
// 在这里执行默认初始化操作
console.log('使用默认设置初始化网站');
return 0;
}
}
catch (error) {
console.log(error);
return 0;
}
}
//打印每一个选项对应的ulr
function printUlr() {
const baseUrl = window.location.origin + window.location.pathname;
var works = document.getElementsByClassName('works');
for (let i = 0; i < works.length; i++) {
console.log(works[i].textContent + ':' + baseUrl + '#selection=' + works[i].textContent);
}
}
//根据参数选择按钮
function selectButton(i) {
if (i != 0) {
var works = document.getElementsByClassName('works');
console.log(works.length);
for (let j = 0; j < works.length; j++) {
if (works[j].textContent == i) {
works[j].click();
break;
}
}
}
else
{
var works = document.getElementsByClassName('works');
works[0].click();
}
}
// 调用异步函数
(async () => {
await getAuthorWorks();
var works = document.getElementsByClassName('works');
console.log(works.length);
printUlr();//打印每一个选项对应的ulr
var i = getParams();//获取URL参数
selectButton(i);//根据参数选择按钮
})();
</script>
</html>