版本比较
洛谷首页显示At和Cf的比赛
正文
增加 17 行删除 18 行
9 行未改动101112131414151617123 行未改动全部展开14114214314414614514614714814952 行未改动20220320420520720620720820921018 行未改动2292302312322342332342352362372382392412402412422432448 行未改动25325425525625825725825926026112 行未改动27427527627727927827928028128328228328428528615 行未改动30230330430530730630730830931031231131231331431531731631731831932049 行未改动3703713723733753743753763773783793803823813823833843855 行未改动39139239339439639539639739840039940040140240312 行未改动41641741841942142042142242442342442542642723 行未改动45145245345445645545645745845951 行未改动9 行未改动

::anti-ai{哈哈哈}:::info[代码]```javascript line-numbers// ==UserScript==// @name Luogu Contest Aggregator123 行未改动全部展开
function showSettings() { document.getElementById('lg-contest-settings-modal').style.display = 'block'; document.getElementById('lg-contest-settings-overlay').style.display = 'block'; }10; // 在这里设置最多显示比赛数量 }10; // 在这里设置最多显示比赛数量
// 格式化时间 function formatTimeRemaining(ms) { const seconds = Math.floor(Math.abs(ms) / 1000);52 行未改动 try { const parser = new DOMParser(); const doc = parser.parseFromString(response.responseText, "text/html"); const contests = [];
const parseTable = (tableSelector, status) => { const table = doc.querySelector(tableSelector + " tbody"); if (!table) return; table.querySelectorAll("tr").forEach(tr => {18 行未改动 // AtCoder sometimes has icons before the name, get the last <a> or the one with contest link const contestLink = tds[1].querySelector("a[href^='/contests/']"); const name = contestLink ? contestLink.textContent.trim() : (nameA ? nameA.textContent.trim() : ""); const url = contestLink ? "https://atcoder.jp" + contestLink.getAttribute("href") : (nameA ? "https://atcoder.jp" + nameA.getAttribute("href") : "");
const durationStr = tds[2]?.textContent.trim() || "02:00"; const parts = durationStr.split(":"); let durationMs = 0; if (parts.length === 2) { durationMs = (parseInt(parts[0]) * 3600 + parseInt(parts[1]) * 60) * 1000; }
contests.push({ name: name, url: url, startTime: startTime,8 行未改动 };
parseTable("#contest-table-upcoming", "未开始"); parseTable("#contest-table-active", "进行中");
resolve(contests); } catch (e) { console.error("Failed to parse AtCoder contests", e); resolve([]);12 行未改动
const container = h2.parentElement; const contestSections = container.querySelectorAll("section.am-panel"); console.log("[LuoguContestAggregator] Found potential sections in container:", contestSections.length);
contestSections.forEach((section, index) => { const titleA = section.querySelector("h3 a, .am-panel-title a"); const timeDisplay = section.querySelector(".lg-right, .am-panel-bd span.lg-right");
if (!titleA) { console.log(`[LuoguContestAggregator] Section ${index}: No title found`); return; }15 行未改动
function extractData(section, titleA, timeElement) { const text = timeElement.innerText; const timeMatches = text.match(/\d{2}-\d{2} \d{2}:\d{2}/g);
if (timeMatches && timeMatches.length >= 2) { const year = new Date().getFullYear(); const startTime = new Date(`${year}-${timeMatches[0]}`).getTime(); const endTime = new Date(`${year}-${timeMatches[1]}`).getTime();
if (!isNaN(startTime)) { contests.push({ name: titleA.textContent.trim(), url: new URL(titleA.getAttribute("href"), "https://www.luogu.com.cn").href, startTime, endTime, startTime, endTime, platform: "Luogu", platformUrl: "https://www.luogu.com.cn/", rated: !!section.querySelector(".lg-bg-green"), status: section.querySelector("strong")?.textContent.trim() || "", originalHtml: section.outerHTML49 行未改动 panelClass = "am-panel-danger"; }
const ratedBadge = contest.rated ? `<span class="am-badge am-radius lg-bg-green">Rated</span>` : "";
let platformBadgeStyle = ""; if (contest.platform === "AtCoder") { platformBadgeStyle = `style="background-color: ${settings.atCoderColor};"`; } else if (contest.platform === "Codeforces") { platformBadgeStyle = `style="background-color: ${settings.codeforcesColor};"`; }
// Only show relevant platform link const platformLink = `<a class="colored" href="${contest.platformUrl}" target="_blank">${contest.platform} 官网</a>`;
return `5 行未改动 </h3> </header> <div class="am-panel-bd"> <span class="lg-small lg-inline-up"> <span class="am-badge am-radius" ${platformBadgeStyle}>${contest.platform}</span> <span class="am-badge am-radius" ${platformBadgeStyle}>${contest.platform}</span> </span> <span class="lg-small lg-inline-up"> ${statusHtml}<br> ${platformLink} ${platformLink} </span> <span class="lg-small lg-inline-up lg-right lg-md-hide"> ${formatDateToMMddHHmm(new Date(contest.startTime))}<br> ${formatDateToMMddHHmm(new Date(contest.endTime))}12 行未改动 if (isInjected) { console.log("[LuoguContestAggregator] Already injected, skipping."); return; }
const h2 = Array.from(document.querySelectorAll("h2")).find(h => h.textContent.includes("近期比赛")); const luoguContainer = h2 ? h2.parentElement : null;
if (!luoguContainer || !h2) return;
// 注入设置按钮 if (!document.getElementById('lg-contest-settings-btn')) {23 行未改动 fetchPromises.push(fetchCFContests().then(res => { console.log("[LuoguContestAggregator] CF fetched:", res.length); return res; })); } else { fetchPromises.push(Promise.resolve([])); }
if (settings.showAtCoder) { fetchPromises.push(fetchAtCoderContests().then(res => { console.log("[LuoguContestAggregator] AtCoder fetched:", res.length); return res; })); } else { fetchPromises.push(Promise.resolve([]));51 行未改动