-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcjhb_search.html
More file actions
105 lines (92 loc) · 3.39 KB
/
cjhb_search.html
File metadata and controls
105 lines (92 loc) · 3.39 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>纯几何吧题号查题</title>
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f2f2f2;
text-align: center;
padding: 50px;
color: #333;
}
input {
width: 200px;
padding: 5px 10px;
margin-top: 10px;
border-radius: 4px;
border: 1px solid #ccc;
font-size: 18px;
text-align: center;
}
button {
margin-left: 10px;
padding: 6px 12px;
font-size: 18px;
background-color: #4CAF50;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
transition-duration: 0.4s;
}
button:hover {
background-color: #45a049;
}
p {
font-size: 18px;
margin-top: 30px;
}
</style>
</head>
<body>
<h2>输入题号以查询帖子链接</h2>
<input type="number" id="indexInput" placeholder="输入题号">
<button id="searchButton">查找</button>
<p id="result"></p>
<script>
document.addEventListener("DOMContentLoaded", function () {
fetch('./cjhb.txt')
.then(response => {
if (response.ok) {
return response.text();
} else {
throw new Error('Failed to fetch txt file');
}
})
.then(content => {
let lines = content.trim().split("\n");
let dict = {};
for (let i = 0; i < lines.length; i += 2) {
let index = parseInt(lines[i].trim());
let urls = lines[i + 1].trim().split(' ').filter(url => url !== ''); // 分割多个URL并移除空的项
if (urls.length > 0) {
dict[index] = urls;
}
}
window.searchURL = function () {
let index = parseInt(document.getElementById("indexInput").value);
let resultElem = document.getElementById("result");
if (isNaN(index) || index < 1) {
resultElem.textContent = "输入错误,请输入一个正整数。";
return;
}
let urls = dict[index];
if (urls) {
let links = urls.map(url => `<a href="${"https://tieba.baidu.com/p" + url}" target="_blank">${"https://tieba.baidu.com/p" + url}</a>`).join(', ');
resultElem.innerHTML = `题号 ${index} 对应的链接是: ${links}`;
} else {
resultElem.textContent = `题号 ${index} 没有找到对应的链接。`;
}
}
document.getElementById('searchButton').addEventListener('click', searchURL);
})
.catch(error => {
console.error('Error:', error);
});
});
</script>
</body>
</html>