// ==UserScript== // @name Luogu MC Achievements // @namespace https://www.luogu.com.cn/ // @version 1.2 // @icon https://cdn.xqyhcc.qzz.io/img/luogumc.png // @author cgy20140502&cyx20131003 // @description AC 就出现 MC 成就 // @match https://www.luogu.com.cn/* // @grant none // @run-at document-start // @license MIT // ==/UserScript== (function () { 'use strict'; const IMG_URL = 'https://www.mcmod.cn/pages/tools/achievements/images/achievements/0_QpjUsXuG.png';//在这里输入你自定义图片地址 const imgPreload = new Image(); imgPreload.src = IMG_URL; const style = document.createElement('style'); style.textContent = ` #mc-achv { position: fixed !important; top: 16px !important; right: 16px !important; z-index: 2147483647 !important; width: 320px !important; margin: 0 !important; padding: 0 !important; transform: translateX(360px) !important; opacity: 0 !important; transition: transform 0.25s cubic-bezier(0.22,1,0.36,1), opacity 0.25s cubic-bezier(0.22,1,0.36,1) !important; pointer-events: none !important; box-sizing: border-box !important; background-color: #ffffff !important; border-radius: 6px !important; overflow: hidden !important; box-shadow: 0 4px 12px rgba(0,0,0,0.5) !important; } #mc-achv.show { transform: translateX(0) !important; opacity: 1 !important; } #mc-achv.hide { transition: transform 0.15s ease-in, opacity 0.15s ease-in !important; transform: translateX(400px) !important; opacity: 0 !important; } #mc-achv img { display: block !important; width: 100% !important; height: auto !important; max-width: none !important; max-height: none !important; image-rendering: pixelated !important; } `; (document.head || document.documentElement).appendChild(style); let isShown = false; let currentUrl = location.href; function showToast() { if (isShown) return; isShown = true; const el = document.createElement('div'); el.id = 'mc-achv'; el.innerHTML = `AC`; document.documentElement.appendChild(el); void el.offsetWidth; el.classList.add('show'); setTimeout(() => { el.classList.remove('show'); el.classList.add('hide'); setTimeout(() => el.remove(), 150); }, 5000); } function checkAC() { if (isShown) return; // 严格匹配记录详情页 URL if (!/^\/record\/\d+\/?$/.test(window.location.pathname)) return; if (!document.body) return; const text = document.body.innerText || ''; // 拦截预测试 if (text.includes('Pretests')) return; // 【核心修复】精准抓取右侧面板的状态,不再管满分是 100 还是 10 // 逻辑:页面里必须是纯正的 "Accepted",绝对不能带有 "Un",且不能有其他错误提示 // 1. 如果页面上出现了 Unaccepted、WA 等字眼,一票否决 if (text.includes('Unaccepted') || text.includes('Partially Correct')) return; // 2. 使用正则匹配独立的单词 Accepted (防止被误伤) // 因为洛谷的评测状态里有 "Accepted" 就代表全过了 if (!/\bAccepted\b/.test(text)) return; // 时间校验(15秒内才弹) const timeMatch = text.match(/(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/); if (timeMatch) { const submitTimeStr = timeMatch[1].replace(/-/g, '/'); const submitTime = new Date(submitTimeStr).getTime(); const now = Date.now(); if (now - submitTime <= 15000) { showToast(); } } } let throttleTimer = null; const observer = new MutationObserver(() => { if (location.href !== currentUrl) { currentUrl = location.href; isShown = false; const oldEl = document.getElementById('mc-achv'); if (oldEl) oldEl.remove(); } if (!throttleTimer) { throttleTimer = setTimeout(() => { checkAC(); throttleTimer = null; }, 50); } }); if (document.body) { observer.observe(document.body, { childList: true, subtree: true, characterData: true }); } else { const initObserver = new MutationObserver(() => { if (document.body) { observer.observe(document.body, { childList: true, subtree: true, characterData: true }); initObserver.disconnect(); checkAC(); } }); initObserver.observe(document.documentElement, { childList: true, subtree: true }); } })();