-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
296 lines (265 loc) · 11.9 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
<!DOCTYPE html>
<html lang="zh">
<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;
margin: 20px;
padding: 20px;
background-color: #f4f4f4;
}
h1 {
text-align: center;
}
input[type="text"], input[type="number"] {
width: 48%;
padding: 10px;
margin: 10px 1%;
box-sizing: border-box;
}
button {
padding: 10px;
margin: 10px 0;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
padding: 10px;
border: 1px solid #ccc;
text-align: left;
}
th {
background-color: #f0f0f0;
}
.checkbox-container {
margin-bottom: 10px;
}
.language-toggle {
position: absolute;
right: 20px;
top: 20px;
}
</style>
</head>
<body>
<div class="language-toggle">
<button id="langSwitch" onclick="toggleLanguage()">Show in English</button>
</div>
<h1 id="mainTitle">安全顶会论文搜索</h1>
<input type="text" id="titleAbstractInput" placeholder="正则搜索标题和摘要...">
<input type="text" id="authorInput" placeholder="基于作者搜索...">
<input type="number" id="yearInput" placeholder="只搜索某年以后的论文...">
<button onclick="filterTable()" id="searchButton">搜索</button>
<div class="checkbox-container">
<button onclick="selectAll()" id="selectAllButton">全选</button>
<button onclick="deselectAll()" id="deselectAllButton">全不选</button>
<div id="publicationFilters"></div>
</div>
<table id="resultsTable">
<thead>
<tr>
<th id="indexHeader">序号</th>
<th id="titleHeader">标题</th>
<th id="abstractHeader">摘要</th>
<th id="authorHeader">作者</th>
<th id="yearHeader">年份</th>
<th id="publicationHeader">发表刊物</th>
<th id="linkHeader">链接</th>
</tr>
</thead>
<tbody id="resultsBody">
<!-- 结果将填充到这里 -->
</tbody>
</table>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lz-string/1.4.4/lz-string.min.js"></script>
<script>
let jsonData = [];
let currentLanguage = localStorage.getItem('language') || 'zh';
// 语言文本
const texts = {
zh: {
title: "安全顶会论文搜索",
searchPlaceholder: "正则搜索标题和摘要...",
authorPlaceholder: "基于作者搜索...",
yearPlaceholder: "只搜索某年以后的论文...",
toggleButton: "Show in English",
searchButton: "搜索",
selectAllButton: "全选",
deselectAllButton: "全不选",
indexHeader: "序号",
titleHeader: "标题",
abstractHeader: "摘要",
authorHeader: "作者",
yearHeader: "年份",
publicationHeader: "发表刊物",
linkHeader: "链接",
viewLink: "查看",
},
en: {
title: "Security Top Conference Paper Search",
searchPlaceholder: "Regex search titles and abstracts...",
authorPlaceholder: "Search by author...",
yearPlaceholder: "Only search papers after a certain year...",
toggleButton: "中文显示",
searchButton: "Search",
selectAllButton: "Select All",
deselectAllButton: "Deselect All",
indexHeader: "Index",
titleHeader: "Title",
abstractHeader: "Abstract",
authorHeader: "Author",
yearHeader: "Year",
publicationHeader: "Publication",
linkHeader: "Link",
viewLink: "View",
}
};
// 切换语言
function toggleLanguage() {
currentLanguage = currentLanguage === 'zh' ? 'en' : 'zh';
localStorage.setItem('language', currentLanguage);
updateLanguage();
}
// 更新界面语言
function updateLanguage() {
document.getElementById('mainTitle').innerText = texts[currentLanguage].title;
document.getElementById('titleAbstractInput').placeholder = texts[currentLanguage].searchPlaceholder;
document.getElementById('authorInput').placeholder = texts[currentLanguage].authorPlaceholder;
document.getElementById('yearInput').placeholder = texts[currentLanguage].yearPlaceholder;
document.getElementById('langSwitch').innerText = texts[currentLanguage].toggleButton;
document.getElementById('searchButton').innerText = texts[currentLanguage].searchButton;
document.getElementById('selectAllButton').innerText = texts[currentLanguage].selectAllButton;
document.getElementById('deselectAllButton').innerText = texts[currentLanguage].deselectAllButton;
document.getElementById('indexHeader').innerText = texts[currentLanguage].indexHeader;
document.getElementById('titleHeader').innerText = texts[currentLanguage].titleHeader;
document.getElementById('abstractHeader').innerText = texts[currentLanguage].abstractHeader;
document.getElementById('authorHeader').innerText = texts[currentLanguage].authorHeader;
document.getElementById('yearHeader').innerText = texts[currentLanguage].yearHeader;
document.getElementById('publicationHeader').innerText = texts[currentLanguage].publicationHeader;
document.getElementById('linkHeader').innerText = texts[currentLanguage].linkHeader;
}
// 从配置文件加载 JSON 文件
function storeData(file, data) {
const compressedData = LZString.compress(JSON.stringify(data));
localStorage.setItem(file, compressedData);
}
function getData(file) {
const compressedData = localStorage.getItem(file);
return compressedData ? JSON.parse(LZString.decompress(compressedData)) : null;
}
async function loadConfig() {
const response = await fetch('config.json');
const config = await response.json();
// 使用 Promise.all 来并行处理所有文件
const filePromises = config.json_files.map(async file => {
const cachedData = getData(file); // 尝试从 localStorage 获取缓存
if (cachedData) {
return JSON.parse(cachedData); // 如果有缓存,解析并返回
} else {
const res = await fetch(file); // 如果没有缓存,下载文件
const jsonData = await res.json();
storeData(file, JSON.stringify(jsonData)); // 存储到 localStorage
return jsonData; // 返回下载的数据
}
});
jsonData = (await Promise.all(filePromises)).flat(); // 将多个 JSON 文件的数据合并
loadPublicationFilters(jsonData);
loadTableData(jsonData); // 初始加载数据
}
// 加载发表刊物的复选框
function loadPublicationFilters(data) {
const uniquePublications = [...new Set(data.map(item => item.publication))];
const filterContainer = document.getElementById('publicationFilters');
uniquePublications.forEach(publication => {
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.checked = true; // 默认全选
checkbox.value = publication;
checkbox.id = `filter-${publication}`;
checkbox.onchange = filterTable; // 过滤时触发
const label = document.createElement('label');
label.htmlFor = `filter-${publication}`;
label.innerText = publication;
filterContainer.appendChild(checkbox);
filterContainer.appendChild(label);
filterContainer.appendChild(document.createElement('br'));
});
}
// 向表格中填充数据
function loadTableData(data) {
const tableBody = document.getElementById('resultsBody');
tableBody.innerHTML = ""; // 清空现有内容
data.forEach((item, index) => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${index + 1}</td>
<td>${item.title}</td>
<td>${item.abstract}</td>
<td>${item.author}</td>
<td>${item.year}</td>
<td>${item.publication}</td>
<td><a href="${item.link}" target="_blank">${texts[currentLanguage].viewLink}</a></td>
`;
tableBody.appendChild(row);
});
}
// 搜索和筛选功能
function filterTable() {
const titleAbstractInput = document.getElementById('titleAbstractInput').value;
const authorInput = document.getElementById('authorInput').value;
const yearInput = document.getElementById('yearInput').value;
const checkedPublications = [...document.querySelectorAll('#publicationFilters input:checked')]
.map(checkbox => checkbox.value);
const filteredData = jsonData.filter(item => {
const titleMatch = new RegExp(titleAbstractInput, 'i').test(item.title) ||
new RegExp(titleAbstractInput, 'i').test(item.abstract);
const authorMatch = item.author.toLowerCase().includes(authorInput.toLowerCase());
const yearMatch = yearInput ? parseInt(item.year) >= parseInt(yearInput) : true;
const publicationMatch = checkedPublications.includes(item.publication);
return titleMatch && authorMatch && yearMatch && publicationMatch;
});
loadTableData(filteredData);
}
// 全选和全不选功能
function selectAll() {
const checkboxes = document.querySelectorAll('#publicationFilters input[type="checkbox"]');
checkboxes.forEach(checkbox => {
checkbox.checked = true;
});
filterTable(); // 重新筛选
}
function deselectAll() {
const checkboxes = document.querySelectorAll('#publicationFilters input[type="checkbox"]');
checkboxes.forEach(checkbox => {
checkbox.checked = false;
});
filterTable(); // 重新筛选
}
// 初始加载配置和数据
loadConfig();
updateLanguage(); // 更新语言
// 允许输入框通过回车键触发查询
document.getElementById('titleAbstractInput').addEventListener('keydown', function (event) {
if (event.key === 'Enter') {
filterTable();
}
});
document.getElementById('authorInput').addEventListener('keydown', function (event) {
if (event.key === 'Enter') {
filterTable();
}
});
document.getElementById('yearInput').addEventListener('keydown', function (event) {
if (event.key === 'Enter') {
filterTable();
}
});
</script>
</body>
</html>