Skip to content

Commit b19a9d1

Browse files
Update scripts.js
1 parent cc36c14 commit b19a9d1

File tree

1 file changed

+114
-100
lines changed

1 file changed

+114
-100
lines changed

scripts.js

Lines changed: 114 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ function applyModelFilters() {
8888
// 存储每个表格的原始顺序
8989
let originalOrderMap = {};
9090
let currentSortState = {}; // 记录每张表的当前排序状态
91+
const columnOrder = [
92+
"Model", "Rank", "Average", "Date",
93+
"Fact_ACC", "Fact_ROUGE_L",
94+
"Reason_ACC", "Reason_ROUGE_L",
95+
"Summarize_ACC", "Summarize_Cov",
96+
"Creative_ACC", "Creative_FS", "Creative_Cov",
97+
"Link"
98+
];
99+
91100

92101
function loadCSVData(csvFile, tableId, tbodyId) {
93102
Papa.parse(csvFile, {
@@ -103,21 +112,20 @@ function loadCSVData(csvFile, tableId, tbodyId) {
103112
data.forEach(row => {
104113
const tr = document.createElement("tr");
105114

106-
for (const key in row) {
115+
columnOrder.forEach(col => {
107116
const td = document.createElement("td");
108-
if (key === "Link") {
109-
td.innerHTML = `<p style="text-align: center;"><a href="${row[key]}" target="_blank">🔗</a></p>`;
117+
if (col === "Link") {
118+
td.innerHTML = `<p style="text-align: center;"><a href="${row[col]}" target="_blank">🔗</a></p>`;
110119
} else {
111-
td.innerHTML = `<p class="number">${row[key]}</p>`;
120+
td.innerHTML = `<p class="number">${row[col]}</p>`;
112121
}
113122
tr.appendChild(td);
114-
}
123+
});
115124

116125
originalRows.push(tr.cloneNode(true));
117126
tbody.appendChild(tr);
118127
});
119128

120-
// 保存原始顺序
121129
originalOrderMap[tbodyId] = originalRows;
122130
currentSortState[tableId] = { column: null, direction: "none" };
123131

@@ -128,13 +136,14 @@ function loadCSVData(csvFile, tableId, tbodyId) {
128136

129137
function attachSortEvents(tableId, tbodyId) {
130138
const table = document.getElementById(tableId);
131-
const headers = table.querySelectorAll("thead th");
139+
const headers = table.querySelectorAll("thead th[data-sort]");
132140

133-
headers.forEach((header, index) => {
134-
if (!header.hasAttribute("data-sort")) return;
141+
headers.forEach(header => {
142+
const colIndex = parseInt(header.getAttribute("data-col"));
143+
if (isNaN(colIndex)) return;
135144

136145
header.style.cursor = "pointer";
137-
header.addEventListener("click", () => sortTable(index, header, tableId, tbodyId));
146+
header.addEventListener("click", () => sortTable(colIndex, header, tableId, tbodyId));
138147
});
139148
}
140149

@@ -182,20 +191,25 @@ function sortTable(columnIndex, headerEl, tableId, tbodyId) {
182191
}
183192

184193
rows.sort((a, b) => {
185-
let valA = a.children[columnIndex]?.innerText.trim() || "";
186-
let valB = b.children[columnIndex]?.innerText.trim() || "";
194+
let valA = a.children[columnIndex]?.querySelector("p")?.innerText.trim() || "";
195+
let valB = b.children[columnIndex]?.querySelector("p")?.innerText.trim() || "";
196+
197+
const dateRegex = /^\d{4}-\d{2}$/;
198+
const isDate = dateRegex.test(valA) && dateRegex.test(valB);
199+
200+
if (isDate) {
201+
return newState === "asc" ? valA.localeCompare(valB) : valB.localeCompare(valA);
202+
}
187203

188-
let numA = parseFloat(valA);
189-
let numB = parseFloat(valB);
190-
let isNumeric = !isNaN(numA) && !isNaN(numB);
204+
const numA = parseFloat(valA);
205+
const numB = parseFloat(valB);
191206

207+
const isNumeric = !isNaN(numA) && !isNaN(numB);
192208
if (isNumeric) {
193209
return newState === "asc" ? numA - numB : numB - numA;
194-
} else {
195-
return newState === "asc"
196-
? valA.localeCompare(valB)
197-
: valB.localeCompare(valA);
198210
}
211+
212+
return newState === "asc" ? valA.localeCompare(valB) : valB.localeCompare(valA);
199213
});
200214

201215
tbody.innerHTML = "";
@@ -282,99 +296,99 @@ function openLeaderboard(leaderboard, updateHash = true) {
282296

283297

284298
function openSection(leaderboard) {
285-
var tabcontent = document.getElementsByClassName("tabcontent");
286-
for (var i = 0; i < tabcontent.length; i++) {
287-
tabcontent[i].style.display = "none";
288-
}
299+
var tabcontent = document.getElementsByClassName("tabcontent");
300+
for (var i = 0; i < tabcontent.length; i++) {
301+
tabcontent[i].style.display = "none";
302+
}
289303

290-
var tablinks = document.getElementsByClassName("sectionlinks");
291-
for (var i = 0; i < tablinks.length; i++) {
292-
tablinks[i].classList.remove("active");
293-
}
304+
var tablinks = document.getElementsByClassName("sectionlinks");
305+
for (var i = 0; i < tablinks.length; i++) {
306+
tablinks[i].classList.remove("active");
307+
}
294308

295-
document.getElementById(`sections-${leaderboard}`).style.display = "block";
296-
document.querySelector(`[data-sections="${leaderboard}"]`).classList.add("active");
309+
document.getElementById(`sections-${leaderboard}`).style.display = "block";
310+
document.querySelector(`[data-sections="${leaderboard}"]`).classList.add("active");
297311

298-
// Update URL hash if requested
299-
if (updateHash) {
300-
window.location.hash = leaderboard.toLowerCase();
301-
}
312+
// Update URL hash if requested
313+
if (updateHash) {
314+
window.location.hash = leaderboard.toLowerCase();
302315
}
316+
}
303317

304318
function preCopy() {
305-
//执行复制
306-
let btn = document.querySelector(".btn-pre-copy");
307-
let pre = document.querySelector("#copy-content");
308-
//为了实现复制功能。新增一个临时的textarea节点。使用他来复制内容
309-
let temp = document.createElement("textarea");
310-
temp.textContent = pre.textContent;
311-
pre.appendChild(temp);
312-
temp.select();
313-
document.execCommand("Copy");
314-
temp.remove();
315-
//修改按钮名
316-
btn.textContent = "Copied";
317-
//一定时间后吧按钮名改回来
318-
setTimeout(() => {
319-
btn.textContent = "Copy";
320-
}, 1500);
321-
}
319+
//执行复制
320+
let btn = document.querySelector(".btn-pre-copy");
321+
let pre = document.querySelector("#copy-content");
322+
//为了实现复制功能。新增一个临时的textarea节点。使用他来复制内容
323+
let temp = document.createElement("textarea");
324+
temp.textContent = pre.textContent;
325+
pre.appendChild(temp);
326+
temp.select();
327+
document.execCommand("Copy");
328+
temp.remove();
329+
//修改按钮名
330+
btn.textContent = "Copied";
331+
//一定时间后吧按钮名改回来
332+
setTimeout(() => {
333+
btn.textContent = "Copy";
334+
}, 1500);
335+
}
322336

323337
document.addEventListener('DOMContentLoaded', function () {
324-
var tabs = document.querySelectorAll('.tablinks:not(.sectionlinks)');
325-
tabs.forEach(function (tab) {
326-
tab.addEventListener('click', function (event) {
327-
openLeaderboard(this.getAttribute('data-leaderboard'));
328-
// Scroll to leaderboard section after a slight delay
329-
setTimeout(() => {
330-
document.querySelector('.leaderboard').scrollIntoView({ behavior: 'smooth' });
331-
}, 100);
332-
});
333-
});
334-
335-
// Check URL hash for tab selection
336-
const hash = window.location.hash.slice(1).toLowerCase();
337-
if (hash === 'main' || hash === 'mm' || hash === 'text') {
338-
const tabName = hash.charAt(0).toUpperCase() + hash.slice(1);
339-
openLeaderboard(tabName, false);
338+
var tabs = document.querySelectorAll('.tablinks:not(.sectionlinks)');
339+
tabs.forEach(function (tab) {
340+
tab.addEventListener('click', function (event) {
341+
openLeaderboard(this.getAttribute('data-leaderboard'));
340342
// Scroll to leaderboard section after a slight delay
341343
setTimeout(() => {
342344
document.querySelector('.leaderboard').scrollIntoView({ behavior: 'smooth' });
343345
}, 100);
344-
} else if (hash === 'about') {
345-
setTimeout(() => {
346-
document.querySelector('#about').scrollIntoView({ behavior: 'smooth' });
347-
}, 100);
348-
} else if (hash === 'news') {
349-
setTimeout(() => {
350-
document.querySelector('#news').scrollIntoView({ behavior: 'smooth' });
351-
}, 100);
352-
} else if (hash === 'resources') {
353-
setTimeout(() => {
354-
document.querySelector('#resources').scrollIntoView({ behavior: 'smooth' });
355-
}, 100);
356-
} else if (hash === 'examples') {
357-
setTimeout(() => {
358-
document.querySelector('#examples').scrollIntoView({ behavior: 'smooth' });
359-
}, 100);
360-
} else {
361-
// Open the 'lite' leaderboard by default if no hash
362-
openLeaderboard('story,medical', false);
363-
}
346+
});
364347
});
365348

349+
// Check URL hash for tab selection
350+
const hash = window.location.hash.slice(1).toLowerCase();
351+
if (hash === 'main' || hash === 'mm' || hash === 'text') {
352+
const tabName = hash.charAt(0).toUpperCase() + hash.slice(1);
353+
openLeaderboard(tabName, false);
354+
// Scroll to leaderboard section after a slight delay
355+
setTimeout(() => {
356+
document.querySelector('.leaderboard').scrollIntoView({ behavior: 'smooth' });
357+
}, 100);
358+
} else if (hash === 'about') {
359+
setTimeout(() => {
360+
document.querySelector('#about').scrollIntoView({ behavior: 'smooth' });
361+
}, 100);
362+
} else if (hash === 'news') {
363+
setTimeout(() => {
364+
document.querySelector('#news').scrollIntoView({ behavior: 'smooth' });
365+
}, 100);
366+
} else if (hash === 'resources') {
367+
setTimeout(() => {
368+
document.querySelector('#resources').scrollIntoView({ behavior: 'smooth' });
369+
}, 100);
370+
} else if (hash === 'examples') {
371+
setTimeout(() => {
372+
document.querySelector('#examples').scrollIntoView({ behavior: 'smooth' });
373+
}, 100);
374+
} else {
375+
// Open the 'lite' leaderboard by default if no hash
376+
openLeaderboard('story,medical', false);
377+
}
378+
});
379+
366380
const sidebarLinks = document.querySelectorAll('#sidebar a');
367-
const sections = document.querySelectorAll('.link-section');
368-
window.addEventListener('scroll', () => {
369-
const scrollPosition = window.scrollY;
370-
371-
sections.forEach((section, index) => {
372-
const sectionTop = section.offsetTop;
373-
const sectionHeight = section.offsetHeight;
374-
375-
if (scrollPosition >= sectionTop && scrollPosition < sectionTop + sectionHeight) {
376-
sidebarLinks.forEach(link => link.classList.remove('active'));
377-
sidebarLinks[index].classList.add('active');
378-
}
379-
});
380-
});
381+
const sections = document.querySelectorAll('.link-section');
382+
window.addEventListener('scroll', () => {
383+
const scrollPosition = window.scrollY;
384+
385+
sections.forEach((section, index) => {
386+
const sectionTop = section.offsetTop;
387+
const sectionHeight = section.offsetHeight;
388+
389+
if (scrollPosition >= sectionTop && scrollPosition < sectionTop + sectionHeight) {
390+
sidebarLinks.forEach(link => link.classList.remove('active'));
391+
sidebarLinks[index].classList.add('active');
392+
}
393+
});
394+
});

0 commit comments

Comments
 (0)