// ==UserScript== // @name GenGen-RMJ // @icon https://cdn.luogu.com.cn/upload/image_hosting/3s3czya0.png // @namespace https://gengen.qzz.io/ // @version 3.1.2.10 // @description GenGen RMJ 完整版本 // @author GenGen 队 // @run-at document-start // @match https://www.luogu.com.cn/* // @match https://atcoder.jp/contests/*/submit?RMJ=1 // @match https://codeforces.com/problemset/submit/* // @match https://codeforces.com/problemset/status?my=on // @require https://cdn.bootcdn.net/ajax/libs/html2canvas/1.4.1/html2canvas.js // @require https://cdn.bootcdn.net/ajax/libs/sweetalert2/11.23.0/sweetalert2.all.js // @require https://scriptcat.org/scripts/code/5095/GenGen-CF-RMJ-JL.user.js // @require https://scriptcat.org/scripts/code/5096/GenGen-Cloudflare-RMJ.user.js // @require https://scriptcat.org/scripts/code/5093/GenGen-AT-RMJ-JL.user.js // @require https://scriptcat.org/scripts/code/5094/GenGen-CF-RMJ.user.js // @grant GM_addStyle // @grant GM_xmlhttpRequest // @grant GM_setValue // @grant GM_getValue // @grant unsafeWindow // ==/UserScript== (function () { 'use strict'; const VERSION = '3.1.2.10'; const BUILD_DATE = '2026/2/1'; const UPDATE_INTERVAL = 500; /* ---------------- 工具函数 ---------------- */ const ready = fn => document.readyState === 'loading' ? document.addEventListener('DOMContentLoaded', fn) : fn(); const wait = (sel, cb) => { const t = setInterval(() => { const el = document.querySelector(sel); if (el) { clearInterval(t); cb(el); } }, 100); }; /* ---------------- 样式注入 ---------------- */ GM_addStyle(` #gengen-panel { position: fixed; top: 60px; right: 300px; width: 400px; background: white; border: 1px solid #e0e0e0; border-radius: 4px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 10000; padding: 16px; font-size: 16px; display: none; flex-direction: column; gap: 12px; } #gengen-panel h3 { margin: 0 0 8px 0; font-size: 18px; color: #333; border-bottom: 1px solid #eee; padding-bottom: 6px; } #gengen-panel p { margin: 0; line-height: 1.5; } #gengen-panel a { color: #1a73e8; text-decoration: none; } #gengen-panel a:hover { text-decoration: underline; } .gengen-account-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; } .gengen-account-status { font-weight: bold; color: #2e7d32; } .gengen-not-bound { color: #d32f2f; } .gengen-bind-btn { font-size: 12px; padding: 2px 6px; background: #f1f8ff; border: 1px solid #1a73e8; border-radius: 4px; cursor: pointer; color: #1a73e8; } .gengen-bind-btn:hover { background: #e8f0fe; } #gengen-icon { cursor: pointer; width: 24px; height: 24px; margin-right: 12px; } .gengen-status-wrapper { display: none; justify-content: center; align-items: center; min-height: 24px; width: 100%; } .gengen-managed .gengen-original-content { display: none !important; } .gengen-managed .gengen-status-wrapper { display: flex !important; } `); /* ---------------- 获取账号信息 ---------------- */ async function getAtCoderUser() { return new Promise((resolve) => { GM_xmlhttpRequest({ method: 'GET', url: 'https://atcoder.jp/', onload: res => { if (res.status !== 200) return resolve(null); try { const parser = new DOMParser(); const doc = parser.parseFromString(res.responseText, 'text/html'); const userEl = doc.querySelector("#navbar-collapse > ul.nav.navbar-nav.navbar-right > li:nth-child(2) > a"); if (!userEl || userEl.textContent.trim() === 'Sign Up') resolve(null); else resolve(userEl.textContent.trim()); } catch { resolve(null); } }, onerror: () => resolve(null), timeout: 8000 }); }); } function getCFHandle(callback) { GM_xmlhttpRequest({ method: 'GET', url: 'https://codeforces.com/', withCredentials: true, onload: function(res) { if (res.status !== 200) return callback(null); try { const doc = new DOMParser().parseFromString(res.responseText, 'text/html'); const userLink = doc.querySelector('#header > div.lang-chooser > div:nth-child(2) > a:nth-child(1)'); if (!userLink) return callback(null); const text = userLink.textContent.trim(); if (text === 'Enter') callback(null); else callback(text); } catch (e) { callback(null); } }, onerror: () => callback(null), timeout: 8000 }); } /* ---------------- 题目状态图标渲染 ---------------- */ function getOkIcon() { return ``; } function getErrorIcon() { return ``; } function getNoIcon() { return ``; } // 缓存映射 let cfSubmissionMap = new Map(); let atSubmissionMap = new Map(); let lastCFRaw = ''; let lastATRaw = ''; function refreshCache() { try { const cfRaw = GM_getValue('cf-submissions-cache', '[]'); const atRaw = GM_getValue('at-submissions-cache', '[]'); if (cfRaw !== lastCFRaw) { lastCFRaw = cfRaw; cfSubmissionMap = new Map(); if (cfRaw && cfRaw !== '[]') { const cfCache = JSON.parse(cfRaw); cfCache.forEach(sub => { if (!sub?.taskDisplay) return; const match = sub.taskDisplay.match(/CF[A-Z0-9]+/i); if (match) { const pid = match[0].toUpperCase(); if (!cfSubmissionMap.has(pid)) { cfSubmissionMap.set(pid, sub.verdict || null); } } }); } } if (atRaw !== lastATRaw) { lastATRaw = atRaw; atSubmissionMap = new Map(); if (atRaw && atRaw !== '[]') { const atCache = JSON.parse(atRaw); atCache.forEach(sub => { if (sub?.taskKey) { const key = sub.taskKey.toLowerCase(); if (!atSubmissionMap.has(key)) { atSubmissionMap.set(key, sub.status || null); } } }); } } } catch (e) {} } function initGenGenContainer(cell) { if (cell.dataset.gengenInitialized) return; const originalWrapper = document.createElement('div'); originalWrapper.className = 'gengen-original-content'; originalWrapper.innerHTML = cell.innerHTML; const statusWrapper = document.createElement('div'); statusWrapper.className = 'gengen-status-wrapper'; statusWrapper.innerHTML = getNoIcon(); cell.innerHTML = ''; cell.appendChild(originalWrapper); cell.appendChild(statusWrapper); cell.dataset.gengenInitialized = '1'; cell.dataset.gengenStatus = 'none'; } function updateRowStatus(row) { const cells = row.children; if (cells.length < 2) return false; const firstCell = cells[0]; const secondCell = cells[1]; const pidMatch = secondCell.textContent.trim().match(/^(\S+)/); if (!pidMatch) { if (firstCell.dataset.gengenInitialized) { firstCell.classList.remove('gengen-managed'); } return false; } const pid = pidMatch[1]; let isCFAT = false; let newStatus = 'none'; let iconHTML = getNoIcon(); if (pid.startsWith('CF')) { isCFAT = true; const verdict = cfSubmissionMap.get(pid.toUpperCase()); if (verdict === 'OK') { iconHTML = getOkIcon(); newStatus = 'AC'; } else if (verdict) { iconHTML = getErrorIcon(); newStatus = 'WA'; } } else if (pid.startsWith('AT_')) { isCFAT = true; const taskKey = pid.substring(3).toLowerCase(); const status = atSubmissionMap.get(taskKey); if (status === 'AC') { iconHTML = getOkIcon(); newStatus = 'AC'; } else if (status) { iconHTML = getErrorIcon(); newStatus = 'WA'; } } if (!firstCell.dataset.gengenInitialized) { initGenGenContainer(firstCell); } const oldStatus = firstCell.dataset.gengenStatus; if (isCFAT) { const statusWrapper = firstCell.querySelector('.gengen-status-wrapper'); if (statusWrapper) statusWrapper.innerHTML = iconHTML; firstCell.classList.add('gengen-managed'); firstCell.dataset.gengenStatus = newStatus; return oldStatus !== newStatus; } else { firstCell.classList.remove('gengen-managed'); firstCell.dataset.gengenStatus = 'none'; return oldStatus !== 'none'; } } let updateIntervalId = null; function startStatusUpdateLoop() { if (updateIntervalId) clearInterval(updateIntervalId); updateIntervalId = setInterval(() => { refreshCache(); const rows = document.querySelectorAll('.row'); rows.forEach(updateRowStatus); }, UPDATE_INTERVAL); } function stopStatusUpdateLoop() { if (updateIntervalId) { clearInterval(updateIntervalId); updateIntervalId = null; } } /* ---------------- 创建管理面板 ---------------- */ function createPanel() { if (document.getElementById('gengen-panel')) return; const panel = document.createElement('div'); panel.id = 'gengen-panel'; panel.innerHTML = `
版本:${VERSION} (${BUILD_DATE})
反馈:私信开发者
新特性:支持 CodeForces / ATcoder
工单进度:点击查看