正文
增加 822 行删除 3065 行
1234567894 行未改动14151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628474 行未改动2852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929206 行未改动29272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273[$\textup{Cnblogs link.}$](https://www.cnblogs.com/Fall-wendywan/p/19683545)这个人平时很不自觉,喜欢水谷但不喜欢上什么其它网站。于是她参考了[这篇文章](https://www.luogu.com.cn/article/ysrs7l49),花了~~一个晚上~~将近两周调了十几版,最终用 AI 做出了这个插件。直接粘贴到篡改猴里面保存就能用了。功能介绍:4 行未改动+ 当在专注时点击其他洛谷网页(除题目、提交记录及剪切板外)自动跳转到计划中第一个题目;+ 支持用本地存储倒计时进度,若当前有进度将自动继续走时(该功能容易出问题)。+ 支持勾选是否允许题解查看,否时默认为自动跳转。那就上代码。:::success[$\textup{V1 Code.}$]```// ==UserScript==// @name 洛谷强力学术pro// @namespace http://tampermonkey.net/// @version 10.12// @author wendywan// @icon https://cdn.luogu.com.cn/upload/image_hosting/psd5a03h.png// @match *://*/*// @grant none// @license MIT// @run-at document-start// ==/UserScript==(function() {'use strict';const STORAGE_KEY_PID = "luogu_study_plan_pids";const STORAGE_KEY_SOLUTION = "luogu_study_plan_solution";const STORAGE_KEY_FOCUS_ACTIVE = "luogu_focus_active";const STORAGE_KEY_FOCUS_END = "luogu_focus_end_time";const STORAGE_KEY_FOCUS_DURATION = "luogu_focus_duration";const STORAGE_KEY_FOCUS_COLOR = "luogu_focus_color";const STORAGE_KEY_FOCUS_POS = "luogu_focus_position";const STORAGE_KEY_FOCUS_REMAINING = "luogu_focus_remaining";const STORAGE_KEY_FOCUS_STATE = "luogu_focus_state";const STORAGE_KEY_REST_DURATION = "luogu_rest_duration";const STORAGE_KEY_CURRENT_MODE = "luogu_focus_current_mode";const DEFAULT_WORK_DURATION = 25;const DEFAULT_REST_DURATION = 5;const DEFAULT_COLOR = "#ff6b6b";const DEFAULT_POSITION = { x: 20, y: 100 };const DEFAULT_SIZE = { width: 120, height: 100 };const MAX_PIDS = 6;function getSavePids() {try {const pids = JSON.parse(localStorage.getItem(STORAGE_KEY_PID)) || [];return pids.filter(pid => pid.trim() !== '');} catch {return [];}}function savePids(pids) {localStorage.setItem(STORAGE_KEY_PID, JSON.stringify(pids));}function removePid(pid) {const pids = getSavePids();const index = pids.indexOf(pid);if (index !== -1) {pids.splice(index, 1);savePids(pids);return true;}return false;}function getSolutionStatus() {return localStorage.getItem(STORAGE_KEY_SOLUTION) !== 'false';}function saveSolutionStatus(status) {localStorage.setItem(STORAGE_KEY_SOLUTION, status);}function isFocusActive() {const active = localStorage.getItem(STORAGE_KEY_FOCUS_ACTIVE) === 'true';if (!active) return false;// 修复:暂停状态下不检查结束时间,避免刷新时重置const state = localStorage.getItem(STORAGE_KEY_FOCUS_STATE);if (state === 'paused') {return true;}const endTime = parseInt(localStorage.getItem(STORAGE_KEY_FOCUS_END) || '0');const now = Date.now();if (active && now >= endTime) {endFocusMode();return false;}return active;}function startFocusMode(durationMinutes, isWorkMode) {const endTime = Date.now() + durationMinutes * 60 * 1000;localStorage.setItem(STORAGE_KEY_FOCUS_ACTIVE, 'true');localStorage.setItem(STORAGE_KEY_FOCUS_END, endTime.toString());if (isWorkMode) {localStorage.setItem(STORAGE_KEY_FOCUS_DURATION, durationMinutes.toString());}localStorage.setItem(STORAGE_KEY_FOCUS_STATE, 'running');localStorage.removeItem(STORAGE_KEY_FOCUS_REMAINING);}function pauseFocusMode(remainingSeconds) {localStorage.setItem(STORAGE_KEY_FOCUS_STATE, 'paused');localStorage.setItem(STORAGE_KEY_FOCUS_REMAINING, remainingSeconds.toString());localStorage.removeItem(STORAGE_KEY_FOCUS_END);}function endFocusMode() {localStorage.removeItem(STORAGE_KEY_FOCUS_ACTIVE);localStorage.removeItem(STORAGE_KEY_FOCUS_END);localStorage.removeItem(STORAGE_KEY_FOCUS_STATE);localStorage.removeItem(STORAGE_KEY_FOCUS_REMAINING);localStorage.removeItem(STORAGE_KEY_CURRENT_MODE);}function getWorkDuration() {return parseInt(localStorage.getItem(STORAGE_KEY_FOCUS_DURATION) || DEFAULT_WORK_DURATION);}function getRestDuration() {return parseInt(localStorage.getItem(STORAGE_KEY_REST_DURATION) || DEFAULT_REST_DURATION);}function saveDurations(work, rest) {localStorage.setItem(STORAGE_KEY_FOCUS_DURATION, work.toString());localStorage.setItem(STORAGE_KEY_REST_DURATION, rest.toString());}function getFocusColor() {return localStorage.getItem(STORAGE_KEY_FOCUS_COLOR) || DEFAULT_COLOR;}function saveFocusColor(color) {localStorage.setItem(STORAGE_KEY_FOCUS_COLOR, color);}function getFocusPosition() {try {return JSON.parse(localStorage.getItem(STORAGE_KEY_FOCUS_POS) || JSON.stringify(DEFAULT_POSITION));} catch {return DEFAULT_POSITION;}}function saveFocusPosition(pos) {localStorage.setItem(STORAGE_KEY_FOCUS_POS, JSON.stringify(pos));}function getRedirectUrl() {const pids = getSavePids();return pids.length > 0? `https://www.luogu.com.cn/problem/${pids[0]}`: 'https://www.luogu.com.cn/problem/list';}function shouldAllow() {const currentURL = window.location.href;const isLuoguDomain = /^(https?:\/\/)?(www\.)?luogu\.com\.cn/i.test(currentURL);if (!isLuoguDomain) return true;if (!isFocusActive()) return true;// 修复:休息模式下允许访问所有页面const currentMode = localStorage.getItem(STORAGE_KEY_CURRENT_MODE);if (currentMode === 'rest') {return true;}const path = window.location.pathname.toLowerCase();return (path.startsWith('/problem/') ||path.startsWith('/paste') ||path.startsWith('/paste/') ||path.startsWith('/record/'));}function blockSolutionAccess() {if (!/\/problem\/solution\//i.test(window.location.pathname)) {return false;}if (!getSolutionStatus()) {window.location.replace(getRedirectUrl());return true;}return false;}function monitorSolutionElements() {if (!getSolutionStatus()) {const observer = new MutationObserver((mutations) => {mutations.forEach(mutation => {mutation.addedNodes.forEach(node => {if (node.nodeType !== 1) return;const selectors = ['a[href*="/problem/solution/"]','[class*="solution"]','[class*="answer"]'];try {node.querySelectorAll(selectors.join(',')).forEach(el => {if ((el.textContent && el.textContent.includes('题解')) ||(el.href && el.href.includes('/problem/solution/'))) {el.style.display = 'none !important';el.style.visibility = 'hidden !important';el.style.height = '0 !important';el.style.overflow = 'hidden !important';}});} catch (e) {}});});});observer.observe(document.body, { childList: true, subtree: true });}}if (blockSolutionAccess()) return;if (isFocusActive() && !shouldAllow()) {window.location.replace(getRedirectUrl());return;}function createPomodoroWidget() {if (!/^(https?:\/\/)?(www\.)?luogu\.com\.cn/i.test(window.location.href)) return;const workDuration = getWorkDuration();const restDuration = getRestDuration();const config = {workDuration: workDuration,restDuration: restDuration,color: getFocusColor(),position: getFocusPosition()};const style = document.createElement('style');style.textContent = `#luogu-pomodoro-widget {position: fixed;z-index: 99999;border-radius: 10px;box-shadow: 0 2px 10px rgba(0,0,0,0.15);overflow: hidden;font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", sans-serif;user-select: none;width: ${DEFAULT_SIZE.width}px;height: ${DEFAULT_SIZE.height}px;background: white;border: 1px solid #e0e0e0;cursor: move;}#luogu-pomodoro-widget:hover {box-shadow: 0 3px 15px rgba(0,0,0,0.2);}#luogu-pomodoro-time {font-size: 20px;font-weight: bold;text-align: center;color: #333;padding: 12px 0;height: 40px;display: flex;align-items: center;justify-content: center;}#luogu-pomodoro-progress {height: 4px;background: #f0f0f0;border-radius: 2px;margin: 4px 8px;overflow: hidden;}#luogu-pomodoro-progress-bar {height: 100%;width: 0%;background: ${config.color};border-radius: 2px;transition: width 0.5s ease;}#luogu-pomodoro-controls {display: flex;justify-content: center;gap: 6px;padding: 6px 0;background: #f8f9fa;border-top: 1px solid #eee;}.pomodoro-btn {width: 48%;height: 22px;border: none;border-radius: 3px;font-size: 11px;font-weight: 500;cursor: pointer;transition: all 0.2s;user-select: none;text-align: center;line-height: 22px;color: #333;}.pomodoro-btn:active {transform: scale(0.95);}.pomodoro-btn.start {background: #e8f5e9;color: #2e7d32;}.pomodoro-btn.pause {background: #fff8e1;color: #ff8f00;}.pomodoro-btn.stop {background: #ffebee;color: #c62828;}.pomodoro-btn.start:disabled,.pomodoro-btn.pause:disabled {opacity: 0.6;cursor: not-allowed;transform: none !important;}#luogu-pomodoro-settings {position: absolute;top: 6px;right: 6px;width: 18px;height: 18px;border-radius: 50%;background: #000;color: white;display: flex;align-items: center;justify-content: center;font-size: 12px;cursor: pointer;z-index: 10;}#luogu-pomodoro-settings:hover {background: #333;transform: scale(1.1);}`;document.head.appendChild(style);const widget = document.createElement('div');widget.id = 'luogu-pomodoro-widget';widget.style.left = `${config.position.x}px`;widget.style.top = `${config.position.y}px`;widget.innerHTML = `<div id="luogu-pomodoro-time">25:00</div><div id="luogu-pomodoro-progress"><div id="luogu-pomodoro-progress-bar"></div></div><div id="luogu-pomodoro-controls"><button class="pomodoro-btn start">开始</button><button class="pomodoro-btn stop">结束</button></div><div id="luogu-pomodoro-settings">⚙</div>`;document.body.appendChild(widget);const settingsBtn = widget.querySelector('#luogu-pomodoro-settings');settingsBtn.onclick = (e) => {e.stopPropagation();createSettingUI();};let timer = null;let remainingTime = workDuration * 60;let currentMode = 'work';let isResuming = false;let autoStart = false;const savedMode = localStorage.getItem(STORAGE_KEY_CURRENT_MODE);if (savedMode === 'rest') {currentMode = 'rest';remainingTime = restDuration * 60;}const timeDisplay = widget.querySelector('#luogu-pomodoro-time');const progressBar = widget.querySelector('#luogu-pomodoro-progress-bar');const startBtn = widget.querySelector('.pomodoro-btn.start');const stopBtn = widget.querySelector('.pomodoro-btn.stop');// 修复:统一状态恢复逻辑,支持休息模式const savedState = localStorage.getItem(STORAGE_KEY_FOCUS_STATE);const savedRemaining = parseInt(localStorage.getItem(STORAGE_KEY_FOCUS_REMAINING) || '0');const endTime = parseInt(localStorage.getItem(STORAGE_KEY_FOCUS_END) || '0');const now = Date.now();if (savedState === 'paused' && savedRemaining > 0) {// 恢复暂停状态(工作或休息)remainingTime = savedRemaining;isResuming = true;autoStart = false;} else if (savedState === 'running' && endTime > now) {// 恢复运行状态(工作或休息)remainingTime = Math.floor((endTime - now) / 1000);if (remainingTime > 0) {isResuming = true;autoStart = true;}}// 修复:根据保存状态初始化按钮状态(关键修复)if (savedState === 'paused' && savedRemaining > 0) {startBtn.textContent = '继续';startBtn.classList.add('pause');startBtn.classList.remove('start');startBtn.disabled = false;stopBtn.disabled = false;} else if (savedState === 'running' && endTime > now && remainingTime > 0) {startBtn.textContent = '暂停';startBtn.classList.remove('pause');startBtn.classList.add('start');startBtn.disabled = false;stopBtn.disabled = false;} else {startBtn.textContent = '开始';startBtn.classList.add('start');startBtn.classList.remove('pause');startBtn.disabled = false;stopBtn.disabled = (currentMode === 'work' && remainingTime === workDuration * 60);}function updateDisplay() {const mins = Math.floor(remainingTime / 60);const secs = remainingTime % 60;timeDisplay.textContent = `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;const totalSeconds = (currentMode === 'work' ? workDuration : restDuration) * 60;const progress = ((totalSeconds - remainingTime) / totalSeconds) * 100;progressBar.style.width = `${Math.max(0, Math.min(100, progress))}%`;}function toggleTimer() {if (timer) {clearInterval(timer);timer = null;pauseFocusMode(remainingTime);localStorage.setItem(STORAGE_KEY_CURRENT_MODE, currentMode);isResuming = true;startBtn.textContent = '继续';startBtn.classList.add('pause');startBtn.classList.remove('start');startBtn.disabled = false;stopBtn.disabled = false;} else {if (isResuming) {const endTime = Date.now() + remainingTime * 1000;localStorage.setItem(STORAGE_KEY_FOCUS_END, endTime.toString());localStorage.setItem(STORAGE_KEY_FOCUS_STATE, 'running');localStorage.setItem(STORAGE_KEY_CURRENT_MODE, currentMode);localStorage.removeItem(STORAGE_KEY_FOCUS_REMAINING);isResuming = false;} else {remainingTime = (currentMode === 'work' ? workDuration : restDuration) * 60;// 修复:统一设置专注模式状态,支持休息模式startFocusMode(currentMode === 'work' ? workDuration : restDuration,currentMode === 'work');localStorage.setItem(STORAGE_KEY_CURRENT_MODE, currentMode);}startBtn.textContent = '暂停';startBtn.classList.remove('pause');startBtn.classList.add('start');startBtn.disabled = false;stopBtn.disabled = false;timer = setInterval(() => {remainingTime--;updateDisplay();if (remainingTime <= 0) {clearInterval(timer);timer = null;if (currentMode === 'work') {// 修复:工作结束进入休息模式,清除专注状态(不保存暂停状态)currentMode = 'rest';remainingTime = restDuration * 60;endFocusMode(); // 清除工作计时状态localStorage.setItem(STORAGE_KEY_CURRENT_MODE, 'rest');updateDisplay();startBtn.textContent = '开始';startBtn.classList.add('start');startBtn.classList.remove('pause');startBtn.disabled = false;stopBtn.disabled = false;} else {// 休息结束,完全结束专注模式endFocusMode();startBtn.textContent = '开始';startBtn.classList.add('start');startBtn.classList.remove('pause');startBtn.disabled = false;stopBtn.disabled = true;// 重置为工作模式currentMode = 'work';remainingTime = workDuration * 60;updateDisplay();}}}, 1000);}}function stopTimer() {clearInterval(timer);timer = null;remainingTime = workDuration * 60;currentMode = 'work';isResuming = false;updateDisplay();endFocusMode();startBtn.textContent = '开始';startBtn.classList.add('start');startBtn.classList.remove('pause');startBtn.disabled = false;stopBtn.disabled = true;}startBtn.onclick = toggleTimer;stopBtn.onclick = stopTimer;let isDragging = false;let offsetX, offsetY;widget.onmousedown = (e) => {if (e.target.id === 'luogu-pomodoro-settings') return;isDragging = true;const rect = widget.getBoundingClientRect();offsetX = e.clientX - rect.left;offsetY = e.clientY - rect.top;widget.style.cursor = 'move';e.preventDefault();};document.onmousemove = (e) => {if (!isDragging) return;const x = e.clientX - offsetX;const y = e.clientY - offsetY;const maxX = window.innerWidth - widget.offsetWidth;const maxY = window.innerHeight - widget.offsetHeight;widget.style.left = `${Math.max(0, Math.min(x, maxX))}px`;widget.style.top = `${Math.max(0, Math.min(y, maxY))}px`;};document.onmouseup = () => {if (isDragging) {isDragging = false;widget.style.cursor = 'default';const rect = widget.getBoundingClientRect();saveFocusPosition({x: Math.round(rect.left),y: Math.round(rect.top)});}};updateDisplay();if (autoStart) {setTimeout(() => {toggleTimer();}, 300);}}function createSettingUI() {if (!/^(https?:\/\/)?(www\.)?luogu\.com\.cn/i.test(window.location.href)) return;const existingMask = document.getElementById('luogu-modal-mask');const existingBox = document.getElementById('luogu-modal-box');if (existingMask) existingMask.remove();if (existingBox) existingBox.remove();const style = document.createElement('style');style.textContent = `#luogu-modal-mask {position: fixed;top: 0;left: 0;right: 0;bottom: 0;background: rgba(0,0,0,0.5);z-index: 99997;display: none;}#luogu-modal-box {position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%);width: 340px;padding: 20px;background: #fff;border-radius: 10px;z-index: 99998;display: none;box-shadow: 0 0 20px rgba(0,0,0,0.3);font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", sans-serif;}#luogu-modal-box h3 {margin: 0 0 15px 0;color: #222;text-align: center;font-size: 20px;border-bottom: 1px solid #eee;padding-bottom: 10px;}.luogu-form-group {margin-bottom: 15px;}.luogu-form-group label {display: block;margin-bottom: 8px;font-weight: 600;color: #333;font-size: 14px;}#luogu-pid-input {width: 100%;padding: 10px;box-sizing: border-box;border: 1px solid #ddd;border-radius: 4px;font-size: 14px;transition: border-color 0.3s;}#luogu-pid-input:focus {border-color: #0099ff;outline: none;}#luogu-solution-switch {display: flex;align-items: center;gap: 8px;padding: 8px 0;}#luogu-solution-switch input {width: 18px;height: 18px;cursor: pointer;}.duration-settings {display: flex;gap: 10px;}.duration-col {flex: 1;}.duration-input {width: 100%;padding: 8px;border: 1px solid #ddd;border-radius: 4px;font-size: 14px;margin-top: 4px;}.pid-list {display: flex;flex-wrap: wrap;gap: 8px;margin-top: 8px;min-height: 30px;}.pid-item {background: #f0f0f0;padding: 5px 10px;border-radius: 12px;font-size: 13px;display: flex;align-items: center;gap: 5px;cursor: pointer;transition: all 0.2s;}.pid-item:hover {background: #e0e0e0;transform: scale(1.02);}.pid-item .remove {color: #ff4444;cursor: pointer;font-size: 14px;margin-left: 4px;}#luogu-color-input {width: 100%;height: 30px;border: none;border-radius: 4px;padding: 0;margin-top: 5px;cursor: pointer;}#luogu-modal-btn-group {display: flex;gap: 10px;margin-top: 15px;padding-top: 10px;border-top: 1px solid #f5f5f5;}#luogu-save-btn, #luogu-cancel-btn {flex: 1;padding: 10px;border: none;border-radius: 4px;cursor: pointer;font-size: 14px;font-weight: 500;transition: all 0.2s;}#luogu-save-btn {background: #0099ff;color: white;}#luogu-save-btn:hover {background: #0077cc;}#luogu-cancel-btn {background: #f0f0f0;color: #666;}#luogu-cancel-btn:hover {background: #e0e0e0;}.luogu-hint {font-size: 12px;color: #888;margin-top: 5px;line-height: 1.4;}`;document.head.appendChild(style);const mask = document.createElement('div');mask.id = 'luogu-modal-mask';mask.onclick = () => {mask.style.display = 'none';modalBox.style.display = 'none';};document.body.appendChild(mask);const modalBox = document.createElement('div');modalBox.id = 'luogu-modal-box';modalBox.innerHTML = `<h3>专注设置</h3><div class="luogu-form-group"><label>题目计划</label><input type="text" id="luogu-pid-input" placeholder="输入题号(如:P1000)"><div class="luogu-hint">最多添加6道题目,点击题号跳转</div><div class="pid-list" id="pid-list"></div></div><div class="luogu-form-group"><label>题解访问</label><div id="luogu-solution-switch"><input type="checkbox" id="luogu-solution-checkbox"><span>允许查看题解(独立控制,不受计时影响)</span></div></div><div class="luogu-form-group"><label>番茄钟时长(分钟)</label><div class="duration-settings"><div class="duration-col"><div>工作</div><input type="number" id="luogu-work-input" class="duration-input" min="1" max="120" value="${getWorkDuration()}"></div><div class="duration-col"><div>休息</div><input type="number" id="luogu-rest-input" class="duration-input" min="1" max="60" value="${getRestDuration()}"></div></div></div><div class="luogu-form-group"><label>番茄钟颜色</label><input type="color" id="luogu-color-input" value="${getFocusColor()}"></div><div id="luogu-modal-btn-group"><button id="luogu-save-btn">保存</button><button id="luogu-cancel-btn">取消</button></div>`;document.body.appendChild(modalBox);function renderPidList() {const pidList = document.getElementById('pid-list');pidList.innerHTML = '';const pids = getSavePids();if (pids.length === 0) {pidList.innerHTML = '<div style="text-align:center;color:#999;padding:5px 0">暂无题目</div>';return;}pids.forEach(pid => {const item = document.createElement('div');item.className = 'pid-item';item.innerHTML = `${pid}<span class="remove">×</span>`;item.addEventListener('click', (e) => {if (e.target.classList.contains('remove')) return;window.location.href = `https://www.luogu.com.cn/problem/${pid}`;});const removeBtn = item.querySelector('.remove');removeBtn.addEventListener('click', (e) => {e.stopPropagation();if (removePid(pid)) {renderPidList();}});pidList.appendChild(item);});}document.getElementById('luogu-save-btn').onclick = () => {const pidInput = document.getElementById('luogu-pid-input');const pid = pidInput.value.trim().toUpperCase();const solutionChecked = document.getElementById('luogu-solution-checkbox').checked;const workDuration = parseInt(document.getElementById('luogu-work-input').value) || DEFAULT_WORK_DURATION;const restDuration = parseInt(document.getElementById('luogu-rest-input').value) || DEFAULT_REST_DURATION;const color = document.getElementById('luogu-color-input').value;if (workDuration < 1 || workDuration > 120) {alert('工作时长必须在 1-120 分钟之间');return;}if (restDuration < 1 || restDuration > 60) {alert('休息时长必须在 1-60 分钟之间');return;}if (pid && !/^(P|SP)\d{4,6}$/i.test(pid)) {alert('题号格式错误!\n正确格式:P1000 或 SP123');return;}const pids = getSavePids();if (pid && pids.length < MAX_PIDS && !pids.includes(pid)) {pids.push(pid);savePids(pids);}saveSolutionStatus(solutionChecked);saveDurations(workDuration, restDuration);saveFocusColor(color);alert('设置已保存!');mask.style.display = 'none';modalBox.style.display = 'none';renderPidList();monitorSolutionElements();};document.getElementById('luogu-cancel-btn').onclick = () => {mask.style.display = 'none';modalBox.style.display = 'none';};document.getElementById('luogu-pid-input').addEventListener('keypress', (e) => {if (e.key === 'Enter') {document.getElementById('luogu-save-btn').click();}});mask.style.display = 'block';modalBox.style.display = 'block';document.getElementById('luogu-pid-input').value = '';document.getElementById('luogu-solution-checkbox').checked = getSolutionStatus();renderPidList();}if (document.readyState === 'loading') {document.addEventListener('DOMContentLoaded', () => {createPomodoroWidget();});} else {createPomodoroWidget();}window.addEventListener('load', () => {monitorSolutionElements();});})();```:::---## $\textup{Upd on 2026.3.7}$注意到我们的添加题库出了一点问题,可能是因为在原文章基础上进行开发,没有把入门与面试、CF、AT 和 UVA 题库的题目添加到计划的功能。在完善这个功能的同时,我正添加了在学习过程中按暂停可以暂时访问其他网页的功能。(否则暂停键没有起到任何作用吧。)包括考虑将在未来添加一个可以选择是否拦截所有除题目外的网址的模式,但是调了好久没整出来。:::success[$\textup{V2 Code.}$]```// ==UserScript==// @name 洛谷强力学术 pro// @namespace http://tampermonkey.net/// @version 10.57// @author wendywan// @icon https://cdn.luogu.com.cn/upload/image_hosting/psd5a03h.png// @match *://*/*// @grant none// @license MIT// @run-at document-start// ==/UserScript==(function() {'use strict';const STORAGE_KEY_PID = "luogu_study_plan_pids";const STORAGE_KEY_SOLUTION = "luogu_study_plan_solution";const STORAGE_KEY_FOCUS_ACTIVE = "luogu_focus_active";const STORAGE_KEY_FOCUS_END = "luogu_focus_end_time";const STORAGE_KEY_FOCUS_DURATION = "luogu_focus_duration";const STORAGE_KEY_FOCUS_COLOR = "luogu_focus_color";const STORAGE_KEY_FOCUS_POS = "luogu_focus_position";const STORAGE_KEY_FOCUS_REMAINING = "luogu_focus_remaining";const STORAGE_KEY_FOCUS_STATE = "luogu_focus_state";const STORAGE_KEY_REST_DURATION = "luogu_rest_duration";const STORAGE_KEY_CURRENT_MODE = "luogu_focus_current_mode";const DEFAULT_WORK_DURATION = 25;const DEFAULT_REST_DURATION = 5;const DEFAULT_COLOR = "#ff6b6b";const DEFAULT_POSITION = { x: 20, y: 100 };const DEFAULT_SIZE = { width: 120, height: 100 };const MAX_PIDS = 6;function getSavePids() {try {const pids = JSON.parse(localStorage.getItem(STORAGE_KEY_PID)) || [];return pids.filter(pid => pid.trim() !== '');} catch {return [];}}function savePids(pids) {localStorage.setItem(STORAGE_KEY_PID, JSON.stringify(pids));}function removePid(pid) {const pids = getSavePids();const index = pids.indexOf(pid);if (index !== -1) {pids.splice(index, 1);savePids(pids);return true;}return false;}function getSolutionStatus() {return localStorage.getItem(STORAGE_KEY_SOLUTION) !== 'false';}function saveSolutionStatus(status) {localStorage.setItem(STORAGE_KEY_SOLUTION, status);}function isFocusActive() {const active = localStorage.getItem(STORAGE_KEY_FOCUS_ACTIVE) === 'true';if (!active) return false;const state = localStorage.getItem(STORAGE_KEY_FOCUS_STATE);if (state === 'paused') {return true;}const endTime = parseInt(localStorage.getItem(STORAGE_KEY_FOCUS_END) || '0');const now = Date.now();if (active && now >= endTime) {endFocusMode();return false;}return active;}function startFocusMode(durationMinutes, isWorkMode) {const endTime = Date.now() + durationMinutes * 60 * 1000;localStorage.setItem(STORAGE_KEY_FOCUS_ACTIVE, 'true');localStorage.setItem(STORAGE_KEY_FOCUS_END, endTime.toString());if (isWorkMode) {localStorage.setItem(STORAGE_KEY_FOCUS_DURATION, durationMinutes.toString());}localStorage.setItem(STORAGE_KEY_FOCUS_STATE, 'running');localStorage.removeItem(STORAGE_KEY_FOCUS_REMAINING);}function pauseFocusMode(remainingSeconds) {localStorage.setItem(STORAGE_KEY_FOCUS_STATE, 'paused');localStorage.setItem(STORAGE_KEY_FOCUS_REMAINING, remainingSeconds.toString());localStorage.removeItem(STORAGE_KEY_FOCUS_END);}function endFocusMode() {localStorage.removeItem(STORAGE_KEY_FOCUS_ACTIVE);localStorage.removeItem(STORAGE_KEY_FOCUS_END);localStorage.removeItem(STORAGE_KEY_FOCUS_STATE);localStorage.removeItem(STORAGE_KEY_FOCUS_REMAINING);localStorage.removeItem(STORAGE_KEY_CURRENT_MODE);}function getWorkDuration() {return parseInt(localStorage.getItem(STORAGE_KEY_FOCUS_DURATION) || DEFAULT_WORK_DURATION);}function getRestDuration() {return parseInt(localStorage.getItem(STORAGE_KEY_REST_DURATION) || DEFAULT_REST_DURATION);}function saveDurations(work, rest) {localStorage.setItem(STORAGE_KEY_FOCUS_DURATION, work.toString());localStorage.setItem(STORAGE_KEY_REST_DURATION, rest.toString());}function getFocusColor() {return localStorage.getItem(STORAGE_KEY_FOCUS_COLOR) || DEFAULT_COLOR;}function saveFocusColor(color) {localStorage.setItem(STORAGE_KEY_FOCUS_COLOR, color);}function getFocusPosition() {try {return JSON.parse(localStorage.getItem(STORAGE_KEY_FOCUS_POS) || JSON.stringify(DEFAULT_POSITION));} catch {return DEFAULT_POSITION;}}function saveFocusPosition(pos) {localStorage.setItem(STORAGE_KEY_FOCUS_POS, JSON.stringify(pos));}function getRedirectUrl() {const pids = getSavePids();return pids.length > 0? `https://www.luogu.com.cn/problem/${pids[0]}`: 'https://www.luogu.com.cn/problem/list';}function shouldAllow() {const currentURL = window.location.href;const isLuoguDomain = /^(https?:\/\/)?(www\.)?luogu\.com\.cn/i.test(currentURL);if (!isLuoguDomain) return true;if (!isFocusActive()) return true;const state = localStorage.getItem(STORAGE_KEY_FOCUS_STATE);if (state === 'paused') {return true;}const currentMode = localStorage.getItem(STORAGE_KEY_CURRENT_MODE);if (currentMode === 'rest') {return true;}const path = window.location.pathname.toLowerCase();return (path.startsWith('/problem/') ||path.startsWith('/paste') ||path.startsWith('/paste/') ||path.startsWith('/record/'));}function blockSolutionAccess() {if (!/\/problem\/solution\//i.test(window.location.pathname)) {return false;}if (!getSolutionStatus()) {window.location.replace(getRedirectUrl());return true;}return false;}function monitorSolutionElements() {if (!getSolutionStatus()) {const observer = new MutationObserver((mutations) => {mutations.forEach(mutation => {mutation.addedNodes.forEach(node => {if (node.nodeType !== 1) return;const selectors = ['a[href*="/problem/solution/"]','[class*="solution"]','[class*="answer"]'];try {node.querySelectorAll(selectors.join(',')).forEach(el => {if ((el.textContent && el.textContent.includes('题解')) ||(el.href && el.href.includes('/problem/solution/'))) {el.style.display = 'none !important';el.style.visibility = 'hidden !important';el.style.height = '0 !important';el.style.overflow = 'hidden !important';}});} catch (e) {}});});});observer.observe(document.body, { childList: true, subtree: true });}}if (blockSolutionAccess()) return;if (isFocusActive() && !shouldAllow()) {window.location.replace(getRedirectUrl());return;}function createPomodoroWidget() {if (!/^(https?:\/\/)?(www\.)?luogu\.com\.cn/i.test(window.location.href)) return;const workDuration = getWorkDuration();const restDuration = getRestDuration();const config = {workDuration: workDuration,restDuration: restDuration,color: getFocusColor(),position: getFocusPosition()};const style = document.createElement('style');style.textContent = `#luogu-pomodoro-widget {position: fixed;z-index: 99999;border-radius: 10px;box-shadow: 0 2px 10px rgba(0,0,0,0.15);overflow: hidden;font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", sans-serif;user-select: none;width: ${DEFAULT_SIZE.width}px;height: ${DEFAULT_SIZE.height}px;background: white;border: 1px solid #e0e0e0;cursor: move;transition: border-color 0.3s ease;}#luogu-pomodoro-widget:hover {box-shadow: 0 3px 15px rgba(0,0,0,0.2);}#luogu-pomodoro-time {font-size: 20px;font-weight: bold;text-align: center;color: #333;padding: 12px 0;height: 40px;display: flex;align-items: center;justify-content: center;}#luogu-pomodoro-progress {height: 4px;background: #f0f0f0;border-radius: 2px;margin: 4px 8px;overflow: hidden;}#luogu-pomodoro-progress-bar {height: 100%;width: 0%;background: ${config.color};border-radius: 2px;transition: width 0.5s ease;}#luogu-pomodoro-controls {display: flex;justify-content: center;gap: 6px;padding: 6px 0;background: #f8f9fa;border-top: 1px solid #eee;}.pomodoro-btn {width: 48%;height: 22px;border: none;border-radius: 3px;font-size: 11px;font-weight: 500;cursor: pointer;transition: all 0.2s;user-select: none;text-align: center;line-height: 22px;color: #333;}.pomodoro-btn:active {transform: scale(0.95);}.pomodoro-btn.start {background: #e8f5e9;color: #2e7d32;}.pomodoro-btn.pause {background: #fff8e1;color: #ff8f00;}.pomodoro-btn.stop {background: #ffebee;color: #c62828;}.pomodoro-btn.start:disabled,.pomodoro-btn.pause:disabled {opacity: 0.6;cursor: not-allowed;transform: none !important;}#luogu-pomodoro-settings {position: absolute;top: 8px;right: 8px;width: 24px;height: 24px;border-radius: 6px;background: ${config.color};display: flex;align-items: center;justify-content: center;font-size: 14px;cursor: pointer;z-index: 10;transition: all 0.2s;box-shadow: 0 1px 3px rgba(0,0,0,0.2);}#luogu-pomodoro-settings:hover {transform: scale(1.1);box-shadow: 0 2px 6px rgba(0,0,0,0.3);}#luogu-pomodoro-settings svg {width: 14px;height: 14px;fill: white;}#luogu-pomodoro-widget.focus-running {border: 2px solid ${config.color} !important;}`;document.head.appendChild(style);const widget = document.createElement('div');widget.id = 'luogu-pomodoro-widget';widget.style.left = `${config.position.x}px`;widget.style.top = `${config.position.y}px`;widget.innerHTML = `<div id="luogu-pomodoro-time">25:00</div><div id="luogu-pomodoro-progress"><div id="luogu-pomodoro-progress-bar"></div></div><div id="luogu-pomodoro-controls"><button class="pomodoro-btn start">开始</button><button class="pomodoro-btn stop">结束</button></div><div id="luogu-pomodoro-settings"><svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19.14 12.94c.04-.31.06-.63.06-.94 0-.31-.02-.63-.06-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.04.31-.06.63-.06.94s.02.63.06.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z"/></svg></div>`;document.body.appendChild(widget);const settingsBtn = widget.querySelector('#luogu-pomodoro-settings');settingsBtn.onclick = (e) => {e.stopPropagation();createSettingUI();};let timer = null;let remainingTime = workDuration * 60;let currentMode = 'work';let isResuming = false;let autoStart = false;const savedMode = localStorage.getItem(STORAGE_KEY_CURRENT_MODE);if (savedMode === 'rest') {currentMode = 'rest';remainingTime = restDuration * 60;}const timeDisplay = widget.querySelector('#luogu-pomodoro-time');const progressBar = widget.querySelector('#luogu-pomodoro-progress-bar');const startBtn = widget.querySelector('.pomodoro-btn.start');const stopBtn = widget.querySelector('.pomodoro-btn.stop');const savedState = localStorage.getItem(STORAGE_KEY_FOCUS_STATE);const savedRemaining = parseInt(localStorage.getItem(STORAGE_KEY_FOCUS_REMAINING) || '0');const endTime = parseInt(localStorage.getItem(STORAGE_KEY_FOCUS_END) || '0');const now = Date.now();if (savedState === 'paused' && savedRemaining > 0) {remainingTime = savedRemaining;isResuming = true;autoStart = false;} else if (savedState === 'running' && endTime > now) {remainingTime = Math.floor((endTime - now) / 1000);if (remainingTime > 0) {isResuming = true;autoStart = true;}}if (savedState === 'paused' && savedRemaining > 0) {startBtn.textContent = '继续';startBtn.classList.add('pause');startBtn.classList.remove('start');startBtn.disabled = false;stopBtn.disabled = false;} else if (savedState === 'running' && endTime > now && remainingTime > 0) {startBtn.textContent = '暂停';startBtn.classList.remove('pause');startBtn.classList.add('start');startBtn.disabled = false;stopBtn.disabled = false;} else {startBtn.textContent = '开始';startBtn.classList.add('start');startBtn.classList.remove('pause');startBtn.disabled = false;stopBtn.disabled = (currentMode === 'work' && remainingTime === workDuration * 60);}function updateFocusBorderStyle() {const isRunning = timer !== null;const isWorkMode = currentMode === 'work';const isPaused = localStorage.getItem(STORAGE_KEY_FOCUS_STATE) === 'paused';const isRest = currentMode === 'rest';if (isRunning && isWorkMode && !isPaused && !isRest) {widget.classList.add('focus-running');} else {widget.classList.remove('focus-running');}}function updateDisplay() {const mins = Math.floor(remainingTime / 60);const secs = remainingTime % 60;timeDisplay.textContent = `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;const totalSeconds = (currentMode === 'work' ? workDuration : restDuration) * 60;const progress = ((totalSeconds - remainingTime) / totalSeconds) * 100;progressBar.style.width = `${Math.max(0, Math.min(100, progress))}%`;updateFocusBorderStyle();}function toggleTimer() {if (timer) {clearInterval(timer);timer = null;pauseFocusMode(remainingTime);localStorage.setItem(STORAGE_KEY_CURRENT_MODE, currentMode);isResuming = true;startBtn.textContent = '继续';startBtn.classList.add('pause');startBtn.classList.remove('start');startBtn.disabled = false;stopBtn.disabled = false;updateFocusBorderStyle();} else {if (isResuming) {const endTime = Date.now() + remainingTime * 1000;localStorage.setItem(STORAGE_KEY_FOCUS_END, endTime.toString());localStorage.setItem(STORAGE_KEY_FOCUS_STATE, 'running');localStorage.setItem(STORAGE_KEY_CURRENT_MODE, currentMode);localStorage.removeItem(STORAGE_KEY_FOCUS_REMAINING);isResuming = false;} else {remainingTime = (currentMode === 'work' ? workDuration : restDuration) * 60;startFocusMode(currentMode === 'work' ? workDuration : restDuration,currentMode === 'work');localStorage.setItem(STORAGE_KEY_CURRENT_MODE, currentMode);}startBtn.textContent = '暂停';startBtn.classList.remove('pause');startBtn.classList.add('start');startBtn.disabled = false;stopBtn.disabled = false;updateFocusBorderStyle();timer = setInterval(() => {remainingTime--;updateDisplay();if (remainingTime <= 0) {clearInterval(timer);timer = null;if (currentMode === 'work') {currentMode = 'rest';remainingTime = restDuration * 60;endFocusMode();localStorage.setItem(STORAGE_KEY_CURRENT_MODE, 'rest');updateDisplay();startBtn.textContent = '开始';startBtn.classList.add('start');startBtn.classList.remove('pause');startBtn.disabled = false;stopBtn.disabled = false;} else {endFocusMode();startBtn.textContent = '开始';startBtn.classList.add('start');startBtn.classList.remove('pause');startBtn.disabled = false;stopBtn.disabled = true;currentMode = 'work';remainingTime = workDuration * 60;updateDisplay();}}}, 1000);}}function stopTimer() {clearInterval(timer);timer = null;remainingTime = workDuration * 60;currentMode = 'work';isResuming = false;updateDisplay();endFocusMode();startBtn.textContent = '开始';startBtn.classList.add('start');startBtn.classList.remove('pause');startBtn.disabled = false;stopBtn.disabled = true;}startBtn.onclick = toggleTimer;stopBtn.onclick = stopTimer;let isDragging = false;let offsetX, offsetY;widget.onmousedown = (e) => {if (e.target.id === 'luogu-pomodoro-settings') return;isDragging = true;const rect = widget.getBoundingClientRect();offsetX = e.clientX - rect.left;offsetY = e.clientY - rect.top;widget.style.cursor = 'move';e.preventDefault();};document.onmousemove = (e) => {if (!isDragging) return;const x = e.clientX - offsetX;const y = e.clientY - offsetY;const maxX = window.innerWidth - widget.offsetWidth;const maxY = window.innerHeight - widget.offsetHeight;widget.style.left = `${Math.max(0, Math.min(x, maxX))}px`;widget.style.top = `${Math.max(0, Math.min(y, maxY))}px`;};document.onmouseup = () => {if (isDragging) {isDragging = false;widget.style.cursor = 'default';const rect = widget.getBoundingClientRect();saveFocusPosition({x: Math.round(rect.left),y: Math.round(rect.top)});}};updateDisplay();if (autoStart) {setTimeout(() => {toggleTimer();}, 300);}}function createSettingUI() {if (!/^(https?:\/\/)?(www\.)?luogu\.com\.cn/i.test(window.location.href)) return;const existingMask = document.getElementById('luogu-modal-mask');const existingBox = document.getElementById('luogu-modal-box');if (existingMask) existingMask.remove();if (existingBox) existingBox.remove();const style = document.createElement('style');style.textContent = `#luogu-modal-mask {position: fixed;top: 0;left: 0;right: 0;bottom: 0;background: rgba(0,0,0,0.5);z-index: 99997;display: none;}#luogu-modal-box {position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%);width: 420px;padding: 24px;background: #fff;border-radius: 12px;z-index: 99998;display: none;box-shadow: 0 0 20px rgba(0,0,0,0.3);font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", sans-serif;}#luogu-modal-box h3 {margin: 0 0 20px 0;color: #222;text-align: center;font-size: 22px;border-bottom: 1px solid #eee;padding-bottom: 12px;}.luogu-form-group {margin-bottom: 18px;}.luogu-form-group label {display: block;margin-bottom: 8px;font-weight: 600;color: #333;font-size: 15px;}#luogu-pid-input {width: 100%;padding: 12px;box-sizing: border-box;border: 1px solid #ddd;border-radius: 6px;font-size: 14px;transition: border-color 0.3s;}#luogu-pid-input:focus {border-color: #0099ff;outline: none;}#luogu-solution-switch {display: flex;align-items: center;gap: 10px;padding: 10px 0;}#luogu-solution-switch input {width: 20px;height: 20px;cursor: pointer;}.duration-settings {display: flex;gap: 15px;}.duration-col {flex: 1;}.duration-input {width: 100%;padding: 10px;border: 1px solid #ddd;border-radius: 6px;font-size: 14px;margin-top: 6px;}.pid-list {display: flex;flex-wrap: wrap;gap: 8px;margin-top: 10px;min-height: 35px;}.pid-item {background: #f0f0f0;padding: 6px 12px;border-radius: 14px;font-size: 13px;display: flex;align-items: center;gap: 6px;cursor: pointer;transition: all 0.2s;}.pid-item:hover {background: #e0e0e0;transform: scale(1.03);}.pid-item .remove {color: #ff4444;cursor: pointer;font-size: 15px;margin-left: 4px;}#luogu-color-input {width: 100%;height: 36px;border: 1px solid #ddd;border-radius: 6px;padding: 2px;margin-top: 6px;cursor: pointer;}#luogu-modal-btn-group {display: flex;gap: 12px;margin-top: 20px;padding-top: 16px;border-top: 1px solid #f5f5f5;}#luogu-save-btn, #luogu-cancel-btn {flex: 1;padding: 12px;border: none;border-radius: 6px;cursor: pointer;font-size: 15px;font-weight: 500;transition: all 0.2s;}#luogu-save-btn {background: #0099ff;color: white;}#luogu-save-btn:hover {background: #0077cc;}#luogu-cancel-btn {background: #f0f0f0;color: #666;}#luogu-cancel-btn:hover {background: #e0e0e0;}.luogu-hint {font-size: 12px;color: #888;margin-top: 8px;line-height: 1.5;}`;document.head.appendChild(style);const mask = document.createElement('div');mask.id = 'luogu-modal-mask';mask.onclick = () => {mask.style.display = 'none';modalBox.style.display = 'none';};document.body.appendChild(mask);const modalBox = document.createElement('div');modalBox.id = 'luogu-modal-box';modalBox.innerHTML = `<h3>专注设置</h3><div class="luogu-form-group"><label>题目计划</label><input type="text" id="luogu-pid-input" placeholder="输入题号(如:P1000、B2001、CF1C、AT_abc001_a、UVA100)"><div class="luogu-hint">最多添加 6 道题目,点击题号可直接跳转。支持洛谷、Codeforces、AtCoder、UVA 等题库编号。</div><div class="pid-list" id="pid-list"></div></div><div class="luogu-form-group"><label>题解访问</label><div id="luogu-solution-switch"><input type="checkbox" id="luogu-solution-checkbox"><span>允许查看题解(独立控制,不受计时影响)</span></div></div><div class="luogu-form-group"><label>番茄钟时长(分钟)</label><div class="duration-settings"><div class="duration-col"><div style="font-size:13px;color:#666;">工作时长</div><input type="number" id="luogu-work-input" class="duration-input" min="1" max="120" value="${getWorkDuration()}"></div><div class="duration-col"><div style="font-size:13px;color:#666;">休息时长</div><input type="number" id="luogu-rest-input" class="duration-input" min="1" max="60" value="${getRestDuration()}"></div></div></div><div class="luogu-form-group"><label>番茄钟颜色</label><input type="color" id="luogu-color-input" value="${getFocusColor()}"><div class="luogu-hint">专注工作时,番茄钟边框会显示此颜色。</div></div><div id="luogu-modal-btn-group"><button id="luogu-save-btn">保存</button><button id="luogu-cancel-btn">取消</button></div>`;document.body.appendChild(modalBox);function renderPidList() {const pidList = document.getElementById('pid-list');pidList.innerHTML = '';const pids = getSavePids();if (pids.length === 0) {pidList.innerHTML = '<div style="text-align:center;color:#999;padding:8px 0;width:100%">暂无题目</div>';return;}pids.forEach(pid => {const item = document.createElement('div');item.className = 'pid-item';item.innerHTML = `${pid}<span class="remove">×</span>`;item.addEventListener('click', (e) => {if (e.target.classList.contains('remove')) return;window.location.href = `https://www.luogu.com.cn/problem/${pid}`;});const removeBtn = item.querySelector('.remove');removeBtn.addEventListener('click', (e) => {e.stopPropagation();if (removePid(pid)) {renderPidList();}});pidList.appendChild(item);});}document.getElementById('luogu-save-btn').onclick = () => {const pidInput = document.getElementById('luogu-pid-input');const rawPid = pidInput.value.trim();const pid = rawPid.startsWith('AT_') ? rawPid : rawPid.toUpperCase();const solutionChecked = document.getElementById('luogu-solution-checkbox').checked;const workDuration = parseInt(document.getElementById('luogu-work-input').value) || DEFAULT_WORK_DURATION;const restDuration = parseInt(document.getElementById('luogu-rest-input').value) || DEFAULT_REST_DURATION;const color = document.getElementById('luogu-color-input').value;if (workDuration < 1 || workDuration > 120) {alert('工作时长必须在 1-120 分钟之间');return;}if (restDuration < 1 || restDuration > 60) {alert('休息时长必须在 1-60 分钟之间');return;}if (pid && !/^(P\d{4,6}|SP\d{3,5}|B\d{4,5}|CF\d+[A-Z]?|AT_[a-z0-9_]+|UVA\d{3,5})$/i.test(pid)) {alert('题号格式错误!\n正确格式:P1000, SP123, B2001, CF1C, AT_abc001_a, UVA100 等');return;}const pids = getSavePids();if (pid && pids.length < MAX_PIDS && !pids.includes(pid)) {pids.push(pid);savePids(pids);}saveSolutionStatus(solutionChecked);saveDurations(workDuration, restDuration);saveFocusColor(color);alert('设置已保存!');mask.style.display = 'none';modalBox.style.display = 'none';renderPidList();monitorSolutionElements();};document.getElementById('luogu-cancel-btn').onclick = () => {mask.style.display = 'none';modalBox.style.display = 'none';};document.getElementById('luogu-pid-input').addEventListener('keypress', (e) => {if (e.key === 'Enter') {document.getElementById('luogu-save-btn').click();}});mask.style.display = 'block';modalBox.style.display = 'block';document.getElementById('luogu-pid-input').value = '';document.getElementById('luogu-solution-checkbox').checked = getSolutionStatus();renderPidList();}if (document.readyState === 'loading') {document.addEventListener('DOMContentLoaded', () => {createPomodoroWidget();});} else {createPomodoroWidget();}window.addEventListener('load', () => {monitorSolutionElements();});})();```:::## $\textup{Upd on 2026.5.24}$修复目前已知的 bug,比如无法拦截进入题库等功能。:::success[$\textup{V3 Code.}$]```// ==UserScript==// @name 洛谷强力学术Pro// @namespace http://tampermonkey.net/// @version 10.58// @author wendywan// @icon https://cdn.luogu.com.cn/upload/image_hosting/psd5a03h.png// @match *://*/*// @grant none// @license MIT// @run-at document-start// ==/UserScript==(function() {'use strict';const STORAGE_KEY_PID = "luogu_study_plan_pids";const STORAGE_KEY_SOLUTION = "luogu_study_plan_solution";const STORAGE_KEY_FOCUS_ACTIVE = "luogu_focus_active";const STORAGE_KEY_FOCUS_END = "luogu_focus_end_time";const STORAGE_KEY_FOCUS_DURATION = "luogu_focus_duration";const STORAGE_KEY_FOCUS_COLOR = "luogu_focus_color";const STORAGE_KEY_FOCUS_POS = "luogu_focus_position";const STORAGE_KEY_FOCUS_REMAINING = "luogu_focus_remaining";const STORAGE_KEY_FOCUS_STATE = "luogu_focus_state";const STORAGE_KEY_REST_DURATION = "luogu_rest_duration";const STORAGE_KEY_CURRENT_MODE = "luogu_focus_current_mode";const DEFAULT_WORK_DURATION = 25;const DEFAULT_REST_DURATION = 5;const DEFAULT_COLOR = "#ff6b6b";const DEFAULT_POSITION = { x: 20, y: 100 };const DEFAULT_SIZE = { width: 120, height: 100 };const MAX_PIDS = 6;function getSavePids() {try {const pids = JSON.parse(localStorage.getItem(STORAGE_KEY_PID)) || [];return pids.filter(pid => pid.trim() !== '');} catch {return [];}}function savePids(pids) {localStorage.setItem(STORAGE_KEY_PID, JSON.stringify(pids));}function removePid(pid) {const pids = getSavePids();const index = pids.indexOf(pid);if (index !== -1) {pids.splice(index, 1);savePids(pids);return true;}return false;}function getSolutionStatus() {return localStorage.getItem(STORAGE_KEY_SOLUTION) !== 'false';}function saveSolutionStatus(status) {localStorage.setItem(STORAGE_KEY_SOLUTION, status);}function isFocusActive() {const active = localStorage.getItem(STORAGE_KEY_FOCUS_ACTIVE) === 'true';if (!active) return false;const state = localStorage.getItem(STORAGE_KEY_FOCUS_STATE);if (state === 'paused') {return true;}const endTime = parseInt(localStorage.getItem(STORAGE_KEY_FOCUS_END) || '0');const now = Date.now();if (active && now >= endTime) {endFocusMode();return false;}return active;}function startFocusMode(durationMinutes, isWorkMode) {const endTime = Date.now() + durationMinutes * 60 * 1000;localStorage.setItem(STORAGE_KEY_FOCUS_ACTIVE, 'true');localStorage.setItem(STORAGE_KEY_FOCUS_END, endTime.toString());if (isWorkMode) {localStorage.setItem(STORAGE_KEY_FOCUS_DURATION, durationMinutes.toString());}localStorage.setItem(STORAGE_KEY_FOCUS_STATE, 'running');localStorage.removeItem(STORAGE_KEY_FOCUS_REMAINING);}function pauseFocusMode(remainingSeconds) {localStorage.setItem(STORAGE_KEY_FOCUS_STATE, 'paused');localStorage.setItem(STORAGE_KEY_FOCUS_REMAINING, remainingSeconds.toString());localStorage.removeItem(STORAGE_KEY_FOCUS_END);}function endFocusMode() {localStorage.removeItem(STORAGE_KEY_FOCUS_ACTIVE);localStorage.removeItem(STORAGE_KEY_FOCUS_END);localStorage.removeItem(STORAGE_KEY_FOCUS_STATE);localStorage.removeItem(STORAGE_KEY_FOCUS_REMAINING);localStorage.removeItem(STORAGE_KEY_CURRENT_MODE);}function getWorkDuration() {return parseInt(localStorage.getItem(STORAGE_KEY_FOCUS_DURATION) || DEFAULT_WORK_DURATION);}function getRestDuration() {return parseInt(localStorage.getItem(STORAGE_KEY_REST_DURATION) || DEFAULT_REST_DURATION);}function saveDurations(work, rest) {localStorage.setItem(STORAGE_KEY_FOCUS_DURATION, work.toString());localStorage.setItem(STORAGE_KEY_REST_DURATION, rest.toString());}function getFocusColor() {return localStorage.getItem(STORAGE_KEY_FOCUS_COLOR) || DEFAULT_COLOR;}function saveFocusColor(color) {localStorage.setItem(STORAGE_KEY_FOCUS_COLOR, color);}function getFocusPosition() {try {return JSON.parse(localStorage.getItem(STORAGE_KEY_FOCUS_POS) || JSON.stringify(DEFAULT_POSITION));} catch {return DEFAULT_POSITION;}}function saveFocusPosition(pos) {localStorage.setItem(STORAGE_KEY_FOCUS_POS, JSON.stringify(pos));}function getRedirectUrl() {const pids = getSavePids();return pids.length > 0? `https://www.luogu.com.cn/problem/${pids[0]}`: 'https://www.luogu.com.cn/problem/list';}function shouldAllow() {const currentURL = window.location.href;const isLuoguDomain = /^(https?:\/\/)?(www\.)?luogu\.com\.cn/i.test(currentURL);if (!isLuoguDomain) return true;if (!isFocusActive()) return true;const state = localStorage.getItem(STORAGE_KEY_FOCUS_STATE);if (state === 'paused') return true;const currentMode = localStorage.getItem(STORAGE_KEY_CURRENT_MODE);if (currentMode === 'rest') return true;const path = window.location.pathname.toLowerCase();const allowedProblem = /^\/problem\//i.test(path);const allowedPaste = /^\/paste(\/.*)?$/i.test(path);const allowedRecord = /^\/record\//i.test(path);if (/\/problem\/solution\//i.test(path)) {return getSolutionStatus();}return allowedProblem || allowedPaste || allowedRecord;}function blockSolutionAccess() {const path = window.location.pathname.toLowerCase();if (/\/problem\/solution\//i.test(path)) {if (!getSolutionStatus()) {window.location.replace(getRedirectUrl());return true;}}return false;}function enforceAccessRules() {if (blockSolutionAccess()) return true;if (isFocusActive() && !shouldAllow()) {window.location.replace(getRedirectUrl());return true;}return false;}function monitorSolutionElements() {if (!getSolutionStatus()) {const observer = new MutationObserver((mutations) => {mutations.forEach(mutation => {mutation.addedNodes.forEach(node => {if (node.nodeType !== 1) return;const selectors = ['a[href*="/problem/solution/"]','[class*="solution"]','[class*="answer"]','.lg-article-content'];try {node.querySelectorAll(selectors.join(',')).forEach(el => {if ((el.textContent && el.textContent.includes('题解')) ||(el.href && el.href.includes('/problem/solution/'))) {el.style.display = 'none';el.style.visibility = 'hidden';el.style.height = '0';el.style.overflow = 'hidden';el.style.pointerEvents = 'none';}});} catch (e) {}});});});if (document.body) observer.observe(document.body, { childList: true, subtree: true });else document.addEventListener('DOMContentLoaded', () => observer.observe(document.body, { childList: true, subtree: true }));}}function createPomodoroWidget() {if (!/^(https?:\/\/)?(www\.)?luogu\.com\.cn/i.test(window.location.href)) return;const workDuration = getWorkDuration();const restDuration = getRestDuration();const config = {workDuration: workDuration,restDuration: restDuration,color: getFocusColor(),position: getFocusPosition()};const style = document.createElement('style');style.textContent = `#luogu-pomodoro-widget {position: fixed; z-index: 99999; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.15);overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", sans-serif;user-select: none; width: ${DEFAULT_SIZE.width}px; height: ${DEFAULT_SIZE.height}px;background: white; border: 1px solid #e0e0e0; cursor: move; transition: border-color 0.3s ease, box-shadow 0.3s ease;}#luogu-pomodoro-widget:hover { box-shadow: 0 3px 15px rgba(0,0,0,0.2); }#luogu-pomodoro-time { font-size: 20px; font-weight: bold; text-align: center; color: #333; padding: 12px 0; height: 40px; display: flex; align-items: center; justify-content: center; }#luogu-pomodoro-progress { height: 4px; background: #f0f0f0; border-radius: 2px; margin: 4px 8px; overflow: hidden; }#luogu-pomodoro-progress-bar { height: 100%; width: 0%; background: ${config.color}; border-radius: 2px; transition: width 0.5s ease; }#luogu-pomodoro-controls { display: flex; justify-content: center; gap: 6px; padding: 6px 0; background: #f8f9fa; border-top: 1px solid #eee; }.pomodoro-btn { width: 48%; height: 22px; border: none; border-radius: 3px; font-size: 11px; font-weight: 500; cursor: pointer; transition: all 0.2s; user-select: none; text-align: center; line-height: 22px; color: #333; }.pomodoro-btn:active { transform: scale(0.95); }.pomodoro-btn.start { background: #e8f5e9; color: #2e7d32; }.pomodoro-btn.pause { background: #fff8e1; color: #ff8f00; }.pomodoro-btn.stop { background: #ffebee; color: #c62828; }.pomodoro-btn.start:disabled, .pomodoro-btn.pause:disabled { opacity: 0.6; cursor: not-allowed; transform: none !important; }#luogu-pomodoro-settings { position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; border-radius: 6px; background: ${config.color}; display: flex; align-items: center; justify-content: center; font-size: 14px; cursor: pointer; z-index: 10; transition: all 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }#luogu-pomodoro-settings:hover { transform: scale(1.1); box-shadow: 0 2px 6px rgba(0,0,0,0.3); }#luogu-pomodoro-settings svg { width: 14px; height: 14px; fill: white; }#luogu-pomodoro-widget.focus-running { border: 2px solid ${config.color} !important; box-shadow: 0 4px 12px ${config.color}40 !important; }`;document.head.appendChild(style);const widget = document.createElement('div');widget.id = 'luogu-pomodoro-widget';widget.style.left = `${config.position.x}px`;widget.style.top = `${config.position.y}px`;widget.innerHTML = `<div id="luogu-pomodoro-time">25:00</div><div id="luogu-pomodoro-progress"><div id="luogu-pomodoro-progress-bar"></div></div><div id="luogu-pomodoro-controls"><button class="pomodoro-btn start">开始</button><button class="pomodoro-btn stop">结束</button></div><div id="luogu-pomodoro-settings"><svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19.14 12.94c.04-.31.06-.63.06-.94 0-.31-.02-.63-.06-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.04.31-.06.63-.06.94s.02.63.06.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z"/></svg></div>`;document.body.appendChild(widget);const settingsBtn = widget.querySelector('#luogu-pomodoro-settings');settingsBtn.onclick = (e) => { e.stopPropagation(); createSettingUI(); };let timer = null;let remainingTime = workDuration * 60;let currentMode = 'work';let isResuming = false;let autoStart = false;const savedMode = localStorage.getItem(STORAGE_KEY_CURRENT_MODE);if (savedMode === 'rest') { currentMode = 'rest'; remainingTime = restDuration * 60; }const timeDisplay = widget.querySelector('#luogu-pomodoro-time');const progressBar = widget.querySelector('#luogu-pomodoro-progress-bar');const startBtn = widget.querySelector('.pomodoro-btn.start');const stopBtn = widget.querySelector('.pomodoro-btn.stop');const savedState = localStorage.getItem(STORAGE_KEY_FOCUS_STATE);const savedRemaining = parseInt(localStorage.getItem(STORAGE_KEY_FOCUS_REMAINING) || '0');const endTime = parseInt(localStorage.getItem(STORAGE_KEY_FOCUS_END) || '0');const now = Date.now();if (savedState === 'paused' && savedRemaining > 0) { remainingTime = savedRemaining; isResuming = true; autoStart = false; }else if (savedState === 'running' && endTime > now) { remainingTime = Math.floor((endTime - now) / 1000); if (remainingTime > 0) { isResuming = true; autoStart = true; } }if (savedState === 'paused' && savedRemaining > 0) { startBtn.textContent = '继续'; startBtn.classList.add('pause'); startBtn.classList.remove('start'); startBtn.disabled = false; stopBtn.disabled = false; }else if (savedState === 'running' && endTime > now && remainingTime > 0) { startBtn.textContent = '暂停'; startBtn.classList.remove('pause'); startBtn.classList.add('start'); startBtn.disabled = false; stopBtn.disabled = false; }else { startBtn.textContent = '开始'; startBtn.classList.add('start'); startBtn.classList.remove('pause'); startBtn.disabled = false; stopBtn.disabled = (currentMode === 'work' && remainingTime === workDuration * 60); }function updateFocusBorderStyle() {if (timer && currentMode === 'work' && localStorage.getItem(STORAGE_KEY_FOCUS_STATE) !== 'paused') widget.classList.add('focus-running');else widget.classList.remove('focus-running');}function updateDisplay() {const mins = Math.floor(remainingTime / 60); const secs = remainingTime % 60;timeDisplay.textContent = `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;const totalSeconds = (currentMode === 'work' ? workDuration : restDuration) * 60;progressBar.style.width = `${Math.max(0, Math.min(100, ((totalSeconds - remainingTime) / totalSeconds) * 100))}%`;updateFocusBorderStyle();}function toggleTimer() {if (timer) {clearInterval(timer); timer = null; pauseFocusMode(remainingTime); localStorage.setItem(STORAGE_KEY_CURRENT_MODE, currentMode);isResuming = true; startBtn.textContent = '继续'; startBtn.classList.add('pause'); startBtn.classList.remove('start'); startBtn.disabled = false; stopBtn.disabled = false; updateFocusBorderStyle();} else {if (isResuming) { localStorage.setItem(STORAGE_KEY_FOCUS_END, (Date.now() + remainingTime * 1000).toString()); localStorage.setItem(STORAGE_KEY_FOCUS_STATE, 'running'); localStorage.setItem(STORAGE_KEY_CURRENT_MODE, currentMode); localStorage.removeItem(STORAGE_KEY_FOCUS_REMAINING); isResuming = false; }else { remainingTime = (currentMode === 'work' ? workDuration : restDuration) * 60; startFocusMode(currentMode === 'work' ? workDuration : restDuration, currentMode === 'work'); localStorage.setItem(STORAGE_KEY_CURRENT_MODE, currentMode); }startBtn.textContent = '暂停'; startBtn.classList.remove('pause'); startBtn.classList.add('start'); startBtn.disabled = false; stopBtn.disabled = false; updateFocusBorderStyle();timer = setInterval(() => { remainingTime--; updateDisplay(); if (remainingTime <= 0) { clearInterval(timer); timer = null; if (currentMode === 'work') { currentMode = 'rest'; remainingTime = restDuration * 60; endFocusMode(); localStorage.setItem(STORAGE_KEY_CURRENT_MODE, 'rest'); startBtn.textContent = '开始'; startBtn.classList.add('start'); startBtn.classList.remove('pause'); startBtn.disabled = false; stopBtn.disabled = false; alert('工作阶段完成!进入休息。'); } else { endFocusMode(); startBtn.textContent = '开始'; startBtn.classList.add('start'); startBtn.classList.remove('pause'); startBtn.disabled = false; stopBtn.disabled = true; currentMode = 'work'; remainingTime = workDuration * 60; alert('休息结束!准备开始新的工作。'); } updateDisplay(); } }, 1000);}}function stopTimer() { clearInterval(timer); timer = null; remainingTime = workDuration * 60; currentMode = 'work'; isResuming = false; updateDisplay(); endFocusMode(); startBtn.textContent = '开始'; startBtn.classList.add('start'); startBtn.classList.remove('pause'); startBtn.disabled = false; stopBtn.disabled = true; }startBtn.onclick = toggleTimer; stopBtn.onclick = stopTimer;let isDragging = false; let offsetX, offsetY;widget.onmousedown = (e) => { if (e.target.id === 'luogu-pomodoro-settings') return; isDragging = true; const rect = widget.getBoundingClientRect(); offsetX = e.clientX - rect.left; offsetY = e.clientY - rect.top; widget.style.cursor = 'move'; e.preventDefault(); };document.onmousemove = (e) => { if (!isDragging) return; widget.style.left = `${Math.max(0, Math.min(e.clientX - offsetX, window.innerWidth - widget.offsetWidth))}px`; widget.style.top = `${Math.max(0, Math.min(e.clientY - offsetY, window.innerHeight - widget.offsetHeight))}px`; };document.onmouseup = () => { if (isDragging) { isDragging = false; widget.style.cursor = 'default'; const rect = widget.getBoundingClientRect(); saveFocusPosition({ x: Math.round(rect.left), y: Math.round(rect.top) }); } };updateDisplay(); if (autoStart) setTimeout(() => toggleTimer(), 300);}function createSettingUI() {if (!/^(https?:\/\/)?(www\.)?luogu\.com\.cn/i.test(window.location.href)) return;['luogu-modal-mask','luogu-modal-box'].forEach(id => { const el = document.getElementById(id); if(el) el.remove(); });const style = document.createElement('style');style.textContent = `#luogu-modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99997; display: none; backdrop-filter: blur(3px); }#luogu-modal-box { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 400px; max-width: 92vw; padding: 20px; background: #fff; border-radius: 14px; z-index: 99998; display: none; box-shadow: 0 8px 24px rgba(0,0,0,0.2); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }#luogu-modal-box *, #luogu-modal-box *::before, #luogu-modal-box *::after { box-sizing: border-box; }#luogu-modal-box h3 { margin: 0 0 16px; color: #111; text-align: center; font-size: 22px; font-weight: 700; border-bottom: 1px solid #f3f4f6; padding-bottom: 12px; }.luogu-form-group { margin-bottom: 12px; }.luogu-form-group label { display: block; margin-bottom: 6px; font-weight: 600; color: #333; font-size: 15px; }#luogu-pid-input { width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 8px; font-size: 14px; transition: border-color 0.2s; }#luogu-pid-input:focus { border-color: #3b82f6; outline: none; box-shadow: 0 0 0 2px rgba(59,130,246,0.1); }.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; background: #f8fafc; border-radius: 8px; border: 1px solid #f1f5f9; }.switch-text { font-size: 14px; color: #475569; }.switch-toggle { position: relative; width: 44px; height: 24px; }.switch-toggle input { opacity: 0; width: 0; height: 0; }.switch-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #cbd5e1; transition: .2s; border-radius: 24px; }.switch-slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .2s; border-radius: 50%; }input:checked + .switch-slider { background-color: #3b82f6; }input:checked + .switch-slider:before { transform: translateX(20px); }.duration-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }.duration-input-wrap label { font-size: 13px; color: #64748b; margin-bottom: 4px; font-weight: 400; }.duration-input { width: 100%; padding: 8px 10px; border: 1px solid #ddd; border-radius: 6px; font-size: 14px; }.duration-input:focus { outline: none; border-color: #3b82f6; }.pid-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; min-height: 32px; }.pid-item { background: #eef2ff; border: 1px solid #e0e7ff; color: #4338ca; padding: 5px 10px; border-radius: 14px; font-size: 13px; display: flex; align-items: center; gap: 6px; cursor: pointer; transition: all 0.2s; }.pid-item:hover { background: #e0e7ff; transform: translateY(-1px); }.pid-item .remove { color: #ef4444; font-weight: bold; cursor: pointer; line-height: 1; }#luogu-color-input { width: 100%; height: 32px; padding: 2px; border: 1px solid #ddd; border-radius: 6px; cursor: pointer; background: #fff; }.luogu-hint { font-size: 12px; color: #94a3b8; margin-top: 4px; line-height: 1.4; }#luogu-modal-btn-group { display: grid; grid-template-columns: 1fr 1.2fr; gap: 10px; margin-top: 16px; }#luogu-save-btn, #luogu-cancel-btn { padding: 10px; border: none; border-radius: 8px; cursor: pointer; font-size: 15px; font-weight: 600; transition: all 0.2s; }#luogu-save-btn { background: #3b82f6; color: white; }#luogu-save-btn:hover { background: #2563eb; transform: translateY(-1px); box-shadow: 0 2px 8px rgba(59,130,246,0.3); }#luogu-cancel-btn { background: #f1f5f9; color: #475569; }#luogu-cancel-btn:hover { background: #e2e8f0; }`;document.head.appendChild(style);const mask = document.createElement('div'); mask.id = 'luogu-modal-mask';mask.onclick = () => { mask.style.display = 'none'; modalBox.style.display = 'none'; };document.body.appendChild(mask);const modalBox = document.createElement('div'); modalBox.id = 'luogu-modal-box';modalBox.innerHTML = `<h3>专注设置</h3><div class="luogu-form-group"><label>题目计划</label><input type="text" id="luogu-pid-input" placeholder="输入题号(如:P1000、CF1628D、AT_abc001_a)"><div class="pid-list" id="pid-list"></div><div class="luogu-hint">最多 6 题,回车添加。支持 Luogu/CF/AtCoder/UVA 等。</div></div><div class="luogu-form-group"><label>题解访问</label><div class="switch-row"><span class="switch-text">允许查看题解</span><label class="switch-toggle"><input type="checkbox" id="luogu-solution-checkbox"><span class="switch-slider"></span></label></div></div><div class="luogu-form-group"><label>番茄钟时长(分钟)</label><div class="duration-grid"><div class="duration-input-wrap"><label>工作</label><input type="number" id="luogu-work-input" class="duration-input" min="1" max="120"></div><div class="duration-input-wrap"><label>休息</label><input type="number" id="luogu-rest-input" class="duration-input" min="1" max="60"></div></div></div><div class="luogu-form-group"><label>主题颜色</label><input type="color" id="luogu-color-input"></div><div id="luogu-modal-btn-group"><button id="luogu-cancel-btn">取消</button><button id="luogu-save-btn">保存配置</button></div>`;document.body.appendChild(modalBox);function renderPidList() {const list = document.getElementById('pid-list'); list.innerHTML = '';const pids = getSavePids();if (!pids.length) { list.innerHTML = '<div style="text-align:center;color:#cbd5e1;width:100%;padding:4px;font-size:13px">暂无题目</div>'; return; }pids.forEach((pid, idx) => {const item = document.createElement('div'); item.className = 'pid-item';item.innerHTML = `${pid}<span class="remove">×</span>`;item.onclick = (e) => { if (!e.target.classList.contains('remove')) window.location.href = `https://www.luogu.com.cn/problem/${pid}`; };item.querySelector('.remove').onclick = (e) => { e.stopPropagation(); removePid(pid); renderPidList(); };list.appendChild(item);});}function doSave() {const raw = document.getElementById('luogu-pid-input').value.trim();const pid = raw.startsWith('AT_') ? raw : raw.toUpperCase();const solChecked = document.getElementById('luogu-solution-checkbox').checked;const work = parseInt(document.getElementById('luogu-work-input').value) || DEFAULT_WORK_DURATION;const rest = parseInt(document.getElementById('luogu-rest-input').value) || DEFAULT_REST_DURATION;const color = document.getElementById('luogu-color-input').value;if (work < 1 || work > 120) { alert('工作时长 1-120'); return; }if (rest < 1 || rest > 60) { alert('休息时长 1-60'); return; }// 修复正则,放宽 CF 及通用格式匹配,防止报错if (pid && !/^(P\d{3,6}|SP\d{3,5}|B\d{3,5}|CF\d+[A-Z0-9]*|AT_[a-z0-9_]+|UVA\d{3,5}|[A-Z]{2,6}\d+[A-Z0-9]*)$/i.test(pid)) {alert('题号格式错误'); return;}const pids = getSavePids();if (pid && pids.length < MAX_PIDS && !pids.includes(pid)) { pids.push(pid); savePids(pids); }saveSolutionStatus(solChecked); saveDurations(work, rest); saveFocusColor(color);document.getElementById('luogu-pid-input').value = ''; renderPidList(); monitorSolutionElements();mask.style.display = 'none'; modalBox.style.display = 'none';}document.getElementById('luogu-save-btn').onclick = doSave;document.getElementById('luogu-cancel-btn').onclick = () => { mask.style.display = 'none'; modalBox.style.display = 'none'; };document.getElementById('luogu-pid-input').onkeypress = (e) => { if (e.key === 'Enter') doSave(); };mask.style.display = 'block'; modalBox.style.display = 'block';document.getElementById('luogu-solution-checkbox').checked = getSolutionStatus();document.getElementById('luogu-work-input').value = getWorkDuration();document.getElementById('luogu-rest-input').value = getRestDuration();document.getElementById('luogu-color-input').value = getFocusColor();renderPidList();}function initRouterGuard() {let lastPath = window.location.pathname + window.location.hash;const _push = history.pushState; const _replace = history.replaceState;history.pushState = function(){ _push.apply(this, arguments); window.dispatchEvent(new Event('locationchange')); };history.replaceState = function(){ _replace.apply(this, arguments); window.dispatchEvent(new Event('locationchange')); };window.addEventListener('popstate', () => window.dispatchEvent(new Event('locationchange')));window.addEventListener('locationchange', () => { if (blockSolutionAccess()) return; if (isFocusActive() && !shouldAllow()) window.location.replace(getRedirectUrl()); });setInterval(() => {const cur = window.location.pathname + window.location.hash;if (cur !== lastPath) { lastPath = cur; if (blockSolutionAccess()) return; if (isFocusActive() && !shouldAllow()) window.location.replace(getRedirectUrl()); }}, 800);}enforceAccessRules();if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', createPomodoroWidget);else createPomodoroWidget();window.addEventListener('load', () => { monitorSolutionElements(); initRouterGuard(); });})();```:::## $\textup{Upd on 2026.7.14}$修复目前已知的 bug,诸如题目添加等。并且优化了前端的主题功能,更加适配新的洛谷主题。:::success[$\textup{V4 Code.}$]```// ==UserScript==// @name 洛谷强力学术Pro// @namespace http://tampermonkey.net/// @version 10.62// @author wendywan// @icon https://cdn.luogu.com.cn/upload/image_hosting/psd5a03h.png// @match *://*/*// @grant none// @license MIT// @run-at document-start// ==/UserScript==(function() {'use strict';const STORAGE_KEY_PID = "luogu_study_plan_pids";const STORAGE_KEY_SOLUTION = "luogu_study_plan_solution";const STORAGE_KEY_FOCUS_ACTIVE = "luogu_focus_active";const STORAGE_KEY_FOCUS_END = "luogu_focus_end_time";const STORAGE_KEY_FOCUS_DURATION = "luogu_focus_duration";const STORAGE_KEY_FOCUS_COLOR = "luogu_focus_color";const STORAGE_KEY_FOCUS_POS = "luogu_focus_position";const STORAGE_KEY_FOCUS_REMAINING = "luogu_focus_remaining";const STORAGE_KEY_FOCUS_STATE = "luogu_focus_state";const STORAGE_KEY_REST_DURATION = "luogu_rest_duration";const STORAGE_KEY_CURRENT_MODE = "luogu_focus_current_mode";const DEFAULT_WORK_DURATION = 25;const DEFAULT_REST_DURATION = 5;const DEFAULT_COLOR = "#ff6b6b";const DEFAULT_POSITION = { x: 20, y: 100 };const DEFAULT_SIZE = { width: 120, height: 100 };const MAX_PIDS = 6;// 颜色调整辅助函数function adjustColor(hex, percent) {const num = parseInt(hex.replace('#', ''), 16);const amt = Math.round(2.55 * percent);const R = Math.max(0, Math.min(255, (num >> 16) + amt));const G = Math.max(0, Math.min(255, ((num >> 8) & 0x00FF) + amt));const B = Math.max(0, Math.min(255, (num & 0x0000FF) + amt));return '#' + [R, G, B].map(x => x.toString(16).padStart(2, '0')).join('');}// 对比度检测,决定按钮上的文字颜色是黑还是白function getContrastYIQ(hexcolor) {hexcolor = hexcolor.replace("#", "");const r = parseInt(hexcolor.substr(0,2),16);const g = parseInt(hexcolor.substr(2,2),16);const b = parseInt(hexcolor.substr(4,2),16);const yiq = ((r*299)+(g*587)+(b*114))/1000;return (yiq >= 128) ? '#111111' : '#ffffff';}// 根据颜色明度动态计算几何图形透明度function getAdaptiveOpacity(hex) {const c = hex.replace('#', '');const r = parseInt(c.substr(0, 2), 16);const g = parseInt(c.substr(2, 2), 16);const b = parseInt(c.substr(4, 2), 16);const l = (0.299 * r + 0.587 * g + 0.114 * b) / 255;return Math.max(0.18, Math.min(0.40, 0.40 - (l * 0.22))).toFixed(2);}function getSavePids() {try {const pids = JSON.parse(localStorage.getItem(STORAGE_KEY_PID)) || [];return pids.filter(pid => pid.trim() !== '');} catch {return [];}}function savePids(pids) {localStorage.setItem(STORAGE_KEY_PID, JSON.stringify(pids));}function removePid(pid) {const pids = getSavePids();const index = pids.indexOf(pid);if (index !== -1) {pids.splice(index, 1);savePids(pids);return true;}return false;}function getSolutionStatus() {return localStorage.getItem(STORAGE_KEY_SOLUTION) !== 'false';}function saveSolutionStatus(status) {localStorage.setItem(STORAGE_KEY_SOLUTION, status);}function isFocusActive() {const active = localStorage.getItem(STORAGE_KEY_FOCUS_ACTIVE) === 'true';if (!active) return false;const state = localStorage.getItem(STORAGE_KEY_FOCUS_STATE);if (state === 'paused') {return true;}const endTime = parseInt(localStorage.getItem(STORAGE_KEY_FOCUS_END) || '0');const now = Date.now();if (active && now >= endTime) {endFocusMode();return false;}return active;}function startFocusMode(durationMinutes, isWorkMode) {const endTime = Date.now() + durationMinutes * 60 * 1000;localStorage.setItem(STORAGE_KEY_FOCUS_ACTIVE, 'true');localStorage.setItem(STORAGE_KEY_FOCUS_END, endTime.toString());if (isWorkMode) {localStorage.setItem(STORAGE_KEY_FOCUS_DURATION, durationMinutes.toString());}localStorage.setItem(STORAGE_KEY_FOCUS_STATE, 'running');localStorage.removeItem(STORAGE_KEY_FOCUS_REMAINING);}function pauseFocusMode(remainingSeconds) {localStorage.setItem(STORAGE_KEY_FOCUS_STATE, 'paused');localStorage.setItem(STORAGE_KEY_FOCUS_REMAINING, remainingSeconds.toString());localStorage.removeItem(STORAGE_KEY_FOCUS_END);}function endFocusMode() {localStorage.removeItem(STORAGE_KEY_FOCUS_ACTIVE);localStorage.removeItem(STORAGE_KEY_FOCUS_END);localStorage.removeItem(STORAGE_KEY_FOCUS_STATE);localStorage.removeItem(STORAGE_KEY_FOCUS_REMAINING);localStorage.removeItem(STORAGE_KEY_CURRENT_MODE);}function getWorkDuration() {return parseInt(localStorage.getItem(STORAGE_KEY_FOCUS_DURATION) || DEFAULT_WORK_DURATION);}function getRestDuration() {return parseInt(localStorage.getItem(STORAGE_KEY_REST_DURATION) || DEFAULT_REST_DURATION);}function saveDurations(work, rest) {localStorage.setItem(STORAGE_KEY_FOCUS_DURATION, work.toString());localStorage.setItem(STORAGE_KEY_REST_DURATION, rest.toString());}function getFocusColor() {return localStorage.getItem(STORAGE_KEY_FOCUS_COLOR) || DEFAULT_COLOR;}function saveFocusColor(color) {localStorage.setItem(STORAGE_KEY_FOCUS_COLOR, color);}function getFocusPosition() {try {return JSON.parse(localStorage.getItem(STORAGE_KEY_FOCUS_POS) || JSON.stringify(DEFAULT_POSITION));} catch {return DEFAULT_POSITION;}}function saveFocusPosition(pos) {localStorage.setItem(STORAGE_KEY_FOCUS_POS, JSON.stringify(pos));}function getRedirectUrl() {const pids = getSavePids();return pids.length > 0? `https://www.luogu.com.cn/problem/${pids[0]}`: 'https://www.luogu.com.cn/problem/list';}function shouldAllow() {const currentURL = window.location.href;const isLuoguDomain = /^(https?:\/\/)?(www\.)?luogu\.com\.cn/i.test(currentURL);if (!isLuoguDomain) return true;if (!isFocusActive()) return true;const state = localStorage.getItem(STORAGE_KEY_FOCUS_STATE);if (state === 'paused') return true;const currentMode = localStorage.getItem(STORAGE_KEY_CURRENT_MODE);if (currentMode === 'rest') return true;const path = window.location.pathname.toLowerCase();const allowedProblem = /^\/problem\//i.test(path);const allowedPaste = /^\/paste(\/.*)?$/i.test(path);const allowedRecord = /^\/record\//i.test(path);if (/\/problem\/solution\//i.test(path)) {return getSolutionStatus();}return allowedProblem || allowedPaste || allowedRecord;}function blockSolutionAccess() {const path = window.location.pathname.toLowerCase();if (/\/problem\/solution\//i.test(path)) {if (!getSolutionStatus()) {window.location.replace(getRedirectUrl());return true;}}return false;}function enforceAccessRules() {if (blockSolutionAccess()) return true;if (isFocusActive() && !shouldAllow()) {window.location.replace(getRedirectUrl());return true;}return false;}function monitorSolutionElements() {if (!getSolutionStatus()) {const observer = new MutationObserver((mutations) => {mutations.forEach(mutation => {mutation.addedNodes.forEach(node => {if (node.nodeType !== 1) return;const selectors = ['a[href*="/problem/solution/"]','[class*="solution"]','[class*="answer"]','.lg-article-content'];try {node.querySelectorAll(selectors.join(',')).forEach(el => {if ((el.textContent && el.textContent.includes('题解')) ||(el.href && el.href.includes('/problem/solution/'))) {el.style.display = 'none';el.style.visibility = 'hidden';el.style.height = '0';el.style.overflow = 'hidden';el.style.pointerEvents = 'none';}});} catch (e) {}});});});if (document.body) observer.observe(document.body, { childList: true, subtree: true });else document.addEventListener('DOMContentLoaded', () => observer.observe(document.body, { childList: true, subtree: true }));}}function createPomodoroWidget() {if (!/^(https?:\/\/)?(www\.)?luogu\.com\.cn/i.test(window.location.href)) return;const workDuration = getWorkDuration();const restDuration = getRestDuration();const config = {workDuration: workDuration,restDuration: restDuration,color: getFocusColor(),position: getFocusPosition()};// --- 动态配色方案 ---const mainColor = config.color;const lightColor = adjustColor(mainColor, 85); // 浅色背景const darkColor = adjustColor(mainColor, -20); // 深色文字const textColor = getContrastYIQ(mainColor); // 主按钮上的文字颜色const secondaryTextColor = getContrastYIQ(lightColor); // 次级按钮上的文字颜色const style = document.createElement('style');style.textContent = `#luogu-pomodoro-widget {position: fixed; z-index: 99999; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.15);overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", sans-serif;user-select: none; width: ${DEFAULT_SIZE.width}px; height: ${DEFAULT_SIZE.height}px;background: white; border: 1px solid #e0e0e0; cursor: move; transition: border-color 0.3s ease, box-shadow 0.3s ease;}#luogu-pomodoro-widget:hover { box-shadow: 0 3px 15px rgba(0,0,0,0.2); }#luogu-pomodoro-time { font-size: 20px; font-weight: bold; text-align: center; color: #333; padding: 12px 0; height: 40px; display: flex; align-items: center; justify-content: center; }#luogu-pomodoro-progress { height: 4px; background: #f0f0f0; border-radius: 2px; margin: 4px 8px; overflow: hidden; }#luogu-pomodoro-progress-bar { height: 100%; width: 0%; background: ${mainColor}; border-radius: 2px; transition: width 0.5s ease; }#luogu-pomodoro-controls { display: flex; justify-content: center; gap: 6px; padding: 6px 0; background: #f8f9fa; border-top: 1px solid #eee; }.pomodoro-btn { width: 48%; height: 22px; border: none; border-radius: 3px; font-size: 11px; font-weight: 500; cursor: pointer; transition: all 0.2s; user-select: none; text-align: center; line-height: 22px; }.pomodoro-btn:active { transform: scale(0.95); }/* 主要按钮:主色背景 */.pomodoro-btn.primary { background: ${mainColor}; color: ${textColor}; }.pomodoro-btn.primary:hover { filter: brightness(0.9); }/* 次要按钮:浅色背景 */.pomodoro-btn.secondary { background: ${lightColor}; color: ${darkColor}; }.pomodoro-btn.secondary:hover { filter: brightness(0.95); }.pomodoro-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none !important; }#luogu-pomodoro-settings { position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; border-radius: 6px; background: ${mainColor}; display: flex; align-items: center; justify-content: center; font-size: 14px; cursor: pointer; z-index: 10; transition: all 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }#luogu-pomodoro-settings:hover { transform: scale(1.1); box-shadow: 0 2px 6px rgba(0,0,0,0.3); }#luogu-pomodoro-settings svg { width: 14px; height: 14px; fill: white; }#luogu-pomodoro-widget.focus-running { border: 2px solid ${mainColor} !important; box-shadow: 0 4px 12px ${mainColor}40 !important; }`;document.head.appendChild(style);const widget = document.createElement('div');widget.id = 'luogu-pomodoro-widget';widget.style.left = `${config.position.x}px`;widget.style.top = `${config.position.y}px`;widget.innerHTML = `<div id="luogu-pomodoro-time">25:00</div><div id="luogu-pomodoro-progress"><div id="luogu-pomodoro-progress-bar"></div></div><div id="luogu-pomodoro-controls"><button class="pomodoro-btn primary" id="btn-start">开始</button><button class="pomodoro-btn secondary" id="btn-stop">结束</button></div><div id="luogu-pomodoro-settings"><svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19.14 12.94c.04-.31.06-.63.06-.94 0-.31-.02-.63-.06-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.04.31-.06.63-.06.94s.02.63.06.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z"/></svg></div>`;document.body.appendChild(widget);const settingsBtn = widget.querySelector('#luogu-pomodoro-settings');settingsBtn.onclick = (e) => { e.stopPropagation(); createSettingUI(); };let timer = null;let remainingTime = workDuration * 60;let currentMode = 'work';let isResuming = false;let autoStart = false;const savedMode = localStorage.getItem(STORAGE_KEY_CURRENT_MODE);if (savedMode === 'rest') { currentMode = 'rest'; remainingTime = restDuration * 60; }const timeDisplay = widget.querySelector('#luogu-pomodoro-time');const progressBar = widget.querySelector('#luogu-pomodoro-progress-bar');const startBtn = widget.querySelector('#btn-start');const stopBtn = widget.querySelector('#btn-stop');const savedState = localStorage.getItem(STORAGE_KEY_FOCUS_STATE);const savedRemaining = parseInt(localStorage.getItem(STORAGE_KEY_FOCUS_REMAINING) || '0');const endTime = parseInt(localStorage.getItem(STORAGE_KEY_FOCUS_END) || '0');const now = Date.now();if (savedState === 'paused' && savedRemaining > 0) { remainingTime = savedRemaining; isResuming = true; autoStart = false; }else if (savedState === 'running' && endTime > now) { remainingTime = Math.floor((endTime - now) / 1000); if (remainingTime > 0) { isResuming = true; autoStart = true; } }if (savedState === 'paused' && savedRemaining > 0) { startBtn.textContent = '继续'; startBtn.disabled = false; stopBtn.disabled = false; }else if (savedState === 'running' && endTime > now && remainingTime > 0) { startBtn.textContent = '暂停'; startBtn.disabled = false; stopBtn.disabled = false; }else { startBtn.textContent = '开始'; startBtn.disabled = false; stopBtn.disabled = (currentMode === 'work' && remainingTime === workDuration * 60); }function updateFocusBorderStyle() {if (timer && currentMode === 'work' && localStorage.getItem(STORAGE_KEY_FOCUS_STATE) !== 'paused') widget.classList.add('focus-running');else widget.classList.remove('focus-running');}function updateDisplay() {const mins = Math.floor(remainingTime / 60); const secs = remainingTime % 60;timeDisplay.textContent = `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;const totalSeconds = (currentMode === 'work' ? workDuration : restDuration) * 60;progressBar.style.width = `${Math.max(0, Math.min(100, ((totalSeconds - remainingTime) / totalSeconds) * 100))}%`;updateFocusBorderStyle();}function toggleTimer() {if (timer) {clearInterval(timer); timer = null; pauseFocusMode(remainingTime); localStorage.setItem(STORAGE_KEY_CURRENT_MODE, currentMode);isResuming = true; startBtn.textContent = '继续'; startBtn.disabled = false; stopBtn.disabled = false; updateFocusBorderStyle();} else {if (isResuming) { localStorage.setItem(STORAGE_KEY_FOCUS_END, (Date.now() + remainingTime * 1000).toString()); localStorage.setItem(STORAGE_KEY_FOCUS_STATE, 'running'); localStorage.setItem(STORAGE_KEY_CURRENT_MODE, currentMode); localStorage.removeItem(STORAGE_KEY_FOCUS_REMAINING); isResuming = false; }else { remainingTime = (currentMode === 'work' ? workDuration : restDuration) * 60; startFocusMode(currentMode === 'work' ? workDuration : restDuration, currentMode === 'work'); localStorage.setItem(STORAGE_KEY_CURRENT_MODE, currentMode); }startBtn.textContent = '暂停'; startBtn.disabled = false; stopBtn.disabled = false; updateFocusBorderStyle();timer = setInterval(() => {remainingTime--;updateDisplay();if (remainingTime <= 0) {// --- 自动进入下一阶段逻辑 ---// 切换模式currentMode = (currentMode === 'work') ? 'rest' : 'work';// 重置时间const nextDuration = (currentMode === 'work') ? workDuration : restDuration;remainingTime = nextDuration * 60;// 更新本地存储,保证跨页刷新时状态正确const newEndTime = Date.now() + remainingTime * 1000;localStorage.setItem(STORAGE_KEY_FOCUS_END, newEndTime.toString());localStorage.setItem(STORAGE_KEY_CURRENT_MODE, currentMode);// UI 更新updateDisplay();}}, 1000);}}function stopTimer() {clearInterval(timer); timer = null; remainingTime = workDuration * 60; currentMode = 'work'; isResuming = false; updateDisplay(); endFocusMode(); startBtn.textContent = '开始'; startBtn.disabled = false; stopBtn.disabled = true;}startBtn.onclick = toggleTimer; stopBtn.onclick = stopTimer;let isDragging = false; let offsetX, offsetY;widget.onmousedown = (e) => { if (e.target.id === 'luogu-pomodoro-settings') return; isDragging = true; const rect = widget.getBoundingClientRect(); offsetX = e.clientX - rect.left; offsetY = e.clientY - rect.top; widget.style.cursor = 'move'; e.preventDefault(); };document.onmousemove = (e) => { if (!isDragging) return; widget.style.left = `${Math.max(0, Math.min(e.clientX - offsetX, window.innerWidth - widget.offsetWidth))}px`; widget.style.top = `${Math.max(0, Math.min(e.clientY - offsetY, window.innerHeight - widget.offsetHeight))}px`; };document.onmouseup = () => { if (isDragging) { isDragging = false; widget.style.cursor = 'default'; const rect = widget.getBoundingClientRect(); saveFocusPosition({ x: Math.round(rect.left), y: Math.round(rect.top) }); } };updateDisplay(); if (autoStart) setTimeout(() => toggleTimer(), 300);}function createSettingUI() {if (!/^(https?:\/\/)?(www\.)?luogu\.com\.cn/i.test(window.location.href)) return;['luogu-modal-mask','luogu-modal-box'].forEach(id => { const el = document.getElementById(id); if(el) el.remove(); });const themeColor = getFocusColor();const geoOp = getAdaptiveOpacity(themeColor);const style = document.createElement('style');style.textContent = `#luogu-modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 99997; display: none; backdrop-filter: blur(2px); }#luogu-modal-box { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 400px; max-width: 92vw; padding: 20px;background: rgba(255, 255, 255, 0.65);backdrop-filter: blur(15px);-webkit-backdrop-filter: blur(15px);border: 1px solid rgba(255, 255, 255, 0.6);box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);border-radius: 16px; z-index: 99998; display: none;font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;transition: all 0.3s;overflow: hidden;}#luogu-modal-box *, #luogu-modal-box *::before, #luogu-modal-box *::after { box-sizing: border-box; }.modal-inner { position: relative; z-index: 2; }.bg-geo { position: absolute; pointer-events: none; z-index: 1; filter: blur(1px); transition: opacity 0.4s; }#luogu-modal-box h3 { margin: 0 0 16px; color: #111; text-align: center; font-size: 22px; font-weight: 700; border-bottom: 1px solid rgba(0,0,0,0.1); padding-bottom: 12px; }.luogu-form-group { margin-bottom: 12px; }.luogu-form-group label { display: block; margin-bottom: 6px; font-weight: 600; color: #333; font-size: 15px; }#luogu-pid-input { width: 100%; padding: 10px 12px; border: 1px solid rgba(0,0,0,0.1); border-radius: 8px; font-size: 14px; transition: border-color 0.2s; background: rgba(255,255,255,0.5); }#luogu-pid-input:focus { border-color: ${themeColor}; outline: none; box-shadow: 0 0 0 2px ${themeColor}44; background: rgba(255,255,255,0.8); }.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; background: rgba(248, 250, 252, 0.5); border-radius: 8px; border: 1px solid rgba(241, 245, 249, 0.6); }.switch-text { font-size: 14px; color: #374151; }.switch-toggle { position: relative; width: 44px; height: 24px; }.switch-toggle input { opacity: 0; width: 0; height: 0; }.switch-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #cbd5e1; transition: .2s; border-radius: 24px; }.switch-slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .2s; border-radius: 50%; }input:checked + .switch-slider { background: linear-gradient(135deg, ${themeColor}, ${themeColor}cc); }input:checked + .switch-slider:before { transform: translateX(20px); }.duration-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }.duration-input-wrap label { font-size: 13px; color: #64748b; margin-bottom: 4px; font-weight: 400; }.duration-input { width: 100%; padding: 8px 10px; border: 1px solid rgba(0,0,0,0.1); border-radius: 6px; font-size: 14px; background: rgba(255,255,255,0.5); }.duration-input:focus { outline: none; border-color: ${themeColor}; background: rgba(255,255,255,0.8); }.pid-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; min-height: 32px; }.pid-item { background: linear-gradient(135deg, rgba(238, 242, 255, 0.8), ${themeColor}20); border: 1px solid ${themeColor}40; color: ${themeColor}; padding: 5px 10px; border-radius: 14px; font-size: 13px; display: flex; align-items: center; gap: 6px; cursor: pointer; transition: all 0.2s; }.pid-item:hover { background: linear-gradient(135deg, #e0e7ff, ${themeColor}25); transform: translateY(-1px); }.pid-item .remove { color: #ef4444; font-weight: bold; cursor: pointer; line-height: 1; }#luogu-color-input { width: 100%; height: 32px; padding: 2px; border: 1px solid rgba(0,0,0,0.1); border-radius: 6px; cursor: pointer; background: rgba(255,255,255,0.5); }.luogu-hint { font-size: 12px; color: #64748b; margin-top: 4px; line-height: 1.4; }#luogu-modal-btn-group { display: grid; grid-template-columns: 1fr 1.2fr; gap: 10px; margin-top: 16px; }#luogu-save-btn, #luogu-cancel-btn { padding: 10px; border: none; border-radius: 8px; cursor: pointer; font-size: 15px; font-weight: 600; transition: all 0.2s; }#luogu-save-btn { background: linear-gradient(135deg, ${themeColor}, ${themeColor}bb); color: white; box-shadow: 0 2px 8px ${themeColor}44; }#luogu-save-btn:hover { background: linear-gradient(135deg, ${themeColor}dd, ${themeColor}aa); transform: translateY(-1px); box-shadow: 0 4px 12px ${themeColor}66; }#luogu-cancel-btn { background: rgba(241, 245, 249, 0.6); color: #4b5563; }#luogu-cancel-btn:hover { background: rgba(226, 232, 240, 0.8); }`;document.head.appendChild(style);const mask = document.createElement('div'); mask.id = 'luogu-modal-mask';mask.onclick = () => { mask.style.display = 'none'; modalBox.style.display = 'none'; };document.body.appendChild(mask);const modalBox = document.createElement('div'); modalBox.id = 'luogu-modal-box';modalBox.innerHTML = `<div class="bg-geo" style="top:-30px; right:-30px; width:130px; height:130px; border-radius:50%; background:${themeColor}; opacity:${geoOp};"></div><div class="bg-geo" style="bottom:-20px; left:-25px; width:100px; height:100px; transform:rotate(45deg); border-radius:16px; background:${themeColor}; opacity:${(geoOp * 0.75).toFixed(2)};"></div><div class="bg-geo" style="top:40%; right:25px; width:0; height:0; border-left:30px solid transparent; border-right:30px solid transparent; border-bottom:50px solid ${themeColor}; opacity:${(geoOp * 0.85).toFixed(2)}; transform:rotate(-15deg);"></div><div class="bg-geo" style="top:15%; left:-20px; width:60px; height:60px; border-radius:50%; border: 6px solid ${themeColor}; opacity:${(geoOp * 0.6).toFixed(2)};"></div><div class="modal-inner"><h3>专注设置</h3><div class="luogu-form-group"><label>题目计划</label><input type="text" id="luogu-pid-input" placeholder="输入题号(如:P1000、CF1628D、AT_abc001_a)"><div class="pid-list" id="pid-list"></div><div class="luogu-hint">最多 6 题,回车添加。支持 Luogu/CF/AtCoder/UVA 等。</div></div><div class="luogu-form-group"><label>题解访问</label><div class="switch-row"><span class="switch-text">允许查看题解</span><label class="switch-toggle"><input type="checkbox" id="luogu-solution-checkbox"><span class="switch-slider"></span></label></div></div><div class="luogu-form-group"><label>番茄钟时长(分钟)</label><div class="duration-grid"><div class="duration-input-wrap"><label>工作</label><input type="number" id="luogu-work-input" class="duration-input" min="1" max="120"></div><div class="duration-input-wrap"><label>休息</label><input type="number" id="luogu-rest-input" class="duration-input" min="1" max="60"></div></div></div><div class="luogu-form-group"><label>主题颜色</label><input type="color" id="luogu-color-input"></div><div id="luogu-modal-btn-group"><button id="luogu-cancel-btn">取消</button><button id="luogu-save-btn">保存配置</button></div></div>`;document.body.appendChild(modalBox);function renderPidList() {const list = document.getElementById('pid-list'); list.innerHTML = '';const pids = getSavePids();if (!pids.length) { list.innerHTML = '<div style="text-align:center;color:#cbd5e1;width:100%;padding:4px;font-size:13px">暂无题目</div>'; return; }pids.forEach((pid, idx) => {const item = document.createElement('div'); item.className = 'pid-item';item.innerHTML = `${pid}<span class="remove">×</span>`;item.onclick = (e) => { if (!e.target.classList.contains('remove')) window.location.href = `https://www.luogu.com.cn/problem/${pid}`; };item.querySelector('.remove').onclick = (e) => { e.stopPropagation(); removePid(pid); renderPidList(); };list.appendChild(item);});}function doSave() {const raw = document.getElementById('luogu-pid-input').value.trim();const pid = raw.startsWith('AT_') ? raw : raw.toUpperCase();const solChecked = document.getElementById('luogu-solution-checkbox').checked;const work = parseInt(document.getElementById('luogu-work-input').value) || DEFAULT_WORK_DURATION;const rest = parseInt(document.getElementById('luogu-rest-input').value) || DEFAULT_REST_DURATION;const color = document.getElementById('luogu-color-input').value;if (work < 1 || work > 120) { alert('工作时长 1-120'); return; }if (rest < 1 || rest > 60) { alert('休息时长 1-60'); return; }if (pid && !/^(P\d{3,6}|SP\d{3,5}|B\d{3,5}|CF\d+[A-Z0-9]*|AT_[a-z0-9_]+|UVA\d{3,5}|[A-Z]{2,6}\d+[A-Z0-9]*)$/i.test(pid)) {alert('题号格式错误'); return;}const pids = getSavePids();if (pid && pids.length < MAX_PIDS && !pids.includes(pid)) { pids.push(pid); savePids(pids); }saveSolutionStatus(solChecked); saveDurations(work, rest); saveFocusColor(color);document.getElementById('luogu-pid-input').value = ''; renderPidList(); monitorSolutionElements();mask.style.display = 'none'; modalBox.style.display = 'none';}document.getElementById('luogu-save-btn').onclick = doSave;document.getElementById('luogu-cancel-btn').onclick = () => { mask.style.display = 'none'; modalBox.style.display = 'none'; };document.getElementById('luogu-pid-input').onkeypress = (e) => { if (e.key === 'Enter') doSave(); };mask.style.display = 'block'; modalBox.style.display = 'block';document.getElementById('luogu-solution-checkbox').checked = getSolutionStatus();document.getElementById('luogu-work-input').value = getWorkDuration();document.getElementById('luogu-rest-input').value = getRestDuration();document.getElementById('luogu-color-input').value = getFocusColor();renderPidList();}function initRouterGuard() {let lastPath = window.location.pathname + window.location.hash;const _push = history.pushState; const _replace = history.replaceState;history.pushState = function(){ _push.apply(this, arguments); window.dispatchEvent(new Event('locationchange')); };history.replaceState = function(){ _replace.apply(this, arguments); window.dispatchEvent(new Event('locationchange')); };window.addEventListener('popstate', () => window.dispatchEvent(new Event('locationchange')));window.addEventListener('locationchange', () => { if (blockSolutionAccess()) return; if (isFocusActive() && !shouldAllow()) window.location.replace(getRedirectUrl()); });setInterval(() => {const cur = window.location.pathname + window.location.hash;if (cur !== lastPath) { lastPath = cur; if (blockSolutionAccess()) return; if (isFocusActive() && !shouldAllow()) window.location.replace(getRedirectUrl()); }}, 800);}enforceAccessRules();if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', createPomodoroWidget);else createPomodoroWidget();window.addEventListener('load', () => { monitorSolutionElements(); initRouterGuard(); });})();```:::---## $\textup{Upd on 2026.9.23}$修复目前已知的 bug,如钟面无法显示全等。添加调整透明度功能,添加强力学术(隔绝洛谷外的访问!终于实现了!)并对前端进行大力优化。:::success[$\textup{V5 Code.}$]```// ==UserScript==// @name 洛谷强力学术Pro// @namespace http://tampermonkey.net/// @version 10.68// @author wendywan// @icon https://cdn.luogu.com.cn/upload/image_hosting/psd5a03h.png// @description 洛谷专注模式:番茄钟阻断、题目计划、题解管控、网址白名单、可拖动钟面// @match *://*/*// @noframes// @grant GM_getValue// @grant GM_setValue4 行未改动(function () {'use strict';const KEY = { PIDS: 'luogu_study_plan_pids', SOLUTION: 'luogu_study_plan_solution', ACTIVE: 'luogu_focus_active', END: 'luogu_focus_end_time', WORK: 'luogu_focus_duration', REST: 'luogu_rest_duration', COLOR: 'luogu_focus_color', OPACITY: 'luogu_widget_opacity', POS: 'luogu_focus_position', REMAINING: 'luogu_focus_remaining', STATE: 'luogu_focus_state', MODE: 'luogu_focus_current_mode', URLWL: 'luogu_focus_url_whitelist', URLWL_ON: 'luogu_focus_url_whitelist_on', MIG: 'luogu_focus_migrated' };const DEFAULT = { WORK: 25, REST: 5, COLOR: '#ff6b6b', OPACITY: 0.9, POS: { x: 20, y: 100 }, WIDTH: 138, MAX_PIDS: 6, MAX_URLS: 10 };const PID_RE = /^(P\d{3,6}|SP\d{3,5}|B\d{3,5}|CF\d+[A-Z0-9]*|AT_[a-z0-9_]+|UVA\d{3,5}|[A-Z]{2,6}\d+[A-Z0-9]*)$/i;const HEX_RE = /^#[0-9a-f]{6}$/i;const URL_ENTRY_RE = /^([a-z0-9*-]+\.)+[a-z*]{2,}(:\d+)?([/?#]\S*)?$/i;const LUOGU_RE = /^(https?:\/\/)?(www\.)?luogu\.com\.cn/i;const onLuogu = () => LUOGU_RE.test(window.location.href);// 状态存储:GM 存储跨域共享(站外页面可读),无 GM 环境回退 localStorage 并双写const HAS_GM = typeof GM_getValue === 'function' && typeof GM_setValue === 'function' && typeof GM_deleteValue === 'function';const store = {get(k, d = null) { try { if (HAS_GM) { const v = GM_getValue(k); return v == null ? d : v; } const v = localStorage.getItem(k); return v === null ? d : v; } catch { return d; } },set(k, v) { const s = String(v); try { if (HAS_GM) GM_setValue(k, s); } catch {} try { localStorage.setItem(k, s); } catch {} },del(k) { try { if (HAS_GM) GM_deleteValue(k); } catch {} try { localStorage.removeItem(k); } catch {} },int(k, d) { const n = parseInt(store.get(k), 10); return Number.isFinite(n) ? n : d; },num(k, d) { const n = parseFloat(store.get(k)); return Number.isFinite(n) ? n : d; },json(k, d) { try { const v = JSON.parse(store.get(k)); return v == null ? d : v; } catch { return d; } },setJson(k, v) { store.set(k, JSON.stringify(v)); }};const clamp = (v, a, b) => Math.min(b, Math.max(a, v));const fmt = s => `${String(Math.floor(s / 60)).padStart(2, '0')}:${String(s % 60).padStart(2, '0')}`;const rgb = h => { const n = parseInt(h.replace('#', ''), 16); return [(n >> 16) & 255, (n >> 8) & 255, n & 255]; };const adjustColor = (h, p) => '#' + rgb(h).map(x => clamp(x + Math.round(2.55 * p), 0, 255).toString(16).padStart(2, '0')).join('');const contrast = h => { const [r, g, b] = rgb(h); return ((r * 299 + g * 587 + b * 114) / 1000 >= 128) ? '#111' : '#fff'; };const geoOpacity = h => { const [r, g, b] = rgb(h); return clamp(0.4 - ((0.299 * r + 0.587 * g + 0.114 * b) / 255) * 0.22, 0.18, 0.4); };const settings = {get work() { return clamp(store.int(KEY.WORK, DEFAULT.WORK), 1, 120); },get rest() { return clamp(store.int(KEY.REST, DEFAULT.REST), 1, 60); },get color() { const c = store.get(KEY.COLOR, DEFAULT.COLOR); return HEX_RE.test(c) ? c.toLowerCase() : DEFAULT.COLOR; },get opacity() { return clamp(store.num(KEY.OPACITY, DEFAULT.OPACITY), 0.3, 1); },get pos() { const p = store.json(KEY.POS, DEFAULT.POS) || DEFAULT.POS; return { x: Number(p.x) || 0, y: Number(p.y) || 0 }; }};const getSavePids = () => { const a = store.json(KEY.PIDS, []); return Array.isArray(a) ? a.filter(p => typeof p === 'string' && p.trim()) : []; };const savePids = a => store.setJson(KEY.PIDS, a);const removePid = pid => { const a = getSavePids(), i = a.indexOf(pid); if (i < 0) return false; a.splice(i, 1); savePids(a); return true; };const getSolutionStatus = () => store.get(KEY.SOLUTION, 'true') !== 'false';const saveSolutionStatus = on => store.set(KEY.SOLUTION, on);const saveDurations = (w, r) => { store.set(KEY.WORK, w); store.set(KEY.REST, r); };const saveFocusColor = c => { if (HEX_RE.test(c)) store.set(KEY.COLOR, c.toLowerCase()); };const normUrl = raw => raw.trim().toLowerCase().replace(/^https?:\/\//, '').replace(/^www\./, '').replace(/\/+$/, '');const getUrlWhitelist = () => { const a = store.json(KEY.URLWL, []); return Array.isArray(a) ? a.filter(x => typeof x === 'string' && x.trim()) : []; };const saveUrlWhitelist = a => store.setJson(KEY.URLWL, a);const removeUrl = u => { const a = getUrlWhitelist(), i = a.indexOf(u); if (i < 0) return false; a.splice(i, 1); saveUrlWhitelist(a); return true; };const getUrlWlStatus = () => store.get(KEY.URLWL_ON, 'false') === 'true';const saveUrlWlStatus = on => store.set(KEY.URLWL_ON, on);function migrateLegacy() {if (!HAS_GM || !onLuogu() || store.get(KEY.MIG) === '1') return;for (const k of Object.values(KEY)) { try { const v = localStorage.getItem(k); if (v !== null && GM_getValue(k) == null) GM_setValue(k, v); } catch {} }store.set(KEY.MIG, '1');}// 专注状态机(持久化到 localStorage,跨页延续)const Focus = {get active() { return store.get(KEY.ACTIVE) === 'true'; },get expired() { return this.active && store.get(KEY.STATE) === 'running' && Date.now() >= store.int(KEY.END, 0); },isActive() { return this.active && !this.expired; }, // 到期视为未专注,由 tick 收尾get mode() { return store.get(KEY.MODE) === 'rest' ? 'rest' : 'work'; },get state() { return store.get(KEY.STATE); },get running() { return this.isActive() && this.state === 'running'; },get paused() { return this.isActive() && this.state === 'paused'; },begin(mode) {const m = mode === 'work' ? settings.work : settings.rest;6 行未改动pause(sec) { store.set(KEY.STATE, 'paused'); store.set(KEY.REMAINING, sec); store.del(KEY.END); },end() { [KEY.ACTIVE, KEY.END, KEY.STATE, KEY.REMAINING, KEY.MODE].forEach(k => store.del(k)); }};// 访问控制:白名单 / 题解阻断 / SPA 路由守卫const redirectUrl = () => { const a = getSavePids(); return 'https://www.luogu.com.cn/problem/' + (a.length ? a[0] : 'list'); };function shouldAllow() {if (!onLuogu() || !Focus.isActive() || Focus.paused || Focus.mode === 'rest') return true;const p = window.location.pathname.toLowerCase();if (/\/problem\/solution\//i.test(p)) return getSolutionStatus();return [/^\/problem\//i, /^\/paste(\/.*)?$/i, /^\/record\//i, /^\/article(\/.*)?$/i, /^\/training(\/.*)?$/i].some(re => re.test(p));}const blockSolution = () => onLuogu() && /\/problem\/solution\//i.test(window.location.pathname) && !getSolutionStatus();// 网址白名单:开关开启且专注中,拦截所有不在名单内的站外网页(洛谷内部逻辑不变)const escRe = s => s.replace(/[.+?^${}()|[\]\\]/g, '\\$&');const urlRuleRe = e => new RegExp('^(https?://)?(www\\.)?' + e.split('*').map(escRe).join('[\\s\\S]*') + (e.endsWith('*') ? '' : '(?=[/?#:]|$)'), 'i');const urlAllowed = href => getUrlWhitelist().some(e => urlRuleRe(e).test(href));const externalBlocked = () => getUrlWlStatus() && !onLuogu() && !urlAllowed(window.location.href); // 开关即总闸,与番茄钟独立function guardRedirect() {if (blockSolution() || externalBlocked() || (Focus.isActive() && !shouldAllow())) { window.location.replace(redirectUrl()); return true; }return false;}function initRouterGuard() {if (window.__lapGuard) return;window.__lapGuard = true;['pushState', 'replaceState'].forEach(fn => {const raw = history[fn];history[fn] = function () { raw.apply(this, arguments); window.dispatchEvent(new Event('locationchange')); };});window.addEventListener('popstate', () => window.dispatchEvent(new Event('locationchange')));window.addEventListener('locationchange', guardRedirect);let last = location.pathname + location.hash;setInterval(() => { const cur = location.pathname + location.hash; if (cur !== last) { last = cur; guardRedirect(); } }, 800);}// 题解入口隐藏(禁用题解时抹掉页面元素,observer 全局唯一)let solutionObserver = null;const SOLUTION_SEL = 'a[href*="/problem/solution/"],[class*="solution"],[class*="answer"],.lg-article-content';function hideSolutionNodes(root) {if (!root.querySelectorAll) return;try {const nodes = [root, ...root.querySelectorAll(SOLUTION_SEL)]; // 含根节点自身nodes.forEach(el => {if (el.nodeType !== 1 || !el.matches?.(SOLUTION_SEL)) return;if (!((el.textContent || '').includes('题解') || (el.href || '').includes('/problem/solution/'))) return;Object.assign(el.style, { display: 'none', visibility: 'hidden', height: '0', overflow: 'hidden', pointerEvents: 'none' });});} catch {}}function ensureSolutionMonitor() {if (getSolutionStatus()) { if (solutionObserver) { solutionObserver.disconnect(); solutionObserver = null; } return; }if (solutionObserver || !document.body) return;solutionObserver = new MutationObserver(ms => ms.forEach(m => m.addedNodes.forEach(n => { if (n.nodeType === 1) hideSolutionNodes(n); })));solutionObserver.observe(document.body, { childList: true, subtree: true });hideSolutionNodes(document.body);}// 主题样式:全局唯一一个 <style>function buildCSS(c) {const L = adjustColor(c, 85), D = adjustColor(c, -20), T = contrast(c), g = geoOpacity(c).toFixed(2);return `#luogu-widget{position:fixed;z-index:2147483644;box-sizing:border-box;width:${DEFAULT.WIDTH}px;background:#fff;border:1px solid #e2e5ea;border-radius:12px;box-shadow:0 4px 16px rgba(30,40,60,.16);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"PingFang SC","Microsoft YaHei",sans-serif;-webkit-font-smoothing:antialiased;user-select:none;-webkit-user-select:none;touch-action:none;overflow:hidden;cursor:grab;transition:box-shadow .25s,opacity .2s}#luogu-widget *,#luogu-widget *::before,#luogu-widget *::after{box-sizing:border-box}#luogu-widget:hover{box-shadow:0 6px 20px rgba(30,40,60,.22)}#luogu-widget.dragging{cursor:grabbing;box-shadow:0 10px 28px rgba(30,40,60,.28)}#luogu-widget.work-running{border-color:${c};box-shadow:0 0 0 2px ${c}55,0 4px 16px ${c}40}@keyframes luogu-pulse{0%{transform:scale(1)}35%{transform:scale(1.06)}100%{transform:scale(1)}}#luogu-widget.pulse{animation:luogu-pulse .6s ease}.lg-head{display:flex;align-items:center;justify-content:space-between;height:30px;padding:6px 6px 0 10px}#luogu-mode{font-size:11px;font-weight:600;color:#8a919c;letter-spacing:1px}#luogu-widget.work-running #luogu-mode{color:${D}}#luogu-widget.paused #luogu-mode{color:#d97706}#luogu-settings{width:22px;height:22px;flex:0 0 22px;border:0;border-radius:6px;background:${c};display:flex;align-items:center;justify-content:center;cursor:pointer;transition:transform .15s,filter .15s;box-shadow:0 1px 3px rgba(0,0,0,.2)}#luogu-settings:hover{transform:scale(1.1);filter:brightness(1.05)}#luogu-settings svg{width:13px;height:13px;fill:${T};pointer-events:none}#luogu-time{font-size:26px;font-weight:700;line-height:1.15;text-align:center;color:#2b3138;font-variant-numeric:tabular-nums;padding:0 6px 5px;white-space:nowrap}.lg-track{height:4px;margin:0 10px;border-radius:2px;background:#edeff2;overflow:hidden}#luogu-bar{height:100%;width:0;background:${c};border-radius:2px;transition:width .3s linear}.lg-controls{display:flex;gap:6px;padding:9px 8px 8px}.lg-btn{flex:1;min-width:0;height:26px;border:0;border-radius:7px;font-size:12px;font-weight:600;font-family:inherit;cursor:pointer;transition:filter .15s,transform .1s}.lg-btn:active:not(:disabled){transform:scale(.96)}.lg-btn:disabled{opacity:.45;cursor:default}.lg-btn.primary{background:${c};color:${T}}.lg-btn.primary:hover:not(:disabled){filter:brightness(.92)}.lg-btn.secondary{background:${L};color:${D}}.lg-btn.secondary:hover:not(:disabled){filter:brightness(.97)}#luogu-modal-mask{position:fixed;inset:0;background:rgba(0,0,0,.3);z-index:2147483645;display:none;backdrop-filter:blur(2px)}#luogu-modal-box{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);width:360px;max-width:92vw;max-height:92vh;overflow:hidden;padding:16px 18px 18px;background:rgba(255,255,255,.7);backdrop-filter:blur(16px);-webkit-backdrop-filter:blur(16px);border:1px solid rgba(255,255,255,.5);box-shadow:0 12px 40px rgba(0,0,0,.15);border-radius:14px;z-index:2147483646;display:none;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"PingFang SC",sans-serif}#luogu-modal-box *,#luogu-modal-box *::before,#luogu-modal-box *::after{box-sizing:border-box}.lg-inner{position:relative;z-index:2;max-height:calc(92vh - 36px);overflow-y:auto;scrollbar-width:none;-ms-overflow-style:none}.lg-inner::-webkit-scrollbar{width:0;height:0}.lg-geo{position:absolute;pointer-events:none;z-index:1;filter:blur(1px)}#luogu-modal-box h3{margin:0 0 12px;color:#1a1a1a;text-align:center;font-size:18px;font-weight:700}.setting-section{margin-bottom:10px}.setting-label{display:block;margin-bottom:6px;font-size:12px;font-weight:600;color:#4a5568;letter-spacing:.3px}#luogu-pid-input,#luogu-url-input{width:100%;padding:8px 10px;border:1.5px solid #e2e8f0;border-radius:8px;font-size:13px;transition:all .2s;background:rgba(255,255,255,.6)}#luogu-pid-input:focus,#luogu-url-input:focus{border-color:${c};outline:none;box-shadow:0 0 0 3px ${c}22;background:#fff}#luogu-url-input{margin-top:8px}.pid-list{display:flex;flex-wrap:wrap;gap:5px;margin-top:6px;min-height:24px}.pid-item{background:linear-gradient(135deg,${c}15,${c}25);border:1px solid ${c}40;color:${c};padding:3px 9px;border-radius:12px;font-size:12px;display:flex;align-items:center;gap:6px;cursor:pointer;transition:all .2s}.pid-item:hover{transform:translateY(-1px);box-shadow:0 2px 8px ${c}33}.pid-item .remove{color:#ef4444;font-weight:bold;cursor:pointer;line-height:1}.pid-empty{color:#cbd5e1;font-size:12px;padding:4px;width:100%;text-align:center}.setting-row{display:flex;align-items:center;justify-content:space-between;padding:9px 12px;background:rgba(248,250,252,.5);border-radius:10px;border:1px solid #e2e8f0}.setting-text{font-size:13px;color:#4a5568;font-weight:500}.switch{position:relative;width:44px;height:24px;flex:0 0 44px}.switch input{opacity:0;width:0;height:0}.switch-slider{position:absolute;cursor:pointer;inset:0;background:#cbd5e1;transition:.3s;border-radius:24px}.switch-slider:before{position:absolute;content:"";height:18px;width:18px;left:3px;bottom:3px;background:#fff;transition:.3s;border-radius:50%;box-shadow:0 2px 4px rgba(0,0,0,.1)}input:checked+.switch-slider{background:linear-gradient(135deg,${c},${c}cc)}input:checked+.switch-slider:before{transform:translateX(20px)}.duration-row{display:grid;grid-template-columns:1fr 1fr;gap:10px}.duration-item{display:flex;flex-direction:column;gap:4px}.duration-item label{font-size:11px;color:#718096;font-weight:500}.duration-input{width:100%;padding:7px 10px;border:1.5px solid #e2e8f0;border-radius:8px;font-size:13px;background:rgba(255,255,255,.6);transition:all .2s}.duration-input:focus{outline:none;border-color:${c};background:#fff}.color-row{display:flex;align-items:center;gap:10px}#luogu-color-input{width:64px;flex:0 0 64px;height:32px;padding:2px;border:1.5px solid #e2e8f0;border-radius:8px;cursor:pointer;background:#fff}.opacity-slider{flex:1;display:flex;align-items:center;gap:10px}.opacity-slider input[type="range"]{flex:1;height:6px;border-radius:3px;background:#e2e8f0;outline:none;-webkit-appearance:none;appearance:none}.opacity-slider input[type="range"]::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;width:18px;height:18px;border-radius:50%;background:${c};cursor:pointer;box-shadow:0 2px 4px rgba(0,0,0,.2)}.opacity-value{min-width:42px;text-align:right;font-size:13px;font-weight:600;color:#4a5568}.hint{font-size:11px;color:#a0aec0;margin-top:4px;line-height:1.4}.btn-group{display:grid;grid-template-columns:1fr 1.3fr;gap:8px;margin-top:12px}.btn{padding:9px;border:none;border-radius:8px;cursor:pointer;font-size:13px;font-weight:600;font-family:inherit;transition:all .2s}#luogu-save-btn{background:linear-gradient(135deg,${c},${c}bb);color:#fff;box-shadow:0 4px 12px ${c}44}#luogu-save-btn:hover{transform:translateY(-1px);box-shadow:0 6px 16px ${c}66}#luogu-cancel-btn{background:#f1f5f9;color:#64748b}#luogu-cancel-btn:hover{background:#e2e8f0}.lg-geo-op{opacity:${g}}`;}function applyTheme() {let st = document.getElementById('luogu-theme-style');if (!st) { st = document.createElement('style'); st.id = 'luogu-theme-style'; (document.head || document.documentElement).appendChild(st); }st.textContent = buildCSS(settings.color);}const applyOpacity = () => { const w = document.getElementById('luogu-widget'); if (w) w.style.opacity = settings.opacity; };// 番茄钟钟面const GEAR = '<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19.14 12.94c.04-.31.06-.63.06-.94 0-.31-.02-.63-.06-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.04.31-.06.63-.06.94s.02.63.06.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z"/></svg>';let widgetApi = null;function createWidget() {if (widgetApi || !onLuogu()) return;const w = document.createElement('div');w.id = 'luogu-widget';w.innerHTML = `<div class="lg-head"><span id="luogu-mode">专注</span><button id="luogu-settings" title="专注设置" aria-label="专注设置">${GEAR}</button></div><div id="luogu-time">--:--</div><div class="lg-track"><div id="luogu-bar"></div></div><div class="lg-controls"><button class="lg-btn primary" id="luogu-main">开始</button><button class="lg-btn secondary" id="luogu-stop">结束</button></div>`;document.body.appendChild(w);const $ = id => w.querySelector('#' + id);const modeEl = $('luogu-mode'), timeEl = $('luogu-time'), barEl = $('luogu-bar'), mainBtn = $('luogu-main'), stopBtn = $('luogu-stop');let mode = Focus.mode, remaining = 0, ticker = null;const durOf = m => (m === 'work' ? settings.work : settings.rest) * 60;function render() {timeEl.textContent = fmt(remaining);barEl.style.width = clamp((1 - remaining / durOf(mode)) * 100, 0, 100) + '%';modeEl.textContent = Focus.paused ? '已暂停' : (mode === 'work' ? '专注' : '休息');mainBtn.textContent = Focus.running ? '暂停' : (Focus.paused ? '继续' : '开始');stopBtn.disabled = !Focus.isActive();w.classList.toggle('work-running', Focus.running && mode === 'work');w.classList.toggle('paused', Focus.paused);}function tick() {const r = Math.max(0, Math.ceil((store.int(KEY.END, 0) - Date.now()) / 1000));if (r !== remaining) { remaining = r; render(); }if (r <= 0 && Focus.active && Focus.state === 'running') return nextPhase(); // 到期先进入下一阶段if (!Focus.running) stopTicker();}function startTicker() { stopTicker(); ticker = setInterval(tick, 250); }function stopTicker() { if (ticker) { clearInterval(ticker); ticker = null; } }function nextPhase() {mode = mode === 'work' ? 'rest' : 'work';Focus.begin(mode); remaining = durOf(mode);w.classList.remove('pulse'); void w.offsetWidth; w.classList.add('pulse');render(); startTicker();}mainBtn.addEventListener('click', () => {if (Focus.running) { Focus.pause(remaining); stopTicker(); }else if (Focus.paused) { Focus.resume(mode, remaining); startTicker(); }else { Focus.begin(mode); remaining = durOf(mode); startTicker(); }render();});stopBtn.addEventListener('click', () => { stopTicker(); Focus.end(); mode = 'work'; remaining = durOf(mode); render(); });$('luogu-settings').addEventListener('click', createSettingUI);let drag = null;function setPosition(x, y) {w.style.left = Math.round(clamp(x, 0, Math.max(0, innerWidth - w.offsetWidth))) + 'px';w.style.top = Math.round(clamp(y, 0, Math.max(0, innerHeight - w.offsetHeight))) + 'px';}w.addEventListener('pointerdown', e => {if ((e.pointerType === 'mouse' && e.button !== 0) || e.target.closest('button')) return;const r = w.getBoundingClientRect();drag = { dx: e.clientX - r.left, dy: e.clientY - r.top };w.classList.add('dragging');try { w.setPointerCapture(e.pointerId); } catch {}e.preventDefault();});w.addEventListener('pointermove', e => { if (drag) setPosition(e.clientX - drag.dx, e.clientY - drag.dy); });const endDrag = () => {if (!drag) return;drag = null; w.classList.remove('dragging');const r = w.getBoundingClientRect();store.setJson(KEY.POS, { x: Math.round(r.left), y: Math.round(r.top) });};w.addEventListener('pointerup', endDrag);w.addEventListener('pointercancel', endDrag);window.addEventListener('resize', () => { const r = w.getBoundingClientRect(); setPosition(r.left, r.top); });document.addEventListener('visibilitychange', () => { if (!document.hidden && Focus.running) tick(); });widgetApi = { refresh() { if (!Focus.isActive()) remaining = durOf(mode); render(); } };remaining = Focus.running ? Math.max(0, Math.ceil((store.int(KEY.END, 0) - Date.now()) / 1000)) : (Focus.paused ? Math.max(0, store.int(KEY.REMAINING, 0)) : durOf(mode));setPosition(settings.pos.x, settings.pos.y);applyOpacity(); render();if (Focus.active && Focus.state === 'running') { if (Focus.expired) nextPhase(); else startTicker(); }}// 设置面板(全局唯一,每次打开重建节点与样式)let modalNodes = null;function closeSettings() {if (!modalNodes) return;modalNodes.mask.remove(); modalNodes.box.remove();document.removeEventListener('keydown', modalNodes.onKey);modalNodes = null;}function createSettingUI() {if (!onLuogu()) return;closeSettings();const c = settings.color, g = geoOpacity(c), cur = settings.opacity;const mask = document.createElement('div'); mask.id = 'luogu-modal-mask';const box = document.createElement('div'); box.id = 'luogu-modal-box';box.innerHTML = `<div class="lg-geo lg-geo-op" style="top:-30px;right:-30px;width:130px;height:130px;border-radius:50%;background:${c}"></div><div class="lg-geo" style="bottom:-20px;left:-25px;width:100px;height:100px;transform:rotate(45deg);border-radius:16px;background:${c};opacity:${(g * .75).toFixed(2)}"></div><div class="lg-geo" style="top:40%;right:25px;width:0;height:0;border-left:30px solid transparent;border-right:30px solid transparent;border-bottom:50px solid ${c};opacity:${(g * .85).toFixed(2)};transform:rotate(-15deg)"></div><div class="lg-geo" style="top:15%;left:-20px;width:60px;height:60px;border-radius:50%;border:6px solid ${c};opacity:${(g * .6).toFixed(2)}"></div><div class="lg-inner"><h3>专注设置</h3><div class="setting-section"><label class="setting-label">题目计划</label><input type="text" id="luogu-pid-input" placeholder="输入题号(如:P1000、CF1628D、AT_abc001_a)"><div class="pid-list" id="pid-list"></div><div class="hint">最多 ${DEFAULT.MAX_PIDS} 题,回车立即添加。支持 Luogu / CF / AtCoder / UVA</div></div><div class="setting-section"><div class="setting-row"><span class="setting-text">允许查看题解</span><label class="switch"><input type="checkbox" id="luogu-solution-checkbox"><span class="switch-slider"></span></label></div></div><div class="setting-section"><div class="setting-row"><span class="setting-text">启用网址白名单</span><label class="switch"><input type="checkbox" id="luogu-urlwl-checkbox"><span class="switch-slider"></span></label></div><input type="text" id="luogu-url-input" placeholder="输入网址,如 bilibili.com 或 wiki.example.com/docs"><div class="pid-list" id="url-list"></div><div class="hint">开启后访问名单外网站将跳回题目页(即刻生效,与番茄钟独立)。支持 * 通配符,回车添加,最多 ${DEFAULT.MAX_URLS} 条</div></div><div class="setting-section"><label class="setting-label">番茄钟时长(分钟)</label><div class="duration-row"><div class="duration-item"><label>工作</label><input type="number" id="luogu-work-input" class="duration-input" min="1" max="120"></div><div class="duration-item"><label>休息</label><input type="number" id="luogu-rest-input" class="duration-input" min="1" max="60"></div></div></div><div class="setting-section"><label class="setting-label">主题颜色</label><div class="color-row"><input type="color" id="luogu-color-input"><div class="opacity-slider"><input type="range" id="luogu-opacity-slider" min="0.3" max="1" step="0.05"><span class="opacity-value" id="opacity-value">${Math.round(cur * 100)}%</span></div></div><div class="hint">右侧滑块调节钟面透明度</div></div><div class="btn-group"><button id="luogu-cancel-btn" class="btn">取消</button><button id="luogu-save-btn" class="btn">保存配置</button></div></div>`;document.body.appendChild(mask);document.body.appendChild(box);modalNodes = { mask, box, onKey: e => { if (e.key === 'Escape') closeSettings(); } };document.addEventListener('keydown', modalNodes.onKey);const $ = id => box.querySelector('#' + id);const pidInput = $('luogu-pid-input'), pidList = $('pid-list'), slider = $('luogu-opacity-slider');const urlInput = $('luogu-url-input'), urlList = $('url-list');function renderPidList() {const pids = getSavePids();pidList.innerHTML = '';if (!pids.length) { pidList.innerHTML = '<div class="pid-empty">暂无题目</div>'; return; }pids.forEach(pid => {const it = document.createElement('div');it.className = 'pid-item';it.innerHTML = `${pid}<span class="remove" title="删除">×</span>`;it.onclick = e => {if (e.target.classList.contains('remove')) { e.stopPropagation(); removePid(pid); renderPidList(); }else window.location.href = `https://www.luogu.com.cn/problem/${pid}`;};pidList.appendChild(it);});}function addPidFromInput() {const raw = pidInput.value.trim();if (!raw) return;const pid = raw.startsWith('AT_') ? raw : raw.toUpperCase(), pids = getSavePids();if (!PID_RE.test(pid)) return alert('题号格式错误:' + raw);if (pids.includes(pid)) { pidInput.value = ''; return alert('该题已在计划中'); }if (pids.length >= DEFAULT.MAX_PIDS) return alert('最多添加 ' + DEFAULT.MAX_PIDS + ' 题');pids.push(pid); savePids(pids); pidInput.value = ''; renderPidList();}function renderUrlList() {const urls = getUrlWhitelist();urlList.innerHTML = '';if (!urls.length) { urlList.innerHTML = '<div class="pid-empty">暂无网址</div>'; return; }urls.forEach(u => {const it = document.createElement('div');it.className = 'pid-item';it.innerHTML = `${u}<span class="remove" title="删除">×</span>`;it.onclick = e => {if (e.target.classList.contains('remove')) { e.stopPropagation(); removeUrl(u); renderUrlList(); }else window.location.href = /^https?:\/\//.test(u) ? u : 'https://' + u;};urlList.appendChild(it);});}function addUrlFromInput() {const raw = urlInput.value.trim();if (!raw) return;const u = normUrl(raw), urls = getUrlWhitelist();if (!URL_ENTRY_RE.test(u)) { urlInput.value = ''; return alert('网址格式错误:' + raw); }if (urls.includes(u)) { urlInput.value = ''; return alert('该网址已在白名单中'); }if (urls.length >= DEFAULT.MAX_URLS) return alert('最多添加 ' + DEFAULT.MAX_URLS + ' 条网址');urls.push(u); saveUrlWhitelist(urls); urlInput.value = ''; renderUrlList();}function doSave() {const work = parseInt($('luogu-work-input').value, 10) || DEFAULT.WORK;const rest = parseInt($('luogu-rest-input').value, 10) || DEFAULT.REST;if (work < 1 || work > 120) return alert('工作时长 1-120');if (rest < 1 || rest > 60) return alert('休息时长 1-60');addPidFromInput(); addUrlFromInput();saveDurations(work, rest);saveFocusColor($('luogu-color-input').value);saveSolutionStatus($('luogu-solution-checkbox').checked);saveUrlWlStatus($('luogu-urlwl-checkbox').checked);store.set(KEY.OPACITY, clamp(parseFloat(slider.value) || DEFAULT.OPACITY, 0.3, 1));applyTheme(); applyOpacity(); ensureSolutionMonitor();if (widgetApi) widgetApi.refresh();closeSettings();}$('luogu-save-btn').onclick = doSave;$('luogu-cancel-btn').onclick = closeSettings;mask.onclick = closeSettings;pidInput.onkeydown = e => { if (e.key === 'Enter') { e.preventDefault(); addPidFromInput(); } };urlInput.onkeydown = e => { if (e.key === 'Enter') { e.preventDefault(); addUrlFromInput(); } };slider.value = cur;slider.oninput = e => {const v = parseFloat(e.target.value) || DEFAULT.OPACITY;$('opacity-value').textContent = Math.round(v * 100) + '%';const w = document.getElementById('luogu-widget'); if (w) w.style.opacity = v;};$('luogu-solution-checkbox').checked = getSolutionStatus();$('luogu-urlwl-checkbox').checked = getUrlWlStatus();$('luogu-work-input').value = settings.work;$('luogu-rest-input').value = settings.rest;$('luogu-color-input').value = c;renderPidList(); renderUrlList();mask.style.display = 'block'; box.style.display = 'block';pidInput.focus();}// 启动migrateLegacy();if (guardRedirect()) return;function boot() { if (onLuogu()) { applyTheme(); createWidget(); } }if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot, { once: true });else boot();window.addEventListener('load', () => { if (onLuogu()) ensureSolutionMonitor(); initRouterGuard(); }, { once: true });})();```:::---有什么建议可以评论私信,持续更新。谢谢你看到这里~123456789101112134 行未改动181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645654 行未改动5705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566 行未改动6636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030防止文章过长,我们把以往的版本都迁移至了 [$\textup{github}$](https://github.com/Fall-wendywan/Luogu-academic-Pro)。[$\textup{Cnblogs Link.}$](https://www.cnblogs.com/Fall-wendywan/p/19683545)这个人平时很不自觉,喜欢水谷但不喜欢上什么其它网站。于是她参考了[这篇文章](https://www.luogu.com.cn/article/ysrs7l49),花了~~一个晚上~~ ~~将近两周~~ 一年调了十几版,最终用 AI 做出了这个插件。直接粘贴到篡改猴里面保存就能用了。功能介绍:4 行未改动+ 当在专注时点击其他洛谷网页(除题目、提交记录及剪切板外)自动跳转到计划中第一个题目;+ 支持用本地存储倒计时进度,若当前有进度将自动继续走时(该功能容易出问题)。+ 支持勾选是否允许题解查看,否时默认为自动跳转。---## $\textup{V2.0}$$\textup{Upd on 2026.3.7.}$注意到我们的添加题库出了一点问题,可能是因为在原文章基础上进行开发,没有把入门与面试、CF、AT 和 UVA 题库的题目添加到计划的功能。在完善这个功能的同时,我正添加了在学习过程中按暂停可以暂时访问其他网页的功能。(否则暂停键没有起到任何作用吧。)包括考虑将在未来添加一个可以选择是否拦截所有除题目外的网址的模式,但是调了好久没整出来。## $\textup{V3.0}$$\textup{Upd on 2026.5.24.}$修复目前已知的 bug,比如无法拦截进入题库等功能。---## $\textup{V4.0}$$\textup{Upd on 2026.7.14.}$修复目前已知的 bug,诸如题目添加等。并且优化了前端的主题功能,更加适配新的洛谷主题。---## $\textup{V4.2}$$\textup{Upd on 2026.7.24.}$添加文章、题单到白名单,觉得这个相对学术。---## $\textup{V5.0}$$\textup{Upd on 2026.9.23}$修复目前已知的 bug,如钟面无法显示全等。添加调整透明度功能,添加强力学术(隔绝洛谷外的访问!终于实现了!)并对前端进行大力优化。~~qwen Agent 立大功!~~:::success[$\textup{Code.}$]```javascript// ==UserScript==// @name 洛谷强力学术Pro// @namespace http://tampermonkey.net/// @version 5.0// @author wendywan// @icon https://cdn.luogu.com.cn/upload/image_hosting/psd5a03h.png// @match *://*/*// @noframes// @grant GM_getValue// @grant GM_setValue// @grant GM_deleteValue// @license MIT// @run-at document-start// ==/UserScript==(function () {'use strict';/* ============ 常量 ============ */const KEY = {PIDS: 'luogu_study_plan_pids', SOLUTION: 'luogu_study_plan_solution',ACTIVE: 'luogu_focus_active', END: 'luogu_focus_end_time', STATE: 'luogu_focus_state',MODE: 'luogu_focus_current_mode', REMAINING: 'luogu_focus_remaining',WORK: 'luogu_focus_duration', REST: 'luogu_rest_duration',COLOR: 'luogu_focus_color', OPACITY: 'luogu_widget_opacity', POS: 'luogu_focus_position',URLWL: 'luogu_focus_url_whitelist', URLWL_ON: 'luogu_focus_url_whitelist_on', MIG: 'luogu_focus_migrated'};const DEFAULT = { WORK: 25, REST: 5, COLOR: '#ff6b6b', OPACITY: 0.9, POS: { x: 20, y: 100 }, WIDTH: 138, MAX_PIDS: 6, MAX_URLS: 10 };const RE = {PID: /^(P\d{3,6}|SP\d{3,5}|B\d{3,5}|CF\d+[A-Z0-9]*|AT_[a-z0-9_]+|UVA\d{3,5}|[A-Z]{2,6}\d+[A-Z0-9]*)$/i,HEX: /^#[0-9a-f]{6}$/i,URL_ENTRY: /^([a-z0-9*-]+\.)+[a-z*]{2,}(:\d+)?([/?#][\w./?#&=%+*-]*)?$/i,LUOGU: /^(https?:\/\/)?(www\.)?luogu\.com\.cn/i,SOLUTION: /\/problem\/solution\//i};const LUOGU_PATHS = [/^\/problem\//i, /^\/paste(\/.*)?$/i, /^\/record\//i, /^\/article(\/.*)?$/i, /^\/training(\/.*)?$/i];const onLuogu = () => RE.LUOGU.test(window.location.href);/* ============ 存储:GM 跨域共享,无 GM 回退 localStorage,双写保兼容 ============ */const safe = fn => { try { return fn(); } catch {} };const HAS_GM = typeof GM_getValue === 'function' && typeof GM_setValue === 'function' && typeof GM_deleteValue === 'function';const store = {get(k, d = null) { try { const v = HAS_GM ? GM_getValue(k) : localStorage.getItem(k); return v == null ? d : v; } catch { return d; } },set(k, v) { const s = String(v); if (HAS_GM) safe(() => GM_setValue(k, s)); safe(() => localStorage.setItem(k, s)); },del(k) { if (HAS_GM) safe(() => GM_deleteValue(k)); safe(() => localStorage.removeItem(k)); },int(k, d) { const n = parseInt(store.get(k), 10); return Number.isFinite(n) ? n : d; },num(k, d) { const n = parseFloat(store.get(k)); return Number.isFinite(n) ? n : d; },json(k, d) { try { const v = JSON.parse(store.get(k)); return v == null ? d : v; } catch { return d; } },setJson(k, v) { store.set(k, JSON.stringify(v)); }};const boolSetting = (key, dflt) => ({ get: () => store.get(key, String(dflt)) === 'true', set: v => store.set(key, v) });const listStore = key => ({get() { const a = store.json(key, []); return Array.isArray(a) ? a.filter(x => typeof x === 'string' && x.trim()) : []; },save(a) { store.setJson(key, a); },add(v, max) { const a = this.get(); if (a.includes(v)) return 'dup'; if (a.length >= max) return 'full'; a.push(v); this.save(a); return 'ok'; },remove(v) { const a = this.get(), i = a.indexOf(v); if (i < 0) return false; a.splice(i, 1); this.save(a); return true; }});/* ============ 通用工具 ============ */const clamp = (v, a, b) => Math.min(b, Math.max(a, v));const fmtTime = s => `${String(Math.floor(s / 60)).padStart(2, '0')}:${String(s % 60).padStart(2, '0')}`;const hexToRgb = h => { const n = parseInt(h.replace('#', ''), 16); return [(n >> 16) & 255, (n >> 8) & 255, n & 255]; };const luma = h => { const [r, g, b] = hexToRgb(h); return (0.299 * r + 0.587 * g + 0.114 * b) / 255; };const shiftHex = (h, pct) => '#' + hexToRgb(h).map(x => clamp(x + Math.round(2.55 * pct), 0, 255).toString(16).padStart(2, '0')).join('');const textOn = h => (luma(h) * 255 >= 128 ? '#111' : '#fff');const geoAlpha = h => clamp(0.4 - luma(h) * 0.22, 0.18, 0.4);const deepShade = h => (luma(h) > 0.45 ? '#' + hexToRgb(h).map(x => Math.round(x * 0.45).toString(16).padStart(2, '0')).join('') : h);const escRe = s => s.replace(/[.+?^${}()|[\]\\]/g, '\\$&');/* ============ 设置与名单 ============ */const settings = {get work() { return clamp(store.int(KEY.WORK, DEFAULT.WORK), 1, 120); },get rest() { return clamp(store.int(KEY.REST, DEFAULT.REST), 1, 60); },get color() { const c = store.get(KEY.COLOR, DEFAULT.COLOR); return RE.HEX.test(c) ? c.toLowerCase() : DEFAULT.COLOR; },get opacity() { return clamp(store.num(KEY.OPACITY, DEFAULT.OPACITY), 0.3, 1); },get pos() { const p = store.json(KEY.POS, DEFAULT.POS) || DEFAULT.POS; return { x: Number(p.x) || 0, y: Number(p.y) || 0 }; }};const pids = listStore(KEY.PIDS);const urls = listStore(KEY.URLWL);const solutionAllowed = boolSetting(KEY.SOLUTION, true);const whitelistOn = boolSetting(KEY.URLWL_ON, false);const normUrl = raw => raw.trim().toLowerCase().replace(/^https?:\/\//, '').replace(/^www\./, '').replace(/\/+$/, '');const saveDurations = (w, r) => { store.set(KEY.WORK, w); store.set(KEY.REST, r); };const saveColor = c => { if (RE.HEX.test(c)) store.set(KEY.COLOR, c.toLowerCase()); };function migrateLegacy() {if (!HAS_GM || !onLuogu() || store.get(KEY.MIG) === '1') return;for (const k of Object.values(KEY)) { const v = safe(() => localStorage.getItem(k)); if (v != null && GM_getValue(k) == null) GM_setValue(k, v); }store.set(KEY.MIG, '1');}/* ============ 专注状态机(跨页延续) ============ */const Focus = {get active() { return store.get(KEY.ACTIVE) === 'true'; },get state() { return store.get(KEY.STATE); },get mode() { return store.get(KEY.MODE) === 'rest' ? 'rest' : 'work'; },get expired() { return this.active && this.state === 'running' && Date.now() >= store.int(KEY.END, 0); },isActive() { return this.active && !this.expired; },get running() { return this.isActive() && this.state === 'running'; },get paused() { return this.isActive() && this.state === 'paused'; },begin(mode) {const m = mode === 'work' ? settings.work : settings.rest;store.set(KEY.ACTIVE, 'true'); store.set(KEY.END, Date.now() + m * 60000);store.set(KEY.STATE, 'running'); store.set(KEY.MODE, mode);if (mode === 'work') store.set(KEY.WORK, m);store.del(KEY.REMAINING);},resume(mode, sec) { store.set(KEY.ACTIVE, 'true'); store.set(KEY.END, Date.now() + sec * 1000); store.set(KEY.STATE, 'running'); store.set(KEY.MODE, mode); store.del(KEY.REMAINING); },pause(sec) { store.set(KEY.STATE, 'paused'); store.set(KEY.REMAINING, sec); store.del(KEY.END); },end() { [KEY.ACTIVE, KEY.END, KEY.STATE, KEY.REMAINING, KEY.MODE].forEach(k => store.del(k)); }};/* ============ 访问控制:洛谷白名单 / 题解阻断 / 站外网址白名单 / SPA 守卫 ============ */const Access = {redirectUrl() { const a = pids.get(); return 'https://www.luogu.com.cn/problem/' + (a.length ? a[0] : 'list'); },urlRule(entry) {const tail = entry.endsWith('*') ? '' : '(?=[/?#:]|$)';const body = entry.startsWith('*.')? '(?:[a-z0-9-]+\\.)*' + escRe(entry.slice(2)).split('*').join('[\\s\\S]*'): escRe(entry).split('*').join('[\\s\\S]*');return new RegExp('^(https?://)?(www\\.)?' + body + tail, 'i');},urlAllowed(href) { return urls.get().some(e => this.urlRule(e).test(href)); },solutionBlocked() { return onLuogu() && RE.SOLUTION.test(window.location.pathname) && !solutionAllowed.get(); },externalBlocked() { return whitelistOn.get() && !onLuogu() && !this.urlAllowed(window.location.href); },luoguAllowed() {if (!Focus.isActive() || Focus.paused || Focus.mode === 'rest') return true;const p = window.location.pathname.toLowerCase();if (RE.SOLUTION.test(p)) return solutionAllowed.get();return LUOGU_PATHS.some(re => re.test(p));},enforce() {const denied = this.solutionBlocked() || this.externalBlocked() || (onLuogu() && Focus.isActive() && !this.luoguAllowed());if (denied) window.location.replace(this.redirectUrl());return denied;},watchRouter() {if (window.__lapGuard) return;window.__lapGuard = true;for (const fn of ['pushState', 'replaceState']) {const raw = history[fn];history[fn] = function () { raw.apply(this, arguments); window.dispatchEvent(new Event('locationchange')); };}window.addEventListener('popstate', () => window.dispatchEvent(new Event('locationchange')));window.addEventListener('locationchange', () => this.enforce());let last = location.pathname + location.hash;setInterval(() => { const cur = location.pathname + location.hash; if (cur !== last) { last = cur; this.enforce(); } }, 800);}};/* ============ 题解入口隐藏(observer 全局唯一) ============ */const SolutionHider = {SEL: 'a[href*="/problem/solution/"],[class*="solution"],[class*="answer"],.lg-article-content',observer: null,hide(root) {if (!root.querySelectorAll) return;safe(() => {for (const el of [root, ...root.querySelectorAll(this.SEL)]) {if (el.nodeType !== 1 || !el.matches?.(this.SEL)) continue;if (!(el.textContent || '').includes('题解') && !(el.href || '').includes('/problem/solution/')) continue;Object.assign(el.style, { display: 'none', visibility: 'hidden', height: '0', overflow: 'hidden', pointerEvents: 'none' });}});},sync() {if (solutionAllowed.get()) { if (this.observer) { this.observer.disconnect(); this.observer = null; } return; }if (this.observer || !document.body) return;this.observer = new MutationObserver(ms => ms.forEach(m => m.addedNodes.forEach(n => { if (n.nodeType === 1) this.hide(n); })));this.observer.observe(document.body, { childList: true, subtree: true });this.hide(document.body);}};/* ============ 主题:全局唯一 <style>,改色整体重写 ============ */const Theme = {palette(c) { return { main: c, light: shiftHex(c, 85), dark: shiftHex(c, -20), onMain: textOn(c), chip: deepShade(c), geo: geoAlpha(c).toFixed(2) }; },css(c) { const p = this.palette(c); return this.widgetCSS(p) + this.modalCSS(p); },widgetCSS(p) {return `#luogu-widget{position:fixed;z-index:2147483644;box-sizing:border-box;width:${DEFAULT.WIDTH}px;background:rgba(255,255,255,var(--lap-a,.9));backdrop-filter:blur(6px) saturate(1.1);-webkit-backdrop-filter:blur(6px) saturate(1.1);border:1px solid #e2e5ea;border-radius:12px;box-shadow:0 4px 16px rgba(30,40,60,.16);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"PingFang SC","Microsoft YaHei",sans-serif;-webkit-font-smoothing:antialiased;user-select:none;-webkit-user-select:none;touch-action:none;overflow:hidden;cursor:grab;transition:box-shadow .25s,background-color .2s}#luogu-widget *,#luogu-widget *::before,#luogu-widget *::after{box-sizing:border-box}#luogu-widget:hover{box-shadow:0 6px 20px rgba(30,40,60,.22)}#luogu-widget.dragging{cursor:grabbing;box-shadow:0 10px 28px rgba(30,40,60,.28)}#luogu-widget.work-running{border-color:${p.main};box-shadow:0 0 0 2px ${p.main}55,0 4px 16px ${p.main}40}@keyframes luogu-pulse{0%{transform:scale(1)}35%{transform:scale(1.06)}100%{transform:scale(1)}}#luogu-widget.pulse{animation:luogu-pulse .6s ease}#luogu-widget .lg-head{display:flex;align-items:center;justify-content:space-between;height:30px;padding:6px 6px 0 10px}#luogu-mode{font-size:11px;font-weight:600;color:#8a919c;letter-spacing:1px}#luogu-widget.work-running #luogu-mode{color:${p.dark}}#luogu-widget.paused #luogu-mode{color:#d97706}#luogu-settings{width:22px;height:22px;flex:0 0 22px;border:0;border-radius:6px;background:${p.main};display:flex;align-items:center;justify-content:center;cursor:pointer;transition:transform .15s,filter .15s;box-shadow:0 1px 3px rgba(0,0,0,.2)}#luogu-settings:hover{transform:scale(1.1);filter:brightness(1.05)}#luogu-settings svg{width:13px;height:13px;fill:${p.onMain};pointer-events:none}#luogu-time{font-size:26px;font-weight:700;line-height:1.15;text-align:center;color:#2b3138;font-variant-numeric:tabular-nums;padding:0 6px 5px;white-space:nowrap}#luogu-widget .lg-track{height:4px;margin:0 10px;border-radius:2px;background:#edeff2;overflow:hidden}#luogu-bar{height:100%;width:0;background:${p.main};border-radius:2px;transition:width .3s linear}#luogu-widget .lg-controls{display:flex;gap:6px;padding:9px 8px 8px}#luogu-widget .lg-btn{flex:1;min-width:0;height:26px;border:0;border-radius:7px;font-size:12px;font-weight:600;font-family:inherit;cursor:pointer;transition:filter .15s,transform .1s}#luogu-widget .lg-btn:active:not(:disabled){transform:scale(.96)}#luogu-widget .lg-btn:disabled{opacity:.45;cursor:default}#luogu-widget .lg-btn.primary{background:${p.main};color:${p.onMain}}#luogu-widget .lg-btn.primary:hover:not(:disabled){filter:brightness(.92)}#luogu-widget .lg-btn.secondary{background:${p.light};color:${p.dark}}#luogu-widget .lg-btn.secondary:hover:not(:disabled){filter:brightness(.97)}`;},modalCSS(p) {return `#luogu-modal-mask{position:fixed;inset:0;background:rgba(0,0,0,.3);z-index:2147483645;display:none;backdrop-filter:blur(2px)}#luogu-modal-box{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);width:360px;max-width:92vw;max-height:92vh;overflow:hidden;padding:16px 18px 18px;background:rgba(255,255,255,.7);backdrop-filter:blur(16px);-webkit-backdrop-filter:blur(16px);border:1px solid rgba(255,255,255,.5);box-shadow:0 12px 40px rgba(0,0,0,.15);border-radius:14px;z-index:2147483646;display:none;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"PingFang SC",sans-serif}#luogu-modal-box *,#luogu-modal-box *::before,#luogu-modal-box *::after{box-sizing:border-box}#luogu-modal-box .lg-inner{position:relative;z-index:2;max-height:calc(92vh - 36px);overflow-y:auto;scrollbar-width:none;-ms-overflow-style:none}#luogu-modal-box .lg-inner::-webkit-scrollbar{width:0;height:0}#luogu-modal-box .lg-geo{position:absolute;pointer-events:none;z-index:1;filter:blur(1px)}#luogu-modal-box h3{margin:0 0 12px;color:#1a1a1a;text-align:center;font-size:18px;font-weight:700}#luogu-modal-box .setting-section{margin-bottom:10px}#luogu-modal-box .setting-label{display:block;margin-bottom:6px;font-size:12px;font-weight:600;color:#4a5568;letter-spacing:.3px}#luogu-pid-input,#luogu-url-input{width:100%;padding:8px 10px;border:1.5px solid #e2e8f0;border-radius:8px;font-size:13px;transition:all .2s;background:rgba(255,255,255,.6)}#luogu-pid-input:focus,#luogu-url-input:focus{border-color:${p.main};outline:none;box-shadow:0 0 0 3px ${p.main}22;background:#fff}#luogu-url-input{margin-top:8px}#luogu-modal-box .pid-list{display:flex;flex-wrap:wrap;gap:5px;margin-top:6px;min-height:24px}#luogu-modal-box .pid-item{background:linear-gradient(135deg,${p.main}26,${p.main}40);border:1px solid ${p.main}66;color:${p.chip};font-weight:600;padding:3px 9px;border-radius:12px;font-size:12px;display:flex;align-items:center;gap:6px;cursor:pointer;transition:all .2s}#luogu-modal-box .pid-item:hover{transform:translateY(-1px);box-shadow:0 2px 8px ${p.main}55;background:linear-gradient(135deg,${p.main}33,${p.main}4d)}#luogu-modal-box .pid-item>span:first-child{max-width:230px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}#luogu-modal-box .pid-item .remove{color:#ef4444;font-weight:bold;cursor:pointer;line-height:1}#luogu-modal-box .pid-empty{color:#cbd5e1;font-size:12px;padding:4px;width:100%;text-align:center}#luogu-modal-box .setting-row{display:flex;align-items:center;justify-content:space-between;padding:9px 12px;background:rgba(248,250,252,.5);border-radius:10px;border:1px solid #e2e8f0}#luogu-modal-box .setting-text{font-size:13px;color:#4a5568;font-weight:500}#luogu-modal-box .switch{position:relative;width:44px;height:24px;flex:0 0 44px}#luogu-modal-box .switch input{opacity:0;width:0;height:0}#luogu-modal-box .switch-slider{position:absolute;cursor:pointer;inset:0;background:#cbd5e1;transition:.3s;border-radius:24px}#luogu-modal-box .switch-slider:before{position:absolute;content:"";height:18px;width:18px;left:3px;bottom:3px;background:#fff;transition:.3s;border-radius:50%;box-shadow:0 2px 4px rgba(0,0,0,.1)}#luogu-modal-box input:checked+.switch-slider{background:linear-gradient(135deg,${p.main},${p.main}cc)}#luogu-modal-box input:checked+.switch-slider:before{transform:translateX(20px)}#luogu-modal-box .duration-row{display:grid;grid-template-columns:1fr 1fr;gap:10px}#luogu-modal-box .duration-item{display:flex;flex-direction:column;gap:4px}#luogu-modal-box .duration-item label{font-size:11px;color:#718096;font-weight:500}#luogu-modal-box .duration-input{width:100%;padding:7px 10px;border:1.5px solid #e2e8f0;border-radius:8px;font-size:13px;background:rgba(255,255,255,.6);transition:all .2s}#luogu-modal-box .duration-input:focus{outline:none;border-color:${p.main};background:#fff}#luogu-modal-box .color-row{display:flex;align-items:center;gap:10px}#luogu-color-input{width:64px;flex:0 0 64px;height:32px;padding:2px;border:1.5px solid #e2e8f0;border-radius:8px;cursor:pointer;background:#fff}#luogu-modal-box .opacity-slider{flex:1;display:flex;align-items:center;gap:10px}#luogu-modal-box .opacity-slider input[type="range"]{flex:1;height:6px;border-radius:3px;background:#e2e8f0;outline:none;-webkit-appearance:none;appearance:none}#luogu-modal-box .opacity-slider input[type="range"]::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;width:18px;height:18px;border-radius:50%;background:${p.main};cursor:pointer;box-shadow:0 2px 4px rgba(0,0,0,.2)}#luogu-modal-box .opacity-value{min-width:42px;text-align:right;font-size:13px;font-weight:600;color:#4a5568}#luogu-modal-box .hint{font-size:11px;color:#a0aec0;margin-top:4px;line-height:1.4}#luogu-modal-box .btn-group{display:grid;grid-template-columns:1fr 1.3fr;gap:8px;margin-top:12px}#luogu-modal-box .btn{padding:9px;border:none;border-radius:8px;cursor:pointer;font-size:13px;font-weight:600;font-family:inherit;transition:all .2s}#luogu-save-btn{background:linear-gradient(135deg,${p.main},${p.main}bb);color:#fff;box-shadow:0 4px 12px ${p.main}44}#luogu-save-btn:hover{transform:translateY(-1px);box-shadow:0 6px 16px ${p.main}66}#luogu-cancel-btn{background:#f1f5f9;color:#64748b}#luogu-cancel-btn:hover{background:#e2e8f0}#luogu-modal-box .lg-geo-op{opacity:${p.geo}}`;},apply() {let st = document.getElementById('luogu-theme-style');if (!st) { st = document.createElement('style'); st.id = 'luogu-theme-style'; (document.head || document.documentElement).appendChild(st); }st.textContent = this.css(settings.color);},applyOpacity() { const w = document.getElementById('luogu-widget'); if (w) w.style.setProperty('--lap-a', settings.opacity); }};/* ============ 钟面 ============ */const GEAR_SVG = '<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19.14 12.94c.04-.31.06-.63.06-.94 0-.31-.02-.63-.06-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.04.31-.06.63-.06.94s.02.63.06.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z"/></svg>';function makeDraggable(el) {const place = (x, y) => {el.style.left = Math.round(clamp(x, 0, Math.max(0, innerWidth - el.offsetWidth))) + 'px';el.style.top = Math.round(clamp(y, 0, Math.max(0, innerHeight - el.offsetHeight))) + 'px';};let drag = null;el.addEventListener('pointerdown', e => {if ((e.pointerType === 'mouse' && e.button !== 0) || e.target.closest('button')) return;const r = el.getBoundingClientRect();drag = { dx: e.clientX - r.left, dy: e.clientY - r.top };el.classList.add('dragging');safe(() => el.setPointerCapture(e.pointerId));e.preventDefault();});el.addEventListener('pointermove', e => { if (drag) place(e.clientX - drag.dx, e.clientY - drag.dy); });const drop = () => {if (!drag) return;drag = null; el.classList.remove('dragging');const r = el.getBoundingClientRect();store.setJson(KEY.POS, { x: Math.round(r.left), y: Math.round(r.top) });};el.addEventListener('pointerup', drop);el.addEventListener('pointercancel', drop);window.addEventListener('resize', () => { const r = el.getBoundingClientRect(); place(r.left, r.top); });return place;}const Widget = {api: null,create() {if (this.api || !onLuogu()) return;const el = document.createElement('div');el.id = 'luogu-widget';el.innerHTML = `<div class="lg-head"><span id="luogu-mode">专注</span><button id="luogu-settings" title="设置" aria-label="设置">${GEAR_SVG}</button></div><div id="luogu-time">--:--</div><div class="lg-track"><div id="luogu-bar"></div></div><div class="lg-controls"><button class="lg-btn primary" id="luogu-main">开始</button><button class="lg-btn secondary" id="luogu-stop">结束</button></div>`;document.body.appendChild(el);const $ = id => el.querySelector('#' + id);const ui = { mode: $('luogu-mode'), time: $('luogu-time'), bar: $('luogu-bar'), main: $('luogu-main'), stop: $('luogu-stop') };let mode = Focus.mode, remaining = 0, ticker = null;const durOf = m => (m === 'work' ? settings.work : settings.rest) * 60;const render = () => {ui.time.textContent = fmtTime(remaining);ui.bar.style.width = clamp((1 - remaining / durOf(mode)) * 100, 0, 100) + '%';ui.mode.textContent = Focus.paused ? '已暂停' : (mode === 'work' ? '专注' : '休息');ui.main.textContent = Focus.running ? '暂停' : (Focus.paused ? '继续' : '开始');ui.stop.disabled = !Focus.isActive();el.classList.toggle('work-running', Focus.running && mode === 'work');el.classList.toggle('paused', Focus.paused);};const startTicker = () => { stopTicker(); ticker = setInterval(tick, 250); };function stopTicker() { if (ticker) { clearInterval(ticker); ticker = null; } }function tick() {const r = Math.max(0, Math.ceil((store.int(KEY.END, 0) - Date.now()) / 1000));if (r !== remaining) { remaining = r; render(); }if (r <= 0 && Focus.active && Focus.state === 'running') return nextPhase();if (!Focus.running) stopTicker();}function nextPhase() {mode = mode === 'work' ? 'rest' : 'work';Focus.begin(mode); remaining = durOf(mode);el.classList.remove('pulse'); void el.offsetWidth; el.classList.add('pulse');render(); startTicker();}ui.main.addEventListener('click', () => {if (Focus.running) { Focus.pause(remaining); stopTicker(); }else if (Focus.paused) { Focus.resume(mode, remaining); startTicker(); }else { Focus.begin(mode); remaining = durOf(mode); startTicker(); }render();});ui.stop.addEventListener('click', () => { stopTicker(); Focus.end(); mode = 'work'; remaining = durOf(mode); render(); });$('luogu-settings').addEventListener('click', () => Panel.open());document.addEventListener('visibilitychange', () => { if (!document.hidden && Focus.running) tick(); });this.api = { refresh() { if (!Focus.isActive()) remaining = durOf(mode); render(); } };remaining = Focus.running ? Math.max(0, Math.ceil((store.int(KEY.END, 0) - Date.now()) / 1000)): (Focus.paused ? Math.max(0, store.int(KEY.REMAINING, 0)) : durOf(mode));makeDraggable(el)(settings.pos.x, settings.pos.y);Theme.applyOpacity(); render();if (Focus.active && Focus.state === 'running') { if (Focus.expired) nextPhase(); else startTicker(); }}};/* ============ 设置面板(全局唯一,每次打开重建) ============ */const Panel = {nodes: null,close() {if (!this.nodes) return;this.nodes.mask.remove(); this.nodes.box.remove();document.removeEventListener('keydown', this.nodes.onKey);this.nodes = null;},chip(text, onRemove, onOpen) {const it = document.createElement('div');it.className = 'pid-item';const label = document.createElement('span');label.textContent = text;const rm = document.createElement('span');rm.className = 'remove'; rm.title = '删除'; rm.textContent = '×';it.append(label, rm);it.onclick = e => { if (e.target === rm) { e.stopPropagation(); onRemove(); } else onOpen(); };return it;},markup(p, g, cur) {return `<div class="lg-geo lg-geo-op" style="top:-30px;right:-30px;width:130px;height:130px;border-radius:50%;background:${p.main}"></div><div class="lg-geo" style="bottom:-20px;left:-25px;width:100px;height:100px;transform:rotate(45deg);border-radius:16px;background:${p.main};opacity:${(g * .75).toFixed(2)}"></div><div class="lg-geo" style="top:40%;right:25px;width:0;height:0;border-left:30px solid transparent;border-right:30px solid transparent;border-bottom:50px solid ${p.main};opacity:${(g * .85).toFixed(2)};transform:rotate(-15deg)"></div><div class="lg-geo" style="top:15%;left:-20px;width:60px;height:60px;border-radius:50%;border:6px solid ${p.main};opacity:${(g * .6).toFixed(2)}"></div><div class="lg-inner"><h3>设置</h3><div class="setting-section"><label class="setting-label">题目计划</label><input type="text" id="luogu-pid-input" placeholder="输入题号(如:P1000、CF1628D、AT_abc001_a)"><div class="pid-list" id="pid-list"></div><div class="hint">最多 ${DEFAULT.MAX_PIDS} 题,回车添加。</div></div><div class="setting-section"><div class="setting-row"><span class="setting-text">允许查看题解</span><label class="switch"><input type="checkbox" id="luogu-solution-checkbox"><span class="switch-slider"></span></label></div></div><div class="setting-section"><div class="setting-row"><span class="setting-text">启用全网阻断</span><label class="switch"><input type="checkbox" id="luogu-urlwl-checkbox"><span class="switch-slider"></span></label></div><input type="text" id="luogu-url-input" placeholder="输入网址(如 bilibili.com/video、oi-wiki.org/*)"><div class="pid-list" id="url-list"></div><div class="hint">开启后,名单外网站访问将被阻断。支持 * 通配符,回车添加,最多 ${DEFAULT.MAX_URLS} 条</div></div><div class="setting-section"><label class="setting-label">番茄钟时长(分钟)</label><div class="duration-row"><div class="duration-item"><label>工作</label><input type="number" id="luogu-work-input" class="duration-input" min="1" max="120"></div><div class="duration-item"><label>休息</label><input type="number" id="luogu-rest-input" class="duration-input" min="1" max="60"></div></div></div><div class="setting-section"><label class="setting-label">主题颜色</label><div class="color-row"><input type="color" id="luogu-color-input"><div class="opacity-slider"><input type="range" id="luogu-opacity-slider" min="0.3" max="1" step="0.05"><span class="opacity-value" id="opacity-value">${Math.round(cur * 100)}%</span></div></div><div class="hint">右侧滑块调节钟面背景透明度</div></div><div class="btn-group"><button id="luogu-cancel-btn" class="btn">取消</button><button id="luogu-save-btn" class="btn">保存</button></div></div>`;},open() {if (!onLuogu()) return;this.close();const c = settings.color, p = Theme.palette(c), cur = settings.opacity;const mask = document.createElement('div'); mask.id = 'luogu-modal-mask';const box = document.createElement('div'); box.id = 'luogu-modal-box';box.innerHTML = this.markup(p, geoAlpha(c), cur);document.body.append(mask, box);this.nodes = { mask, box, onKey: e => { if (e.key === 'Escape') this.close(); } };document.addEventListener('keydown', this.nodes.onKey);const $ = id => box.querySelector('#' + id);const pidInput = $('luogu-pid-input'), pidList = $('pid-list');const urlInput = $('luogu-url-input'), urlList = $('url-list');const slider = $('luogu-opacity-slider');const renderPidList = () => {pidList.innerHTML = '';const items = pids.get();if (!items.length) { pidList.innerHTML = '<div class="pid-empty">暂无题目</div>'; return; }for (const pid of items) pidList.appendChild(this.chip(pid, () => { pids.remove(pid); renderPidList(); }, () => { window.location.href = 'https://www.luogu.com.cn/problem/' + pid; }));};const renderUrlList = () => {urlList.innerHTML = '';const items = urls.get();if (!items.length) { urlList.innerHTML = '<div class="pid-empty">暂无网址</div>'; return; }for (const u of items) urlList.appendChild(this.chip(u, () => { urls.remove(u); renderUrlList(); }, () => { window.location.href = 'https://' + u.replace(/\*/g, ''); }));};const addPid = () => {const raw = pidInput.value.trim();if (!raw) return;const pid = raw.startsWith('AT_') ? raw : raw.toUpperCase();if (!RE.PID.test(pid)) return alert('题号格式错误:' + raw);const r = pids.add(pid, DEFAULT.MAX_PIDS);if (r === 'dup') { pidInput.value = ''; return alert('该题已在计划中'); }if (r === 'full') return alert('最多添加 ' + DEFAULT.MAX_PIDS + ' 题');pidInput.value = ''; renderPidList();};const addUrl = () => {const raw = urlInput.value.trim();if (!raw) return;const u = normUrl(raw);if (!RE.URL_ENTRY.test(u)) return alert('网址格式错误:' + raw);const r = urls.add(u, DEFAULT.MAX_URLS);if (r === 'dup') { urlInput.value = ''; return alert('该网址已在白名单中'); }if (r === 'full') return alert('最多添加 ' + DEFAULT.MAX_URLS + ' 条网址');urlInput.value = ''; renderUrlList();};const doSave = () => {const work = parseInt($('luogu-work-input').value, 10) || DEFAULT.WORK;const rest = parseInt($('luogu-rest-input').value, 10) || DEFAULT.REST;if (work < 1 || work > 120) return alert('工作时长 1-120');if (rest < 1 || rest > 60) return alert('休息时长 1-60');addPid(); addUrl();saveDurations(work, rest);saveColor($('luogu-color-input').value);solutionAllowed.set($('luogu-solution-checkbox').checked);whitelistOn.set($('luogu-urlwl-checkbox').checked);store.set(KEY.OPACITY, clamp(parseFloat(slider.value) || DEFAULT.OPACITY, 0.3, 1));Theme.apply(); Theme.applyOpacity(); SolutionHider.sync();if (Widget.api) Widget.api.refresh();this.close();};$('luogu-save-btn').onclick = doSave;$('luogu-cancel-btn').onclick = () => this.close();mask.onclick = () => this.close();pidInput.onkeydown = e => { if (e.key === 'Enter') { e.preventDefault(); addPid(); } };urlInput.onkeydown = e => { if (e.key === 'Enter') { e.preventDefault(); addUrl(); } };slider.value = cur;slider.oninput = e => {const v = parseFloat(e.target.value) || DEFAULT.OPACITY;$('opacity-value').textContent = Math.round(v * 100) + '%';const w = document.getElementById('luogu-widget');if (w) w.style.setProperty('--lap-a', v);};$('luogu-solution-checkbox').checked = solutionAllowed.get();$('luogu-urlwl-checkbox').checked = whitelistOn.get();$('luogu-work-input').value = settings.work;$('luogu-rest-input').value = settings.rest;$('luogu-color-input').value = c;renderPidList(); renderUrlList();mask.style.display = 'block'; box.style.display = 'block';pidInput.focus();}};/* ============ 启动 ============ */migrateLegacy();if (Access.enforce()) return;const boot = () => { if (onLuogu()) { Theme.apply(); Widget.create(); } };if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot, { once: true });else boot();window.addEventListener('load', () => { if (onLuogu()) SolutionHider.sync(); Access.watchRouter(); }, { once: true });})();```:::---## $\textup{V5.1}$$\textup{Upd on 2026.9.28}$让这个钟面得以在所有页面上显示。为了防止您不喜欢,我们保留 $5.0$ 的代码。:::success[$\textup{Code.}$]```javascript// ==UserScript==// @name 洛谷强力学术Pro// @namespace http://tampermonkey.net/// @version 5.1// @author wendywan// @icon https://cdn.luogu.com.cn/upload/image_hosting/psd5a03h.png// @match *://*/*// @noframes// @grant GM_getValue// @grant GM_setValue4 行未改动(function () {'use strict';/* ============ 常量 ============ */const KEY = {PIDS: 'luogu_study_plan_pids', SOLUTION: 'luogu_study_plan_solution',ACTIVE: 'luogu_focus_active', END: 'luogu_focus_end_time', STATE: 'luogu_focus_state',MODE: 'luogu_focus_current_mode', REMAINING: 'luogu_focus_remaining',WORK: 'luogu_focus_duration', REST: 'luogu_rest_duration',COLOR: 'luogu_focus_color', OPACITY: 'luogu_widget_opacity', POS: 'luogu_focus_position',URLWL: 'luogu_focus_url_whitelist', URLWL_ON: 'luogu_focus_url_whitelist_on', MIG: 'luogu_focus_migrated'};const DEFAULT = { WORK: 25, REST: 5, COLOR: '#ff6b6b', OPACITY: 0.9, POS: { x: 20, y: 100 }, WIDTH: 138, MAX_PIDS: 6, MAX_URLS: 10 };const RE = {PID: /^(P\d{3,6}|SP\d{3,5}|B\d{3,5}|CF\d+[A-Z0-9]*|AT_[a-z0-9_]+|UVA\d{3,5}|[A-Z]{2,6}\d+[A-Z0-9]*)$/i,HEX: /^#[0-9a-f]{6}$/i,URL_ENTRY: /^([a-z0-9*-]+\.)+[a-z*]{2,}(:\d+)?([/?#][\w./?#&=%+*-]*)?$/i,LUOGU: /^(https?:\/\/)?(www\.)?luogu\.com\.cn/i,SOLUTION: /\/problem\/solution\//i};const LUOGU_PATHS = [/^\/problem\//i, /^\/paste(\/.*)?$/i, /^\/record\//i, /^\/article(\/.*)?$/i, /^\/training(\/.*)?$/i];const onLuogu = () => RE.LUOGU.test(window.location.href);/* ============ 存储:GM 跨域共享,无 GM 回退 localStorage,双写保兼容 ============ */const safe = fn => { try { return fn(); } catch {} };const HAS_GM = typeof GM_getValue === 'function' && typeof GM_setValue === 'function' && typeof GM_deleteValue === 'function';const store = {get(k, d = null) { try { const v = HAS_GM ? GM_getValue(k) : localStorage.getItem(k); return v == null ? d : v; } catch { return d; } },set(k, v) { const s = String(v); if (HAS_GM) safe(() => GM_setValue(k, s)); safe(() => localStorage.setItem(k, s)); },del(k) { if (HAS_GM) safe(() => GM_deleteValue(k)); safe(() => localStorage.removeItem(k)); },int(k, d) { const n = parseInt(store.get(k), 10); return Number.isFinite(n) ? n : d; },num(k, d) { const n = parseFloat(store.get(k)); return Number.isFinite(n) ? n : d; },json(k, d) { try { const v = JSON.parse(store.get(k)); return v == null ? d : v; } catch { return d; } },setJson(k, v) { store.set(k, JSON.stringify(v)); }};const boolSetting = (key, dflt) => ({ get: () => store.get(key, String(dflt)) === 'true', set: v => store.set(key, v) });const listStore = key => ({get() { const a = store.json(key, []); return Array.isArray(a) ? a.filter(x => typeof x === 'string' && x.trim()) : []; },save(a) { store.setJson(key, a); },add(v, max) { const a = this.get(); if (a.includes(v)) return 'dup'; if (a.length >= max) return 'full'; a.push(v); this.save(a); return 'ok'; },remove(v) { const a = this.get(), i = a.indexOf(v); if (i < 0) return false; a.splice(i, 1); this.save(a); return true; }});/* ============ 通用工具 ============ */const clamp = (v, a, b) => Math.min(b, Math.max(a, v));const fmtTime = s => `${String(Math.floor(s / 60)).padStart(2, '0')}:${String(s % 60).padStart(2, '0')}`;const hexToRgb = h => { const n = parseInt(h.replace('#', ''), 16); return [(n >> 16) & 255, (n >> 8) & 255, n & 255]; };const luma = h => { const [r, g, b] = hexToRgb(h); return (0.299 * r + 0.587 * g + 0.114 * b) / 255; };const shiftHex = (h, pct) => '#' + hexToRgb(h).map(x => clamp(x + Math.round(2.55 * pct), 0, 255).toString(16).padStart(2, '0')).join('');const textOn = h => (luma(h) * 255 >= 128 ? '#111' : '#fff');const geoAlpha = h => clamp(0.4 - luma(h) * 0.22, 0.18, 0.4);const deepShade = h => (luma(h) > 0.45 ? '#' + hexToRgb(h).map(x => Math.round(x * 0.45).toString(16).padStart(2, '0')).join('') : h);const escRe = s => s.replace(/[.+?^${}()|[\]\\]/g, '\\$&');/* ============ 设置与名单 ============ */const settings = {get work() { return clamp(store.int(KEY.WORK, DEFAULT.WORK), 1, 120); },get rest() { return clamp(store.int(KEY.REST, DEFAULT.REST), 1, 60); },get color() { const c = store.get(KEY.COLOR, DEFAULT.COLOR); return RE.HEX.test(c) ? c.toLowerCase() : DEFAULT.COLOR; },get opacity() { return clamp(store.num(KEY.OPACITY, DEFAULT.OPACITY), 0.3, 1); },get pos() { const p = store.json(KEY.POS, DEFAULT.POS) || DEFAULT.POS; return { x: Number(p.x) || 0, y: Number(p.y) || 0 }; }};const pids = listStore(KEY.PIDS);const urls = listStore(KEY.URLWL);const solutionAllowed = boolSetting(KEY.SOLUTION, true);const whitelistOn = boolSetting(KEY.URLWL_ON, false);const normUrl = raw => raw.trim().toLowerCase().replace(/^https?:\/\//, '').replace(/^www\./, '').replace(/\/+$/, '');const saveDurations = (w, r) => { store.set(KEY.WORK, w); store.set(KEY.REST, r); };const saveColor = c => { if (RE.HEX.test(c)) store.set(KEY.COLOR, c.toLowerCase()); };function migrateLegacy() {if (!HAS_GM || !onLuogu() || store.get(KEY.MIG) === '1') return;for (const k of Object.values(KEY)) { const v = safe(() => localStorage.getItem(k)); if (v != null && GM_getValue(k) == null) GM_setValue(k, v); }store.set(KEY.MIG, '1');}/* ============ 专注状态机(跨页延续) ============ */const Focus = {get active() { return store.get(KEY.ACTIVE) === 'true'; },get state() { return store.get(KEY.STATE); },get mode() { return store.get(KEY.MODE) === 'rest' ? 'rest' : 'work'; },get expired() { return this.active && this.state === 'running' && Date.now() >= store.int(KEY.END, 0); },isActive() { return this.active && !this.expired; },get running() { return this.isActive() && this.state === 'running'; },get paused() { return this.isActive() && this.state === 'paused'; },begin(mode) {const m = mode === 'work' ? settings.work : settings.rest;6 行未改动pause(sec) { store.set(KEY.STATE, 'paused'); store.set(KEY.REMAINING, sec); store.del(KEY.END); },end() { [KEY.ACTIVE, KEY.END, KEY.STATE, KEY.REMAINING, KEY.MODE].forEach(k => store.del(k)); }};/* ============ 访问控制:洛谷白名单 / 题解阻断 / 站外网址白名单 / SPA 守卫 ============ */const Access = {redirectUrl() { const a = pids.get(); return 'https://www.luogu.com.cn/problem/' + (a.length ? a[0] : 'list'); },urlRule(entry) {const tail = entry.endsWith('*') ? '' : '(?=[/?#:]|$)';const body = entry.startsWith('*.')? '(?:[a-z0-9-]+\\.)*' + escRe(entry.slice(2)).split('*').join('[\\s\\S]*'): escRe(entry).split('*').join('[\\s\\S]*');return new RegExp('^(https?://)?(www\\.)?' + body + tail, 'i');},urlAllowed(href) { return urls.get().some(e => this.urlRule(e).test(href)); },solutionBlocked() { return onLuogu() && RE.SOLUTION.test(window.location.pathname) && !solutionAllowed.get(); },externalBlocked() { return whitelistOn.get() && !onLuogu() && !this.urlAllowed(window.location.href); },luoguAllowed() {if (!Focus.isActive() || Focus.paused || Focus.mode === 'rest') return true;const p = window.location.pathname.toLowerCase();if (RE.SOLUTION.test(p)) return solutionAllowed.get();return LUOGU_PATHS.some(re => re.test(p));},enforce() {const denied = this.solutionBlocked() || this.externalBlocked() || (onLuogu() && Focus.isActive() && !this.luoguAllowed());if (denied) window.location.replace(this.redirectUrl());return denied;},watchRouter() {if (window.__lapGuard) return;window.__lapGuard = true;for (const fn of ['pushState', 'replaceState']) {const raw = history[fn];history[fn] = function () { raw.apply(this, arguments); window.dispatchEvent(new Event('locationchange')); };}window.addEventListener('popstate', () => window.dispatchEvent(new Event('locationchange')));window.addEventListener('locationchange', () => this.enforce());let last = location.pathname + location.hash;setInterval(() => { const cur = location.pathname + location.hash; if (cur !== last) { last = cur; this.enforce(); } }, 800);}};/* ============ 题解入口隐藏(observer 全局唯一) ============ */const SolutionHider = {SEL: 'a[href*="/problem/solution/"],[class*="solution"],[class*="answer"],.lg-article-content',observer: null,hide(root) {if (!root.querySelectorAll) return;safe(() => {for (const el of [root, ...root.querySelectorAll(this.SEL)]) {if (el.nodeType !== 1 || !el.matches?.(this.SEL)) continue;if (!(el.textContent || '').includes('题解') && !(el.href || '').includes('/problem/solution/')) continue;Object.assign(el.style, { display: 'none', visibility: 'hidden', height: '0', overflow: 'hidden', pointerEvents: 'none' });}});},sync() {if (solutionAllowed.get()) { if (this.observer) { this.observer.disconnect(); this.observer = null; } return; }if (this.observer || !document.body) return;this.observer = new MutationObserver(ms => ms.forEach(m => m.addedNodes.forEach(n => { if (n.nodeType === 1) this.hide(n); })));this.observer.observe(document.body, { childList: true, subtree: true });this.hide(document.body);}};/* ============ 主题:全局唯一 <style>,改色整体重写 ============ */const Theme = {palette(c) { return { main: c, light: shiftHex(c, 85), dark: shiftHex(c, -20), onMain: textOn(c), chip: deepShade(c), geo: geoAlpha(c).toFixed(2) }; },css(c) { const p = this.palette(c); return this.widgetCSS(p) + this.modalCSS(p); },widgetCSS(p) {return `#luogu-widget{position:fixed;z-index:2147483644;box-sizing:border-box;width:${DEFAULT.WIDTH}px;background:rgba(255,255,255,var(--lap-a,.9));backdrop-filter:blur(6px) saturate(1.1);-webkit-backdrop-filter:blur(6px) saturate(1.1);border:1px solid #e2e5ea;border-radius:12px;box-shadow:0 4px 16px rgba(30,40,60,.16);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"PingFang SC","Microsoft YaHei",sans-serif;-webkit-font-smoothing:antialiased;user-select:none;-webkit-user-select:none;touch-action:none;overflow:hidden;cursor:grab;transition:box-shadow .25s,background-color .2s}#luogu-widget *,#luogu-widget *::before,#luogu-widget *::after{box-sizing:border-box}#luogu-widget:hover{box-shadow:0 6px 20px rgba(30,40,60,.22)}#luogu-widget.dragging{cursor:grabbing;box-shadow:0 10px 28px rgba(30,40,60,.28)}#luogu-widget.work-running{border-color:${p.main};box-shadow:0 0 0 2px ${p.main}55,0 4px 16px ${p.main}40}@keyframes luogu-pulse{0%{transform:scale(1)}35%{transform:scale(1.06)}100%{transform:scale(1)}}#luogu-widget.pulse{animation:luogu-pulse .6s ease}#luogu-widget .lg-head{display:flex;align-items:center;justify-content:space-between;height:30px;padding:6px 6px 0 10px}#luogu-mode{font-size:11px;font-weight:600;color:#8a919c;letter-spacing:1px}#luogu-widget.work-running #luogu-mode{color:${p.dark}}#luogu-widget.paused #luogu-mode{color:#d97706}#luogu-settings{width:22px;height:22px;flex:0 0 22px;border:0;border-radius:6px;background:${p.main};display:flex;align-items:center;justify-content:center;cursor:pointer;transition:transform .15s,filter .15s;box-shadow:0 1px 3px rgba(0,0,0,.2)}#luogu-settings:hover{transform:scale(1.1);filter:brightness(1.05)}#luogu-settings svg{width:13px;height:13px;fill:${p.onMain};pointer-events:none}#luogu-time{font-size:26px;font-weight:700;line-height:1.15;text-align:center;color:#2b3138;font-variant-numeric:tabular-nums;padding:0 6px 5px;white-space:nowrap}#luogu-widget .lg-track{height:4px;margin:0 10px;border-radius:2px;background:#edeff2;overflow:hidden}#luogu-bar{height:100%;width:0;background:${p.main};border-radius:2px;transition:width .3s linear}#luogu-widget .lg-controls{display:flex;gap:6px;padding:9px 8px 8px}#luogu-widget .lg-btn{flex:1;min-width:0;height:26px;border:0;border-radius:7px;font-size:12px;font-weight:600;font-family:inherit;cursor:pointer;transition:filter .15s,transform .1s}#luogu-widget .lg-btn:active:not(:disabled){transform:scale(.96)}#luogu-widget .lg-btn:disabled{opacity:.45;cursor:default}#luogu-widget .lg-btn.primary{background:${p.main};color:${p.onMain}}#luogu-widget .lg-btn.primary:hover:not(:disabled){filter:brightness(.92)}#luogu-widget .lg-btn.secondary{background:${p.light};color:${p.dark}}#luogu-widget .lg-btn.secondary:hover:not(:disabled){filter:brightness(.97)}`;},modalCSS(p) {return `#luogu-modal-mask{position:fixed;inset:0;background:rgba(0,0,0,.3);z-index:2147483645;display:none;backdrop-filter:blur(2px)}#luogu-modal-box{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);width:360px;max-width:92vw;max-height:92vh;overflow:hidden;padding:16px 18px 18px;background:rgba(255,255,255,.7);backdrop-filter:blur(16px);-webkit-backdrop-filter:blur(16px);border:1px solid rgba(255,255,255,.5);box-shadow:0 12px 40px rgba(0,0,0,.15);border-radius:14px;z-index:2147483646;display:none;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"PingFang SC",sans-serif}#luogu-modal-box *,#luogu-modal-box *::before,#luogu-modal-box *::after{box-sizing:border-box}#luogu-modal-box .lg-inner{position:relative;z-index:2;max-height:calc(92vh - 36px);overflow-y:auto;scrollbar-width:none;-ms-overflow-style:none}#luogu-modal-box .lg-inner::-webkit-scrollbar{width:0;height:0}#luogu-modal-box .lg-geo{position:absolute;pointer-events:none;z-index:1;filter:blur(1px)}#luogu-modal-box h3{margin:0 0 12px;color:#1a1a1a;text-align:center;font-size:18px;font-weight:700}#luogu-modal-box .setting-section{margin-bottom:10px}#luogu-modal-box .setting-label{display:block;margin-bottom:6px;font-size:12px;font-weight:600;color:#4a5568;letter-spacing:.3px}#luogu-pid-input,#luogu-url-input{width:100%;padding:8px 10px;border:1.5px solid #e2e8f0;border-radius:8px;font-size:13px;transition:all .2s;background:rgba(255,255,255,.6)}#luogu-pid-input:focus,#luogu-url-input:focus{border-color:${p.main};outline:none;box-shadow:0 0 0 3px ${p.main}22;background:#fff}#luogu-url-input{margin-top:8px}#luogu-modal-box .pid-list{display:flex;flex-wrap:wrap;gap:5px;margin-top:6px;min-height:24px}#luogu-modal-box .pid-item{background:linear-gradient(135deg,${p.main}26,${p.main}40);border:1px solid ${p.main}66;color:${p.chip};font-weight:600;padding:3px 9px;border-radius:12px;font-size:12px;display:flex;align-items:center;gap:6px;cursor:pointer;transition:all .2s}#luogu-modal-box .pid-item:hover{transform:translateY(-1px);box-shadow:0 2px 8px ${p.main}55;background:linear-gradient(135deg,${p.main}33,${p.main}4d)}#luogu-modal-box .pid-item>span:first-child{max-width:230px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}#luogu-modal-box .pid-item .remove{color:#ef4444;font-weight:bold;cursor:pointer;line-height:1}#luogu-modal-box .pid-empty{color:#cbd5e1;font-size:12px;padding:4px;width:100%;text-align:center}#luogu-modal-box .setting-row{display:flex;align-items:center;justify-content:space-between;padding:9px 12px;background:rgba(248,250,252,.5);border-radius:10px;border:1px solid #e2e8f0}#luogu-modal-box .setting-text{font-size:13px;color:#4a5568;font-weight:500}#luogu-modal-box .switch{position:relative;width:44px;height:24px;flex:0 0 44px}#luogu-modal-box .switch input{opacity:0;width:0;height:0}#luogu-modal-box .switch-slider{position:absolute;cursor:pointer;inset:0;background:#cbd5e1;transition:.3s;border-radius:24px}#luogu-modal-box .switch-slider:before{position:absolute;content:"";height:18px;width:18px;left:3px;bottom:3px;background:#fff;transition:.3s;border-radius:50%;box-shadow:0 2px 4px rgba(0,0,0,.1)}#luogu-modal-box input:checked+.switch-slider{background:linear-gradient(135deg,${p.main},${p.main}cc)}#luogu-modal-box input:checked+.switch-slider:before{transform:translateX(20px)}#luogu-modal-box .duration-row{display:grid;grid-template-columns:1fr 1fr;gap:10px}#luogu-modal-box .duration-item{display:flex;flex-direction:column;gap:4px}#luogu-modal-box .duration-item label{font-size:11px;color:#718096;font-weight:500}#luogu-modal-box .duration-input{width:100%;padding:7px 10px;border:1.5px solid #e2e8f0;border-radius:8px;font-size:13px;background:rgba(255,255,255,.6);transition:all .2s}#luogu-modal-box .duration-input:focus{outline:none;border-color:${p.main};background:#fff}#luogu-modal-box .color-row{display:flex;align-items:center;gap:10px}#luogu-color-input{width:64px;flex:0 0 64px;height:32px;padding:2px;border:1.5px solid #e2e8f0;border-radius:8px;cursor:pointer;background:#fff}#luogu-modal-box .opacity-slider{flex:1;display:flex;align-items:center;gap:10px}#luogu-modal-box .opacity-slider input[type="range"]{flex:1;height:6px;border-radius:3px;background:#e2e8f0;outline:none;-webkit-appearance:none;appearance:none}#luogu-modal-box .opacity-slider input[type="range"]::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;width:18px;height:18px;border-radius:50%;background:${p.main};cursor:pointer;box-shadow:0 2px 4px rgba(0,0,0,.2)}#luogu-modal-box .opacity-value{min-width:42px;text-align:right;font-size:13px;font-weight:600;color:#4a5568}#luogu-modal-box .hint{font-size:11px;color:#a0aec0;margin-top:4px;line-height:1.4}#luogu-modal-box .btn-group{display:grid;grid-template-columns:1fr 1.3fr;gap:8px;margin-top:12px}#luogu-modal-box .btn{padding:9px;border:none;border-radius:8px;cursor:pointer;font-size:13px;font-weight:600;font-family:inherit;transition:all .2s}#luogu-save-btn{background:linear-gradient(135deg,${p.main},${p.main}bb);color:#fff;box-shadow:0 4px 12px ${p.main}44}#luogu-save-btn:hover{transform:translateY(-1px);box-shadow:0 6px 16px ${p.main}66}#luogu-cancel-btn{background:#f1f5f9;color:#64748b}#luogu-cancel-btn:hover{background:#e2e8f0}#luogu-modal-box .lg-geo-op{opacity:${p.geo}}`;},apply() {let st = document.getElementById('luogu-theme-style');if (!st) { st = document.createElement('style'); st.id = 'luogu-theme-style'; (document.head || document.documentElement).appendChild(st); }st.textContent = this.css(settings.color);},applyOpacity() { const w = document.getElementById('luogu-widget'); if (w) w.style.setProperty('--lap-a', settings.opacity); }};/* ============ 钟面 ============ */const GEAR_SVG = '<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19.14 12.94c.04-.31.06-.63.06-.94 0-.31-.02-.63-.06-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.04.31-.06.63-.06.94s.02.63.06.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z"/></svg>';function makeDraggable(el) {const place = (x, y) => {el.style.left = Math.round(clamp(x, 0, Math.max(0, innerWidth - el.offsetWidth))) + 'px';el.style.top = Math.round(clamp(y, 0, Math.max(0, innerHeight - el.offsetHeight))) + 'px';};let drag = null;el.addEventListener('pointerdown', e => {if ((e.pointerType === 'mouse' && e.button !== 0) || e.target.closest('button')) return;const r = el.getBoundingClientRect();drag = { dx: e.clientX - r.left, dy: e.clientY - r.top };el.classList.add('dragging');safe(() => el.setPointerCapture(e.pointerId));e.preventDefault();});el.addEventListener('pointermove', e => { if (drag) place(e.clientX - drag.dx, e.clientY - drag.dy); });const drop = () => {if (!drag) return;drag = null; el.classList.remove('dragging');const r = el.getBoundingClientRect();store.setJson(KEY.POS, { x: Math.round(r.left), y: Math.round(r.top) });};el.addEventListener('pointerup', drop);el.addEventListener('pointercancel', drop);window.addEventListener('resize', () => { const r = el.getBoundingClientRect(); place(r.left, r.top); });return place;}const Widget = {api: null,create() {if (this.api) return;const el = document.createElement('div');el.id = 'luogu-widget';el.innerHTML = `<div class="lg-head"><span id="luogu-mode">专注</span><button id="luogu-settings" title="设置" aria-label="设置">${GEAR_SVG}</button></div><div id="luogu-time">--:--</div><div class="lg-track"><div id="luogu-bar"></div></div><div class="lg-controls"><button class="lg-btn primary" id="luogu-main">开始</button><button class="lg-btn secondary" id="luogu-stop">结束</button></div>`;document.body.appendChild(el);const $ = id => el.querySelector('#' + id);const ui = { mode: $('luogu-mode'), time: $('luogu-time'), bar: $('luogu-bar'), main: $('luogu-main'), stop: $('luogu-stop') };let mode = Focus.mode, remaining = 0, ticker = null;const durOf = m => (m === 'work' ? settings.work : settings.rest) * 60;const render = () => {ui.time.textContent = fmtTime(remaining);ui.bar.style.width = clamp((1 - remaining / durOf(mode)) * 100, 0, 100) + '%';ui.mode.textContent = Focus.paused ? '已暂停' : (mode === 'work' ? '专注' : '休息');ui.main.textContent = Focus.running ? '暂停' : (Focus.paused ? '继续' : '开始');ui.stop.disabled = !Focus.isActive();el.classList.toggle('work-running', Focus.running && mode === 'work');el.classList.toggle('paused', Focus.paused);};const startTicker = () => { stopTicker(); ticker = setInterval(tick, 250); };function stopTicker() { if (ticker) { clearInterval(ticker); ticker = null; } }function tick() {const r = Math.max(0, Math.ceil((store.int(KEY.END, 0) - Date.now()) / 1000));if (r !== remaining) { remaining = r; render(); }if (r <= 0 && Focus.active && Focus.state === 'running') return nextPhase();if (!Focus.running) stopTicker();}function nextPhase() {mode = mode === 'work' ? 'rest' : 'work';Focus.begin(mode); remaining = durOf(mode);el.classList.remove('pulse'); void el.offsetWidth; el.classList.add('pulse');render(); startTicker();}ui.main.addEventListener('click', () => {if (Focus.running) { Focus.pause(remaining); stopTicker(); }else if (Focus.paused) { Focus.resume(mode, remaining); startTicker(); }else { Focus.begin(mode); remaining = durOf(mode); startTicker(); }render();});ui.stop.addEventListener('click', () => { stopTicker(); Focus.end(); mode = 'work'; remaining = durOf(mode); render(); });$('luogu-settings').addEventListener('click', () => Panel.open());document.addEventListener('visibilitychange', () => { if (!document.hidden && Focus.running) tick(); });this.api = { refresh() { if (!Focus.isActive()) remaining = durOf(mode); render(); } };remaining = Focus.running ? Math.max(0, Math.ceil((store.int(KEY.END, 0) - Date.now()) / 1000)): (Focus.paused ? Math.max(0, store.int(KEY.REMAINING, 0)) : durOf(mode));makeDraggable(el)(settings.pos.x, settings.pos.y);Theme.applyOpacity(); render();if (Focus.active && Focus.state === 'running') { if (Focus.expired) nextPhase(); else startTicker(); }}};/* ============ 设置面板(全局唯一,每次打开重建) ============ */const Panel = {nodes: null,close() {if (!this.nodes) return;this.nodes.mask.remove(); this.nodes.box.remove();document.removeEventListener('keydown', this.nodes.onKey);this.nodes = null;},chip(text, onRemove, onOpen) {const it = document.createElement('div');it.className = 'pid-item';const label = document.createElement('span');label.textContent = text;const rm = document.createElement('span');rm.className = 'remove'; rm.title = '删除'; rm.textContent = '×';it.append(label, rm);it.onclick = e => { if (e.target === rm) { e.stopPropagation(); onRemove(); } else onOpen(); };return it;},markup(p, g, cur) {return `<div class="lg-geo lg-geo-op" style="top:-30px;right:-30px;width:130px;height:130px;border-radius:50%;background:${p.main}"></div><div class="lg-geo" style="bottom:-20px;left:-25px;width:100px;height:100px;transform:rotate(45deg);border-radius:16px;background:${p.main};opacity:${(g * .75).toFixed(2)}"></div><div class="lg-geo" style="top:40%;right:25px;width:0;height:0;border-left:30px solid transparent;border-right:30px solid transparent;border-bottom:50px solid ${p.main};opacity:${(g * .85).toFixed(2)};transform:rotate(-15deg)"></div><div class="lg-geo" style="top:15%;left:-20px;width:60px;height:60px;border-radius:50%;border:6px solid ${p.main};opacity:${(g * .6).toFixed(2)}"></div><div class="lg-inner"><h3>设置</h3><div class="setting-section"><label class="setting-label">题目计划</label><input type="text" id="luogu-pid-input" placeholder="输入题号(如:P1000、CF1628D、AT_abc001_a)"><div class="pid-list" id="pid-list"></div><div class="hint">最多 ${DEFAULT.MAX_PIDS} 题,回车添加。</div></div><div class="setting-section"><div class="setting-row"><span class="setting-text">允许查看题解</span><label class="switch"><input type="checkbox" id="luogu-solution-checkbox"><span class="switch-slider"></span></label></div></div><div class="setting-section"><div class="setting-row"><span class="setting-text">启用全网阻断</span><label class="switch"><input type="checkbox" id="luogu-urlwl-checkbox"><span class="switch-slider"></span></label></div><input type="text" id="luogu-url-input" placeholder="输入网址(如 bilibili.com/video、oi-wiki.org/*)"><div class="pid-list" id="url-list"></div><div class="hint">开启后,名单外网站访问将被阻断。支持 * 通配符,回车添加,最多 ${DEFAULT.MAX_URLS} 条</div></div><div class="setting-section"><label class="setting-label">番茄钟时长(分钟)</label><div class="duration-row"><div class="duration-item"><label>工作</label><input type="number" id="luogu-work-input" class="duration-input" min="1" max="120"></div><div class="duration-item"><label>休息</label><input type="number" id="luogu-rest-input" class="duration-input" min="1" max="60"></div></div></div><div class="setting-section"><label class="setting-label">主题颜色</label><div class="color-row"><input type="color" id="luogu-color-input"><div class="opacity-slider"><input type="range" id="luogu-opacity-slider" min="0.3" max="1" step="0.05"><span class="opacity-value" id="opacity-value">${Math.round(cur * 100)}%</span></div></div><div class="hint">右侧滑块调节钟面背景透明度</div></div><div class="btn-group"><button id="luogu-cancel-btn" class="btn">取消</button><button id="luogu-save-btn" class="btn">保存</button></div></div>`;},open() {this.close();const c = settings.color, p = Theme.palette(c), cur = settings.opacity;const mask = document.createElement('div'); mask.id = 'luogu-modal-mask';const box = document.createElement('div'); box.id = 'luogu-modal-box';box.innerHTML = this.markup(p, geoAlpha(c), cur);document.body.append(mask, box);this.nodes = { mask, box, onKey: e => { if (e.key === 'Escape') this.close(); } };document.addEventListener('keydown', this.nodes.onKey);const $ = id => box.querySelector('#' + id);const pidInput = $('luogu-pid-input'), pidList = $('pid-list');const urlInput = $('luogu-url-input'), urlList = $('url-list');const slider = $('luogu-opacity-slider');const renderPidList = () => {pidList.innerHTML = '';const items = pids.get();if (!items.length) { pidList.innerHTML = '<div class="pid-empty">暂无题目</div>'; return; }for (const pid of items) pidList.appendChild(this.chip(pid, () => { pids.remove(pid); renderPidList(); }, () => { window.location.href = 'https://www.luogu.com.cn/problem/' + pid; }));};const renderUrlList = () => {urlList.innerHTML = '';const items = urls.get();if (!items.length) { urlList.innerHTML = '<div class="pid-empty">暂无网址</div>'; return; }for (const u of items) urlList.appendChild(this.chip(u, () => { urls.remove(u); renderUrlList(); }, () => { window.location.href = 'https://' + u.replace(/\*/g, ''); }));};const addPid = () => {const raw = pidInput.value.trim();if (!raw) return;const pid = raw.startsWith('AT_') ? raw : raw.toUpperCase();if (!RE.PID.test(pid)) return alert('题号格式错误:' + raw);const r = pids.add(pid, DEFAULT.MAX_PIDS);if (r === 'dup') { pidInput.value = ''; return alert('该题已在计划中'); }if (r === 'full') return alert('最多添加 ' + DEFAULT.MAX_PIDS + ' 题');pidInput.value = ''; renderPidList();};const addUrl = () => {const raw = urlInput.value.trim();if (!raw) return;const u = normUrl(raw);if (!RE.URL_ENTRY.test(u)) return alert('网址格式错误:' + raw);const r = urls.add(u, DEFAULT.MAX_URLS);if (r === 'dup') { urlInput.value = ''; return alert('该网址已在白名单中'); }if (r === 'full') return alert('最多添加 ' + DEFAULT.MAX_URLS + ' 条网址');urlInput.value = ''; renderUrlList();};const doSave = () => {const work = parseInt($('luogu-work-input').value, 10) || DEFAULT.WORK;const rest = parseInt($('luogu-rest-input').value, 10) || DEFAULT.REST;if (work < 1 || work > 120) return alert('工作时长 1-120');if (rest < 1 || rest > 60) return alert('休息时长 1-60');addPid(); addUrl();saveDurations(work, rest);saveColor($('luogu-color-input').value);solutionAllowed.set($('luogu-solution-checkbox').checked);whitelistOn.set($('luogu-urlwl-checkbox').checked);store.set(KEY.OPACITY, clamp(parseFloat(slider.value) || DEFAULT.OPACITY, 0.3, 1));Theme.apply(); Theme.applyOpacity();if (onLuogu()) SolutionHider.sync();if (Widget.api) Widget.api.refresh();this.close();};$('luogu-save-btn').onclick = doSave;$('luogu-cancel-btn').onclick = () => this.close();mask.onclick = () => this.close();pidInput.onkeydown = e => { if (e.key === 'Enter') { e.preventDefault(); addPid(); } };urlInput.onkeydown = e => { if (e.key === 'Enter') { e.preventDefault(); addUrl(); } };slider.value = cur;slider.oninput = e => {const v = parseFloat(e.target.value) || DEFAULT.OPACITY;$('opacity-value').textContent = Math.round(v * 100) + '%';const w = document.getElementById('luogu-widget');if (w) w.style.setProperty('--lap-a', v);};$('luogu-solution-checkbox').checked = solutionAllowed.get();$('luogu-urlwl-checkbox').checked = whitelistOn.get();$('luogu-work-input').value = settings.work;$('luogu-rest-input').value = settings.rest;$('luogu-color-input').value = c;renderPidList(); renderUrlList();mask.style.display = 'block'; box.style.display = 'block';pidInput.focus();}};/* ============ 启动 ============ */migrateLegacy();if (Access.enforce()) return;const boot = () => { Theme.apply(); Widget.create(); }; // 钟面全站常驻if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot, { once: true });else boot();window.addEventListener('load', () => { if (onLuogu()) SolutionHider.sync(); Access.watchRouter(); }, { once: true });})();```:::---有什么建议可以评论[私信](https://www.luogu.com.cn/chat?uid=1357680),持续更新。谢谢你看到这里~