版本比较
洛谷首页显示At和Cf的比赛
正文
增加 17 行删除 17 行
140 行未改动全部展开14114214314414514614714814952 行未改动20220320420520620720820921018 行未改动2292302312322332342352362372382392402412422432448 行未改动25325425525625725825926026112 行未改动27427527627727827928028128228328428528615 行未改动30230330430530630730830931031131231331431531631731831932049 行未改动3703713723733743753763773783793803813823833843855 行未改动39139239339439539639739839940040140240312 行未改动41641741841942042142242342442542642723 行未改动45145245345445545645745845951 行未改动140 行未改动全部展开function showSettings() {document.getElementById('lg-contest-settings-modal').style.display = 'block';document.getElementById('lg-contest-settings-overlay').style.display = 'block';}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 linkconst 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,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 linkconst 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><span class="lg-small lg-inline-up">${statusHtml}<br>${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 行未改动140 行未改动全部展开14114214314414514614714814952 行未改动20220320420520620720820921018 行未改动2292302312322332342352362372382392402412422432448 行未改动25325425525625725825926026112 行未改动27427527627727827928028128228328428528615 行未改动30230330430530630730830931031131231331431531631731831932049 行未改动3703713723733743753763773783793803813823833843855 行未改动39139239339439539639739839940040140240312 行未改动41641741841942042142242342442542642723 行未改动45145245345445545645745845951 行未改动140 行未改动全部展开function showSettings() {document.getElementById('lg-contest-settings-modal').style.display = 'block';document.getElementById('lg-contest-settings-overlay').style.display = 'block';}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 linkconst 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,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 linkconst 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><span class="lg-small lg-inline-up">${statusHtml}<br>${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 行未改动