正文
增加 1472 行删除 1413 行
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496// ==UserScript==// @name Luogu Display Better// @namespace https://github.com/Luogu-Plugins// @version 1.2.0// @description Change your Luogu style what you like best// @author Luogu-Plugins// @match *://www.luogu.com.cn/*// @match *://www.luogu.com/*// @connect github.com// @connect raw.githubusercontent.com// @connect cdn.jsdelivr.net// @connect fastly.jsdelivr.net// @connect gcore.jsdelivr.net// @connect testingcf.jsdelivr.net// @connect purge.jsdelivr.net// @connect cdn.jsdmirror.com// @connect jsd.cdn.zzko.cn// @connect ghproxy.net// @connect ghfast.top// @connect gh-proxy.com// @connect ghproxy.homeboyc.cn// @connect ghp.ci// @connect moeyy.cn// @connect v6.gh-proxy.org// @connect ghfile.geekertao.top// @connect gh.geekertao.top// @connect github.dpik.top// @connect gh.felicity.ac.cn// @connect gh.llkk.cc// @connect raw.gitmirror.com// @connect raw.staticdn.net// @connect raw.githubusercontents.com// @icon https://fecdn.luogu.com.cn/columba/static.325908fec383795b.logo-single-color.svg// @grant GM_addElement// @grant GM_xmlhttpRequest// @grant GM_info// @grant unsafeWindow// @run-at document-end// ==/UserScript==(function() {'use strict';const STYLE_IDS = {rounded: 'ldb-rounded-style',blur: 'ldb-blur-style',opacity: 'ldb-opacity-style',editorLayout: 'ldb-editor-layout-style',bgFullscreen: 'ldb-bgfullscreen-style',adBlock: 'ldb-adblock-style',customCSS: 'ldb-custom-style',idePadding: 'ldb-ide-padding-style',scrollbar: 'ldb-scrollbar-style'};const EDITOR_GAP = 10;const EDITOR_Z_INDEX = 1500;const DOM_POLL_INTERVAL = 200;const SETTINGS_PANEL_DELAY = 150;const UPDATE_URLS = {stable: ['https://cdn.jsdmirror.com/gh/Luogu-Plugins/Luogu-Display-Better@main/LuoguDisplayBetter.user.js','https://jsd.cdn.zzko.cn/gh/Luogu-Plugins/Luogu-Display-Better@main/LuoguDisplayBetter.user.js','https://ghproxy.net/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/main/LuoguDisplayBetter.user.js','https://ghfast.top/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/main/LuoguDisplayBetter.user.js','https://gh-proxy.com/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/main/LuoguDisplayBetter.user.js','https://gh.llkk.cc/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/main/LuoguDisplayBetter.user.js','https://ghproxy.homeboyc.cn/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/main/LuoguDisplayBetter.user.js','https://moeyy.cn/gh-proxy/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/main/LuoguDisplayBetter.user.js','https://v6.gh-proxy.org/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/main/LuoguDisplayBetter.user.js','https://ghfile.geekertao.top/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/main/LuoguDisplayBetter.user.js','https://gh.geekertao.top/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/main/LuoguDisplayBetter.user.js','https://github.dpik.top/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/main/LuoguDisplayBetter.user.js','https://gh.felicity.ac.cn/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/main/LuoguDisplayBetter.user.js','https://ghp.ci/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/main/LuoguDisplayBetter.user.js','https://raw.gitmirror.com/Luogu-Plugins/Luogu-Display-Better/main/LuoguDisplayBetter.user.js','https://raw.staticdn.net/Luogu-Plugins/Luogu-Display-Better/main/LuoguDisplayBetter.user.js','https://raw.githubusercontents.com/Luogu-Plugins/Luogu-Display-Better/main/LuoguDisplayBetter.user.js','https://fastly.jsdelivr.net/gh/Luogu-Plugins/Luogu-Display-Better@main/LuoguDisplayBetter.user.js','https://gcore.jsdelivr.net/gh/Luogu-Plugins/Luogu-Display-Better@main/LuoguDisplayBetter.user.js','https://testingcf.jsdelivr.net/gh/Luogu-Plugins/Luogu-Display-Better@main/LuoguDisplayBetter.user.js','https://cdn.jsdelivr.net/gh/Luogu-Plugins/Luogu-Display-Better@main/LuoguDisplayBetter.user.js','https://github.com/Luogu-Plugins/Luogu-Display-Better/raw/main/LuoguDisplayBetter.user.js','https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/main/LuoguDisplayBetter.user.js'],latest: ['https://cdn.jsdmirror.com/gh/Luogu-Plugins/Luogu-Display-Better@dev/LuoguDisplayBetter.user.js','https://jsd.cdn.zzko.cn/gh/Luogu-Plugins/Luogu-Display-Better@dev/LuoguDisplayBetter.user.js','https://ghproxy.net/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/dev/LuoguDisplayBetter.user.js','https://ghfast.top/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/dev/LuoguDisplayBetter.user.js','https://gh-proxy.com/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/dev/LuoguDisplayBetter.user.js','https://gh.llkk.cc/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/dev/LuoguDisplayBetter.user.js','https://ghproxy.homeboyc.cn/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/dev/LuoguDisplayBetter.user.js','https://moeyy.cn/gh-proxy/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/dev/LuoguDisplayBetter.user.js','https://v6.gh-proxy.org/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/dev/LuoguDisplayBetter.user.js','https://ghfile.geekertao.top/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/dev/LuoguDisplayBetter.user.js','https://gh.geekertao.top/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/dev/LuoguDisplayBetter.user.js','https://github.dpik.top/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/dev/LuoguDisplayBetter.user.js','https://gh.felicity.ac.cn/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/dev/LuoguDisplayBetter.user.js','https://ghp.ci/https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/dev/LuoguDisplayBetter.user.js','https://raw.gitmirror.com/Luogu-Plugins/Luogu-Display-Better/dev/LuoguDisplayBetter.user.js','https://raw.staticdn.net/Luogu-Plugins/Luogu-Display-Better/dev/LuoguDisplayBetter.user.js','https://raw.githubusercontents.com/Luogu-Plugins/Luogu-Display-Better/dev/LuoguDisplayBetter.user.js','https://fastly.jsdelivr.net/gh/Luogu-Plugins/Luogu-Display-Better@dev/LuoguDisplayBetter.user.js','https://gcore.jsdelivr.net/gh/Luogu-Plugins/Luogu-Display-Better@dev/LuoguDisplayBetter.user.js','https://testingcf.jsdelivr.net/gh/Luogu-Plugins/Luogu-Display-Better@dev/LuoguDisplayBetter.user.js','https://cdn.jsdelivr.net/gh/Luogu-Plugins/Luogu-Display-Better@dev/LuoguDisplayBetter.user.js','https://github.com/Luogu-Plugins/Luogu-Display-Better/raw/dev/LuoguDisplayBetter.user.js','https://raw.githubusercontent.com/Luogu-Plugins/Luogu-Display-Better/dev/LuoguDisplayBetter.user.js']};let cardborderRad, picborderRad, blurValue, opacityValue;let cardRounded, picRounded, bgFullscreen, adBlock, customCSS, updateChannel;let panelCreated = false;let panelElement = null;let customCssTextarea = null;let customCssSaveTimer = null;let layoutUpdateTimer = null;let domPollTimer = null;let bgUpdateRaf = null;let bgObserver = null;function removeStyleElement(id) {const el = document.getElementById(id);if (el) el.remove();}function computeCardColor() {const alpha = opacityValue / 100;const themePage = document.querySelector('.theme-page');let baseColor = '255, 255, 255';if (themePage) {const native = getComputedStyle(themePage).getPropertyValue('--theme-card-background').trim();if (native) {const m = native.match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/);if (m) baseColor = `${m[1]}, ${m[2]}, ${m[3]}`;}}return `rgba(${baseColor}, ${alpha})`;}function copyDataAttributes(source, target) {for (const attr of source.attributes) {if (attr.name.startsWith('data-v-')) {target.setAttribute(attr.name, attr.value);}}}function compareVersions(a, b) {const pa = a.split('.').map(Number);const pb = b.split('.').map(Number);for (let i = 0; i < Math.max(pa.length, pb.length); i++) {const na = pa[i] || 0;const nb = pb[i] || 0;if (na > nb) return 1;if (na < nb) return -1;}return 0;}function loadSettings() {cardborderRad = parseFloat(localStorage.getItem("LuoguDisplayBetter-cardborderRad") ?? 15);picborderRad = parseFloat(localStorage.getItem("LuoguDisplayBetter-picborderRad") ?? 8);blurValue = parseFloat(localStorage.getItem("LuoguDisplayBetter-blur") ?? 10);opacityValue = parseFloat(localStorage.getItem("LuoguDisplayBetter-opacity") ?? 75);cardRounded = localStorage.getItem("LuoguDisplayBetter-cardRounded") !== 'false';picRounded = localStorage.getItem("LuoguDisplayBetter-picRounded") !== 'false';adBlock = localStorage.getItem("LuoguDisplayBetter-adBlock") === 'true';bgFullscreen = localStorage.getItem("LuoguDisplayBetter-bgFullscreen") !== 'false';customCSS = localStorage.getItem("LuoguDisplayBetter-customCSS") ?? '';updateChannel = localStorage.getItem("LuoguDisplayBetter-updateChannel") ?? 'stable';}function writeDefaultSettings() {const defaults = {"LuoguDisplayBetter-cardborderRad": 15,"LuoguDisplayBetter-picborderRad": 8,"LuoguDisplayBetter-blur": 10,"LuoguDisplayBetter-cardRounded": true,"LuoguDisplayBetter-picRounded": true,"LuoguDisplayBetter-adBlock": false,"LuoguDisplayBetter-bgFullscreen": true,"LuoguDisplayBetter-opacity": 75,"LuoguDisplayBetter-customCSS": '',"LuoguDisplayBetter-updateChannel": 'stable'};for (const [key, value] of Object.entries(defaults)) {localStorage.setItem(key, value);}}function saveAndApply(key, value) {localStorage.setItem(key, value);loadSettings();applyAll();}function applyRoundedCorners() {removeStyleElement(STYLE_IDS.rounded);if (isNaN(cardborderRad) && isNaN(picborderRad)) return;const cardRadius = cardborderRad + 'px';const picRadius = picborderRad + 'px';let css = '';if (cardRounded) {css = `.l-card, .lg-article, .card { border-radius: ${cardRadius} !important; }.swal2-popup { border-radius: ${cardRadius} !important; }.l-form-layout, .am-panel { border-radius: ${cardRadius} !important; }.author, .meta {border-top-left-radius: ${cardRadius} !important;border-top-right-radius: ${cardRadius} !important;border-bottom-left-radius: 0px !important;border-bottom-right-radius: 0px !important;}.dropdown .center, .cs-dialog { border-radius: ${cardRadius} !important; }.user-header-top { border-top-left-radius: ${cardRadius}; border-top-right-radius: ${cardRadius}; }.user-header-bottom { border-bottom-left-radius: ${cardRadius}; border-bottom-right-radius: ${cardRadius}; }.user-nav { border-bottom-left-radius: ${cardRadius}; border-bottom-right-radius: ${cardRadius}; }.test-case { border-radius: 10px; }html.ldb-bgfullscreen .article-banner.article-banner { border-top-left-radius: ${cardRadius} !important; border-top-right-radius: ${cardRadius} !important; }html.ldb-bgfullscreen .article-content.article-content { border-bottom-left-radius: ${cardRadius} !important; border-bottom-right-radius: ${cardRadius} !important; }html.ldb-bgfullscreen .toc.toc { border-radius: .5em !important; }.ide-container { border-radius: ${cardRadius} !important; }.ide-textarea[readonly].lfe-code { border-bottom-right-radius: ${cardRadius} !important; }.am-viewport { border-radius: ${cardRadius} !important; }.am-slider-default {background-color: transparent !important;-webkit-box-shadow: 0 0 0px rgba(0,0,0,0) !important;box-shadow: 0 0 0px rgba(0,0,0,0) !important;}.casket.cs-full-screen {border-radius: ${cardRadius} !important;overflow: hidden !important;}`;}if (picRounded) css += `img { border-radius: ${picRadius} !important; }`;const style = document.createElement('style');style.id = STYLE_IDS.rounded;style.textContent = css;document.head.appendChild(style);}function applyCardBlur() {removeStyleElement(STYLE_IDS.blur);if (isNaN(blurValue)) return;const val = blurValue === 0 ? 'none' : `blur(${blurValue}px)`;const style = document.createElement('style');style.id = STYLE_IDS.blur;style.textContent = `.lg-article, .card:not(:has(canvas)), .l-card:not(:has(canvas)) { backdrop-filter: ${val} !important; -webkit-backdrop-filter: ${val} !important; }.dropdown .center, .popup { backdrop-filter: ${val} !important; -webkit-backdrop-filter: ${val} !important; }.am-comment-hd, .am-comment-bd { backdrop-filter: ${val} !important; -webkit-backdrop-filter: ${val} !important; }.article-banner { backdrop-filter: ${val} !important; -webkit-backdrop-filter: ${val} !important; }.top-bar, .sidebar, .nav-group, nav.lfe-body, .user-nav, .wrapper.wrapped.lfe-body.header-layout.tiny { backdrop-filter: ${val} !important; -webkit-backdrop-filter: ${val} !important; }.dropdown, .dropdown .center, .popup,.lfe-dropdown, .el-dropdown-menu,.el-popper, .dropdown-menu,.ant-dropdown, .ant-select-dropdown {z-index: 999999 !important;transform: translateZ(0) !important;}.dropdown-container, .el-popper, .el-dropdown-menu,.lfe-dropdown, .ant-dropdown, .ant-select-dropdown,.dropdown-menu { overflow: visible !important; }.header-layout, .top-bar { z-index: 1000 !important; }`;document.head.appendChild(style);}function applyCardOpacity() {removeStyleElement(STYLE_IDS.opacity);if (isNaN(opacityValue)) return;const cardColor = computeCardColor();const style = document.createElement('style');style.id = STYLE_IDS.opacity;style.textContent = `.lg-article, .l-card, .card { background-color: ${cardColor} !important; }.dropdown .center, .popup { background-color: ${cardColor} !important; }.am-comment-hd, .am-comment-bd { background-color: ${cardColor} !important; }nav.lfe-body > div { background-color: ${cardColor} !important; }.user-header-bottom { background-color: transparent !important; }.ide-container { background-color: ${cardColor} !important; }.panel-layout>.panel-divider.with-icon { background-color: transparent !important; }.panel-layout>.panel-divider.dragging { background-color: var(--lfe-color--primary) !important; }.ͼ2 .cm-gutters, .ide-toolbar { background-color: transparent !important; border: 0px solid transparent !important; }input:not([type=range]), textarea, .refined-input { background-color: transparent !important; }.panel-divider, .layout-horizontal>.panel-divider { background-color: transparent !important; }.combo-wrapper>.text, .lform-size-middle.block-item.tag-button,.casket.cs-main:not(.cs-full-screen),.casket:not(.cs-full-screen) .cs-header,.casket:not(.cs-full-screen) .cs-footer,code[class*=language-], pre[class*=language-], .lfe-code { background-color: transparent !important; }`;document.head.appendChild(style);const themePage = document.querySelector('.theme-page');if (themePage) {themePage.style.setProperty('--theme-card-background', cardColor);}}function relocateEditorToBody() {const editors = document.querySelectorAll('.casket.cs-full-screen');if (!editors.length) return false;editors.forEach(el => {if (el.parentElement !== document.body) {document.body.appendChild(el);}});return true;}function measureEditorRect() {const topBar = document.querySelector('.top-bar');const topH = topBar ? Math.round(topBar.getBoundingClientRect().height) : 48;let sideW = 0;const sidebar = document.querySelector('nav.sidebar');if (sidebar) {const rect = sidebar.getBoundingClientRect();const cs = getComputedStyle(sidebar);if (rect.width > 0 && cs.display !== 'none' && cs.visibility !== 'hidden') {sideW = Math.round(rect.width);}}const docEl = document.documentElement;const vw = docEl.clientWidth || window.innerWidth;const vh = docEl.clientHeight || window.innerHeight;const gap = EDITOR_GAP;return {top: topH + gap,left: sideW + gap,width: Math.max(200, vw - sideW - gap * 2),height: Math.max(200, vh - topH - gap * 2)};}function applyFullscreenEditorLayout() {removeStyleElement(STYLE_IDS.editorLayout);if (!relocateEditorToBody()) return;const rect = measureEditorRect();const cardColor = computeCardColor();const style = document.createElement('style');style.id = STYLE_IDS.editorLayout;style.textContent = `.casket.cs-full-screen,.casket.cs-full-screen .cs-header,.casket.cs-full-screen .cs-footer {background-color: ${cardColor} !important;}.casket.cs-main.cs-full-screen {position: fixed !important;top: ${rect.top}px !important;left: ${rect.left}px !important;right: auto !important;bottom: auto !important;width: ${rect.width}px !important;height: ${rect.height}px !important;max-width: none !important;max-height: none !important;margin: 0 !important;padding: 0 !important;border: 0 !important;z-index: ${EDITOR_Z_INDEX} !important;display: flex !important;flex-direction: column !important;overflow: hidden !important;box-sizing: border-box !important;}.casket.cs-full-screen > * {min-height: 0 !important;min-width: 0 !important;box-sizing: border-box !important;}.casket.cs-full-screen .cs-content {flex: 1 1 auto !important;height: auto !important;overflow: hidden !important;}.casket.cs-full-screen .cs-editor,.casket.cs-full-screen .cs-viewer,.casket.cs-full-screen .cm-editor {min-height: 0 !important;height: 100% !important;overflow: hidden !important;}.casket.cs-full-screen .cm-scroller {overflow-y: auto !important;max-height: 100% !important;}`;document.head.appendChild(style);}function scheduleEditorLayoutUpdate() {if (layoutUpdateTimer) return;layoutUpdateTimer = requestAnimationFrame(() => {layoutUpdateTimer = null;applyFullscreenEditorLayout();});}function restoreThemeVars(themePage) {if (!themePage || !themePage._ldbSavedVars) return;for (const [key, value] of Object.entries(themePage._ldbSavedVars)) {if (value) {themePage.style.setProperty(key, value);} else {themePage.style.removeProperty(key);}}delete themePage._ldbSavedVars;}function resolveBackgroundImage(themePage) {if (themePage) {const cs = getComputedStyle(themePage);const img = cs.getPropertyValue('--theme-body-image').trim();if (img && img !== 'none') {const urlMatch = img.match(/url\(["']?([^"')]+)["']?\)/);return {image: urlMatch ? `url("${urlMatch[1]}")` : `url("${img.replace(/^["']|["']$/g, '')}")`,repeat: cs.getPropertyValue('--theme-body-image-repeat').trim() || 'no-repeat',size: cs.getPropertyValue('--theme-body-image-size').trim() || 'cover',position: cs.getPropertyValue('--theme-body-image-position').trim() || 'center',filter: cs.getPropertyValue('--theme-body-color-filter').trim() || 'none'};}}const themeScript = document.getElementById('luogu-theme');if (themeScript) {try {const data = JSON.parse(themeScript.textContent);if (data && data.lBody && data.lBody.image) {const midOpts = data.lBody.midOpts || {};let position = 'center';if (Array.isArray(midOpts.position) && midOpts.position.length >= 2) {position = `${midOpts.position[0]}% ${midOpts.position[1]}%`;}let filter = 'none';if (typeof midOpts.brightness === 'number' && midOpts.brightness !== 0) {filter = `brightness(${100 + midOpts.brightness}%)`;}return {image: `url("${data.lBody.image}")`,repeat: midOpts.notEmpty === false ? 'repeat' : 'no-repeat',size: midOpts.size || 'cover',position: position,filter: filter};}} catch (e) {}}const bgDiv = document.querySelector('.header-layout .background');if (bgDiv) {const style = getComputedStyle(bgDiv);if (style.backgroundImage && style.backgroundImage !== 'none') {return {image: style.backgroundImage,repeat: style.backgroundRepeat || 'no-repeat',size: style.backgroundSize || 'cover',position: style.backgroundPosition || 'center',filter: 'none'};}}return null;}function forceMainTransparent() {const list = document.querySelectorAll('.main-container > main, main');list.forEach(el => {const bgc = el.style.getPropertyValue('background-color').trim();const bg = el.style.getPropertyValue('background').trim();if (bgc && bgc !== 'transparent' && bgc !== 'rgba(0, 0, 0, 0)') {el.style.setProperty('background-color', 'transparent', 'important');}if (bg && bg !== 'transparent' && bg !== 'none') {el.style.setProperty('background', 'transparent', 'important');}});}function applyFullscreenBackground() {removeStyleElement(STYLE_IDS.bgFullscreen);document.documentElement.classList.remove('ldb-bgfullscreen');const themePage = document.querySelector('.theme-page');restoreThemeVars(themePage);if (!bgFullscreen) return;const bg = resolveBackgroundImage(themePage);if (!bg) return;if (themePage) {const varsToOverride = ['--theme-body-image','--theme-body-color','--theme-body-mid-mask','--theme-body-color-filter','--theme-body-back'];const saved = {};for (const v of varsToOverride) {saved[v] = themePage.style.getPropertyValue(v);}themePage._ldbSavedVars = saved;themePage.style.setProperty('--theme-body-image', 'none');themePage.style.setProperty('--theme-body-color', 'none');themePage.style.setProperty('--theme-body-mid-mask', 'none');themePage.style.setProperty('--theme-body-color-filter', 'none');themePage.style.setProperty('--theme-body-back', 'transparent');}const nav = document.querySelector('.container nav');if (nav && location.pathname === '/') nav.classList.remove('user-nav');document.documentElement.classList.add('ldb-bgfullscreen');const styleEl = document.createElement('style');styleEl.id = STYLE_IDS.bgFullscreen;styleEl.textContent = `html.ldb-bgfullscreen {background: transparent !important;background-image: none !important;}html.ldb-bgfullscreen::before {content: '' !important;position: fixed !important;top: 0 !important;left: 0 !important;right: 0 !important;bottom: 0 !important;z-index: -1 !important;pointer-events: none !important;background-image: ${bg.image} !important;background-repeat: ${bg.repeat} !important;background-position: ${bg.position} !important;background-size: ${bg.size} !important;filter: ${bg.filter} !important;-webkit-filter: ${bg.filter} !important;}.header-layout.tiny[data-v-7ddab1d5], .lfe-body[data-v-12f19ddc] { background: transparent !important; }.article-banner + div[data-v-fc349d1c] { background: transparent !important; }html.ldb-bgfullscreen .lcolor-bg-background { background: transparent !important; }html.ldb-bgfullscreen .article-banner.article-banner {background: rgba(245, 245, 245, ${opacityValue / 100}) !important;}html.ldb-bgfullscreen .article-content.article-content {background: rgba(255, 255, 255, ${opacityValue / 100}) !important;}html.ldb-bgfullscreen .toc.toc {background: white !important;box-shadow: 0 2px 4px 0 rgba(0, 0, 0, .15), 0 0 1px 0 rgba(0, 0, 0, .5) inset;padding: 3px 8px;}html.ldb-bgfullscreen body {background: transparent !important;background-image: none !important;}html.ldb-bgfullscreen main,html.ldb-bgfullscreen .main-container > main {background: transparent !important;background-color: transparent !important;}html.ldb-bgfullscreen .main-container,html.ldb-bgfullscreen #app-old,html.ldb-bgfullscreen .lg-index-content,html.ldb-bgfullscreen .lg-index-content .am-g,html.ldb-bgfullscreen .am-panel {background: transparent !important;background-color: transparent !important;}html.ldb-bgfullscreen .header-layout .background { opacity: 0; }html.ldb-bgfullscreen .wrapper.wrapped:not(.header-layout) .background { display: none; }html.ldb-bgfullscreen .wrapper.wrapped:not(.header-layout) { background: transparent !important; }html.ldb-bgfullscreen .footer { background: transparent !important; }html.ldb-bgfullscreen .theme-page { background: transparent !important; }html.ldb-bgfullscreen .top-bar,html.ldb-bgfullscreen .sidebar,html.ldb-bgfullscreen .nav-group,html.ldb-bgfullscreen nav.lfe-body,html.ldb-bgfullscreen nav.lfe-body > div,html.ldb-bgfullscreen .user-nav,html.ldb-bgfullscreen .header-layout {background: transparent !important;background-color: transparent !important;}html.ldb-bgfullscreen .top-bar { --theme-navi-back: transparent !important; }html.ldb-bgfullscreen body::before,html.ldb-bgfullscreen body::after,html.ldb-bgfullscreen #app::before,html.ldb-bgfullscreen #app::after {background: none !important;background-image: none !important;}html.ldb-bgfullscreen #app { background: transparent !important; }`;document.head.appendChild(styleEl);forceMainTransparent();}function cleanThemeBackground() {document.querySelectorAll('.theme-page').forEach(el => {if (el.classList.contains('theme-frosted')) {el.classList.remove('theme-frosted');}if (el.hasAttribute('style')) {el.removeAttribute('style');}});}const BG_VAR_OVERRIDES = [['--theme-body-image', 'none'],['--theme-body-color', 'none'],['--theme-body-mid-mask', 'none'],['--theme-body-color-filter', 'none'],['--theme-body-back', 'transparent']];function isFullscreenBackgroundApplied() {if (!document.documentElement.classList.contains('ldb-bgfullscreen')) return false;if (!document.getElementById(STYLE_IDS.bgFullscreen)) return false;const themePage = document.querySelector('.theme-page');if (!themePage) return true;if (themePage.classList.contains('theme-frosted')) return false;if (!themePage._ldbSavedVars) return false;for (const [name, value] of BG_VAR_OVERRIDES) {if (themePage.style.getPropertyValue(name) !== value) return false;}return true;}function refreshThemeBackground(force) {if (bgUpdateRaf) return;bgUpdateRaf = requestAnimationFrame(() => {bgUpdateRaf = null;if (!force && bgFullscreen && isFullscreenBackgroundApplied()) return;cleanThemeBackground();if (bgFullscreen) {applyFullscreenBackground();}});}function applyAdBlock() {const existing = document.getElementById(STYLE_IDS.adBlock);if (!adBlock) {if (existing) existing.remove();return;}if (existing) return;const style = document.createElement('style');style.id = STYLE_IDS.adBlock;style.textContent = `.side div[data-v-ce0b4304] { display: none !important; }`;document.head.appendChild(style);}function applyCustomCSS() {removeStyleElement(STYLE_IDS.customCSS);if (!customCSS || customCSS.trim() === '') return;const style = document.createElement('style');style.id = STYLE_IDS.customCSS;style.textContent = customCSS;document.head.appendChild(style);}function applyIdeLayout() {removeStyleElement(STYLE_IDS.idePadding);const mainContainer = document.querySelector('.main-container.lside-nav');if (!mainContainer) return;const isIdePage = !!mainContainer.querySelector('.panel-layout.ide-container');const topBar = document.querySelector('.top-bar');const topH = topBar ? topBar.getBoundingClientRect().height : 48;let css = `.main-container.lside-nav {padding: 10px !important;box-sizing: border-box !important;background: transparent !important;}`;if (isIdePage) {css += `.main-container.lside-nav {height: calc(100vh - ${topH}px) !important;max-height: calc(100vh - ${topH}px) !important;display: flex !important;flex-direction: column !important;}.main-container.lside-nav > .panel-layout.ide-container {flex: 1 1 auto !important;height: 100% !important;min-height: 0 !important;min-width: 0 !important;width: 100% !important;margin: 0 !important;box-sizing: border-box !important;}.main-container.lside-nav .panel-layout,.main-container.lside-nav .panel {min-height: 0 !important;min-width: 0 !important;box-sizing: border-box !important;}.ide-textarea.lfe-code {scrollbar-width: none !important;-ms-overflow-style: none !important;box-sizing: border-box !important;max-width: 100% !important;}.ide-textarea.lfe-code::-webkit-scrollbar {display: none !important;width: 0 !important;height: 0 !important;}.ide-textarea.lfe-code::-webkit-scrollbar-corner {display: none !important;background: transparent !important;}`;}const style = document.createElement('style');style.id = STYLE_IDS.idePadding;style.textContent = css;document.head.appendChild(style);}function applyScrollbarStyle() {removeStyleElement(STYLE_IDS.scrollbar);const style = document.createElement('style');style.id = STYLE_IDS.scrollbar;style.textContent = `* { scrollbar-color: rgb(139, 139, 139) transparent; }nav.sidebar::-webkit-scrollbar,.dropdown::-webkit-scrollbar { width: 8px; }nav.sidebar::-webkit-scrollbar-thumb,.dropdown::-webkit-scrollbar-thumb {background: rgb(139, 139, 139);border-radius: 4px;}`;document.head.appendChild(style);}function buildPanelHTML() {return `<div id="ldb-panel" class="l-card hidden"><button id="ldb-panel-close" aria-label="关闭">×</button><h2>插件设置</h2><h3>卡片模糊度</h3><p><input id="ldb-panel-blur" type="range" min="0" max="30" value="${blurValue}" /><span id="blur-value">${blurValue}px</span></p><h3>卡片不透明度</h3><p><input id="ldb-panel-opacity" type="range" min="0" max="100" value="${opacityValue}" /><span id="opacity-value">${opacityValue}%</span></p><h3>卡片圆角曲度</h3><p><input id="ldb-panel-rounded-card" type="range" min="0" max="30" value="${cardborderRad}" /><span id="rounded-value-card">${cardborderRad}px</span></p><h3>图片圆角曲度</h3><p><input id="ldb-panel-rounded-pic" type="range" min="0" max="16" value="${picborderRad}" /><span id="rounded-value-pic">${picborderRad}px</span></p><p><input id="ldb-panel-card-rounded" type="checkbox" ${cardRounded ? 'checked' : ''} /><label for="ldb-panel-card-rounded">卡片圆角</label></p><p><input id="ldb-panel-pic-rounded" type="checkbox" ${picRounded ? 'checked' : ''} /><label for="ldb-panel-pic-rounded">图片圆角</label></p><p><input id="ldb-panel-bgfullscreen" type="checkbox" ${bgFullscreen ? 'checked' : ''} /><label for="ldb-panel-bgfullscreen">背景全屏(在 <a href="/theme" target="_blank">主题</a> 内启用中景图片进行设置)</label></p><p><input id="ldb-panel-adblock" type="checkbox" ${adBlock ? 'checked' : ''} /><label for="ldb-panel-adblock">关闭广告</label></p><h3>自定义 CSS</h3><textarea id="ldb-panel-customCSS" spellcheck="false" autocomplete="off" autocapitalize="off"></textarea><h3>更新通道</h3><p><select id="ldb-panel-updateChannel"><option value="stable" ${updateChannel === 'stable' ? 'selected' : ''}>稳定版</option><option value="latest" ${updateChannel === 'latest' ? 'selected' : ''}>最新版</option></select></p><p><button id="ldb-panel-checkUpdate">检查更新</button><button id="ldb-panel-reset">还原设置</button></p><p id="ldb-updateStatus"></p></div>`;}function injectPanelStyle() {const style = document.createElement('style');style.textContent = `#ldb-panel {position: fixed !important;right: 35px !important;top: 50% !important;transform: translateY(-50%) !important;padding: 28px 24px 24px !important;background: rgba(255, 255, 255, ${opacityValue / 100}) !important;backdrop-filter: blur(${blurValue}px) !important;-webkit-backdrop-filter: blur(${blurValue}px) !important;border-radius: 24px !important;box-shadow: 0 12px 40px rgba(0,0,0,0.15) !important;color: #1e1e2f !important;transition: opacity .3s ease, visibility .3s ease, transform .3s ease !important;z-index: 2147483000 !important;box-sizing: border-box !important;width: min(400px, 50vw) !important;max-width: calc(100vw - 70px) !important;max-height: calc(100vh - 40px) !important;overflow-y: auto !important;font-family: -apple-system, BlinkMacSystemFont, "Segoe UI","PingFang SC", "Microsoft YaHei", sans-serif !important;font-size: 14px !important;line-height: 1.4 !important;text-align: left !important;}#ldb-panel.hidden {opacity: 0 !important;visibility: hidden !important;transform: translateY(-50%) scale(0.96) !important;pointer-events: none !important;}#ldb-panel-close {position: absolute !important;top: 12px !important;right: 12px !important;width: 32px !important;height: 32px !important;padding: 1px 0 0 0 !important;margin: 0 !important;border: none !important;border-radius: 50% !important;background: #ff4d4f !important;box-shadow: 0 2px 8px rgba(0,0,0,0.12) !important;color: #fff !important;font-family: Arial, Helvetica, sans-serif !important;font-size: 22px !important;font-weight: 400 !important;line-height: 1 !important;text-align: center !important;box-sizing: border-box !important;display: inline-flex !important;align-items: center !important;justify-content: center !important;overflow: hidden !important;cursor: pointer !important;transition: background .2s, transform .2s !important;}#ldb-panel-close:hover { background: #e04345 !important; transform: scale(1.06) !important; }#ldb-panel-close:active { transform: scale(0.92) !important; }#ldb-panel h2 { margin: 0 0 16px 0 !important; font-size: 22px !important;font-weight: 600 !important; color: #2c3e50 !important; line-height: 1.3 !important; }#ldb-panel h3 { margin: 18px 0 6px 0 !important; font-size: 15px !important;font-weight: 500 !important; color: #34495e !important; line-height: 1.3 !important; }#ldb-panel p {margin: 6px 0 12px 0 !important;padding: 0 !important;display: flex !important;align-items: center !important;gap: 10px !important;font-size: 14px !important;line-height: 1.4 !important;}#ldb-panel p > input[type="checkbox"] {flex: 0 0 auto !important;width: 18px !important;height: 18px !important;margin: 0 !important;padding: 0 !important;accent-color: #000 !important;cursor: pointer !important;vertical-align: middle !important;}#ldb-panel p > label {display: inline-block !important;margin: 0 !important;padding: 0 !important;cursor: pointer !important;user-select: none !important;font-size: 14px !important;font-weight: 400 !important;line-height: 1 !important;color: #1e1e2f !important;vertical-align: middle !important;}#ldb-panel input[type="range"] {flex: 1 !important;accent-color: #000 !important;height: 4px !important;border-radius: 2px !important;background: #dce3e8 !important;cursor: pointer !important;margin: 0 !important;padding: 0 !important;}#ldb-panel input[type="range"]::-webkit-slider-thumb {-webkit-appearance: none !important;width: 16px !important;height: 16px !important;border-radius: 50% !important;background: #000 !important;box-shadow: 0 1px 4px rgba(0,0,0,0.2) !important;cursor: pointer !important;}#ldb-panel-customCSS {display: block !important;width: 100% !important;height: clamp(100px, calc(100vh - 700px), 160px) !important;margin: 0 !important;padding: 8px 10px !important;border: 1px solid #ccc !important;border-radius: 4px !important;box-sizing: border-box !important;background: transparent !important;color: #1e1e2f !important;font-family: var(--lfe-code-font, Monospace) !important;font-size: 13px !important;line-height: 1.5 !important;resize: none !important;-webkit-appearance: none !important;overflow: auto !important;outline: none !important;tab-size: 2 !important;-moz-tab-size: 2 !important;white-space: pre !important;transition: border-color .2s, box-shadow .2s !important;}#ldb-panel-customCSS::placeholder { color: #9aa4ad !important; }#ldb-panel-customCSS:focus {border-color: #000 !important;box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.08) !important;}#ldb-panel-updateChannel {flex: 1 !important;height: 32px !important;padding: 0 10px !important;font-size: 14px !important;font-family: inherit !important;color: #1e1e2f !important;background: rgba(255, 255, 255, 0.9) !important;border: 1px solid #ccc !important;border-radius: 8px !important;box-sizing: border-box !important;cursor: pointer !important;outline: none !important;transition: border-color .2s, box-shadow .2s !important;}#ldb-panel-updateChannel:hover { border-color: #999 !important; }#ldb-panel-updateChannel:focus {border-color: #000 !important;box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.08) !important;}#ldb-panel-checkUpdate {display: inline-block !important;margin: 0 !important;padding: 8px 24px !important;background: #000 !important;border: none !important;border-radius: 30px !important;font-size: 14px !important;font-weight: 500 !important;color: #fff !important;cursor: pointer !important;box-shadow: 0 1px 4px rgba(0,0,0,0.15) !important;line-height: 1.4 !important;box-sizing: border-box !important;transition: background .2s, transform .1s !important;}#ldb-panel-checkUpdate:hover { background: #333 !important; }#ldb-panel-checkUpdate:active { transform: scale(0.96) !important; }#ldb-panel-reset {display: inline-block !important;margin: 0 !important;padding: 8px 24px !important;background: #ecf0f1 !important;border: none !important;border-radius: 30px !important;font-size: 14px !important;font-weight: 500 !important;color: #2c3e50 !important;cursor: pointer !important;box-shadow: 0 1px 4px rgba(0,0,0,0.05) !important;line-height: 1.4 !important;box-sizing: border-box !important;transition: background .2s, transform .1s !important;}#ldb-panel-reset:hover { background: #d5dbe0 !important; }#ldb-panel-reset:active { transform: scale(0.96) !important; }#ldb-panel #ldb-updateStatus {display: block !important;margin: 4px 0 0 0 !important;padding: 0 !important;font-size: 12px !important;line-height: 1.4 !important;color: #e53935 !important;text-align: left !important;word-break: break-all !important;}#ldb-panel #ldb-updateStatus:empty { display: none !important; margin: 0 !important; }#blur-value, #opacity-value, #rounded-value-card, #rounded-value-pic {display: inline-block !important;width: 45px !important;text-align: center !important;font-weight: 500 !important;line-height: 1 !important;}#ldb-panel a { color: #0d3d41 !important; text-decoration: none !important; }#ldb-panel a:hover { text-decoration: underline !important; }@media (max-width: 900px) {#ldb-panel { width: 50vw !important; right: 12px !important; }}@media (max-width: 400px) {#ldb-panel { width: calc(100vw - 20px) !important; right: 10px !important;padding: 20px 16px !important; }}`;document.head.appendChild(style);}function applyEditorFont() {if (!customCssTextarea) return;let fontFamily = '';try {fontFamily = getComputedStyle(document.body).getPropertyValue('--lfe-code-font').trim();} catch (e) {}customCssTextarea.style.setProperty('font-family', fontFamily || 'Monospace', 'important');}function bindPanelEvents() {const $ = id => document.getElementById(id);const cardroundedSlider = $('ldb-panel-rounded-card');const cardroundedDisplay = $('rounded-value-card');const picroundedSlider = $('ldb-panel-rounded-pic');const picroundedDisplay = $('rounded-value-pic');const closeBtn = $('ldb-panel-close');const blurSlider = $('ldb-panel-blur');const blurDisplay = $('blur-value');const opacitySlider = $('ldb-panel-opacity');const opacityDisplay = $('opacity-value');const cardRoundedCb = $('ldb-panel-card-rounded');const picRoundedCb = $('ldb-panel-pic-rounded');const bgFullscreenCb = $('ldb-panel-bgfullscreen');const adBlockCb = $('ldb-panel-adblock');const updateChannelSel = $('ldb-panel-updateChannel');const checkUpdateBtn = $('ldb-panel-checkUpdate');const updateStatus = $('ldb-updateStatus');const resetBtn = $('ldb-panel-reset');customCssTextarea = $('ldb-panel-customCSS');applyEditorFont();if (customCssTextarea) {customCssTextarea.value = customCSS || '';customCssTextarea.addEventListener('input', function() {if (customCssSaveTimer) clearTimeout(customCssSaveTimer);customCssSaveTimer = setTimeout(function() {customCssSaveTimer = null;if (!customCssTextarea) return;customCSS = customCssTextarea.value;saveAndApply("LuoguDisplayBetter-customCSS", customCSS);}, 300);});}closeBtn.addEventListener('click', () => panelElement.classList.add('hidden'));blurSlider.addEventListener('input', function() {blurDisplay.textContent = this.value + 'px';saveAndApply("LuoguDisplayBetter-blur", this.value);});opacitySlider.addEventListener('input', function() {opacityDisplay.textContent = this.value + '%';saveAndApply("LuoguDisplayBetter-opacity", this.value);});cardroundedSlider.addEventListener('input', function() {cardroundedDisplay.textContent = this.value + 'px';saveAndApply("LuoguDisplayBetter-cardborderRad", this.value);});picroundedSlider.addEventListener('input', function() {picroundedDisplay.textContent = this.value + 'px';saveAndApply("LuoguDisplayBetter-picborderRad", this.value);});cardRoundedCb.addEventListener('change', function() {saveAndApply("LuoguDisplayBetter-cardRounded", this.checked);});picRoundedCb.addEventListener('change', function() {saveAndApply("LuoguDisplayBetter-picRounded", this.checked);});bgFullscreenCb.addEventListener('change', function() {saveAndApply("LuoguDisplayBetter-bgFullscreen", this.checked);});adBlockCb.addEventListener('change', function() {saveAndApply("LuoguDisplayBetter-adBlock", this.checked);});updateChannelSel.addEventListener('change', function() {if (updateStatus._ldbTimer) {clearTimeout(updateStatus._ldbTimer);updateStatus._ldbTimer = null;}saveAndApply("LuoguDisplayBetter-updateChannel", this.value);updateStatus.textContent = '';});checkUpdateBtn.addEventListener('click', function() {checkForUpdate(updateStatus);});resetBtn.addEventListener('click', function() {if (updateStatus._ldbTimer) {clearTimeout(updateStatus._ldbTimer);updateStatus._ldbTimer = null;}writeDefaultSettings();loadSettings();blurSlider.value = blurValue;cardroundedSlider.value = cardborderRad;picroundedSlider.value = picborderRad;blurDisplay.textContent = blurValue + 'px';opacitySlider.value = 75;opacityDisplay.textContent = '75%';cardroundedDisplay.textContent = '15px';picroundedDisplay.textContent = '8px';cardRoundedCb.checked = true;picRoundedCb.checked = true;bgFullscreenCb.checked = true;adBlockCb.checked = false;if (customCssSaveTimer) {clearTimeout(customCssSaveTimer);customCssSaveTimer = null;}if (customCssTextarea) customCssTextarea.value = '';customCSS = '';updateChannelSel.value = 'stable';updateStatus.textContent = '';applyAll();});document.addEventListener('keydown', function(e) {if (e.key === 'Escape' && !panelElement.classList.contains('hidden')) {panelElement.classList.add('hidden');}});}function createSettingsPanel() {if (panelCreated) return;panelCreated = true;const container = document.createElement('div');container.innerHTML = buildPanelHTML();panelElement = container.firstElementChild;document.body.appendChild(panelElement);injectPanelStyle();bindPanelEvents();}function updatePanelStyle() {if (!panelElement) return;const bv = blurValue != null ? blurValue : 0;const ov = opacityValue != null ? opacityValue : 100;panelElement.style.backdropFilter = `blur(${bv}px)`;panelElement.style.webkitBackdropFilter = `blur(${bv}px)`;panelElement.style.background = `rgba(255, 255, 255, ${ov / 100})`;panelElement.style.color = '#1e1e2f';}function toggleSettingsPanel() {if (!panelElement) createSettingsPanel();if (!panelElement) return;panelElement.classList.toggle('hidden');}function ensurePanelInDom() {if (!panelElement) return;if (!document.body.contains(panelElement)) {document.body.appendChild(panelElement);}}function addSettingsNavButton() {if (document.querySelector('.sidebar.lside.bar.hide.nav-scrollbar')) {if (document.getElementById('stylePluginSettingButton')) return;const ul = document.querySelector('.nav-group.on-expand ul[data-v-a119941e]');if (!ul) return;const sampleLi = ul.querySelector('li');if (!sampleLi) return;const newLi = document.createElement('li');copyDataAttributes(sampleLi, newLi);newLi.setAttribute('title', '美化插件设置');const newA = document.createElement('a');const sampleA = sampleLi.querySelector('a');if (sampleA) {copyDataAttributes(sampleA, newA);newA.className = sampleA.className;newA.setAttribute('disabled', sampleA.getAttribute('disabled') || 'false');}newA.href = 'javascript:void(0);';newA.id = 'stylePluginSettingButton';const span = document.createElement('span');const sampleSpan = sampleLi.querySelector('span.title');if (sampleSpan) {copyDataAttributes(sampleSpan, span);span.className = sampleSpan.className;}span.textContent = '美化插件设置';newA.appendChild(document.createComment(''));newA.appendChild(span);newLi.appendChild(newA);newA.addEventListener('click', e => { e.preventDefault(); toggleSettingsPanel(); });ul.appendChild(newLi);return;}const appsContainer = document.querySelector('.apps');if (!appsContainer) return;if (appsContainer.querySelector('#stylePluginSettingButton')) return;const sample = appsContainer.querySelector('a');if (!sample) return;const newLink = document.createElement('a');copyDataAttributes(sample, newLink);newLink.setAttribute('colorscheme', sample.getAttribute('colorscheme') || 'none');newLink.className = sample.className;newLink.href = 'javascript:void(0);';newLink.innerText = '美化插件设置';newLink.id = 'stylePluginSettingButton';newLink.addEventListener('click', e => { e.preventDefault(); toggleSettingsPanel(); });appsContainer.appendChild(newLink);}function purgeJsdelivr(rawUrl, callback) {if (!rawUrl.includes('jsdelivr.net')) {callback();return;}const purgeUrl = rawUrl.replace('cdn.jsdelivr.net', 'purge.jsdelivr.net').replace('fastly.jsdelivr.net', 'purge.jsdelivr.net').replace('gcore.jsdelivr.net', 'purge.jsdelivr.net').replace('testingcf.jsdelivr.net', 'purge.jsdelivr.net');if (purgeUrl === rawUrl) {callback();return;}let called = false;const done = () => {if (called) return;called = true;callback();};GM_xmlhttpRequest({method: 'GET',url: purgeUrl,timeout: 5000,onload: done,onerror: done,ontimeout: done});}function checkForUpdate(statusEl) {if (statusEl._ldbTimer) {clearTimeout(statusEl._ldbTimer);statusEl._ldbTimer = null;}const urls = UPDATE_URLS[updateChannel];if (!urls || !urls.length) {statusEl.textContent = '未知通道';return;}const localVersion = GM_info.script.version;let index = 0;function fetchUrl(rawUrl) {const sep = rawUrl.includes('?') ? '&' : '?';const url = `${rawUrl}${sep}t=${Date.now()}`;statusEl.textContent = `检查中... (${index}/${urls.length})`;GM_xmlhttpRequest({method: 'GET',url: url,headers: { 'Cache-Control': 'no-cache' },timeout: 10000,onload(response) {if (response.status !== 200) {tryNext();return;}const match = response.responseText.match(/\/\/\s*@version\s+([\d.]+)/);if (!match) {tryNext();return;}const remoteVersion = match[1];if (compareVersions(remoteVersion, localVersion) > 0) {statusEl.innerHTML = '发现新版本 v' + remoteVersion + ',' +'<a href="' + rawUrl + '" target="_blank" style="color:#0d6efd;text-decoration:underline;cursor:pointer;">点击安装</a>';} else {statusEl.textContent = '已是最新版本 v' + localVersion;statusEl._ldbTimer = setTimeout(() => {statusEl.textContent = '';statusEl._ldbTimer = null;}, 2000);}},onerror: tryNext,ontimeout: tryNext});}function tryNext() {if (index >= urls.length) {statusEl.textContent = '网络请求失败';return;}const rawUrl = urls[index++];if (rawUrl.includes('jsdelivr.net')) {statusEl.textContent = `刷新缓存中... (${index}/${urls.length})`;purgeJsdelivr(rawUrl, () => fetchUrl(rawUrl));} else {fetchUrl(rawUrl);}}tryNext();}function applyAll() {applyRoundedCorners();applyCardBlur();applyCardOpacity();applyFullscreenBackground();applyFullscreenEditorLayout();applyAdBlock();applyCustomCSS();applyIdeLayout();applyScrollbarStyle();cleanThemeBackground();updatePanelStyle();}function pollDomState() {addSettingsNavButton();ensurePanelInDom();if (relocateEditorToBody()) {scheduleEditorLayoutUpdate();}applyAdBlock();refreshThemeBackground();}function startDomPolling() {if (domPollTimer) return;pollDomState();domPollTimer = setInterval(pollDomState, DOM_POLL_INTERVAL);}function startThemeBackgroundObserver() {if (bgObserver) return;bgObserver = new MutationObserver((mutations) => {for (const m of mutations) {for (const node of m.addedNodes) {if (node.nodeType !== 1) continue;if (node.matches?.('.theme-page, #luogu-theme') ||node.querySelector?.('.theme-page, #luogu-theme')) {refreshThemeBackground(true);return;}}if (m.type === 'characterData' || m.type === 'childList') {const t = m.target;if (t.id === 'luogu-theme' ||t.parentElement?.id === 'luogu-theme') {refreshThemeBackground(true);return;}}}});bgObserver.observe(document.documentElement, {childList: true,subtree: true,characterData: true});}function startResizeObserver() {if (window.ResizeObserver) {const ro = new ResizeObserver(() => {if (document.querySelector('.casket.cs-full-screen')) {scheduleEditorLayoutUpdate();}});ro.observe(document.documentElement);}window.addEventListener('resize', () => {if (document.querySelector('.casket.cs-full-screen')) {scheduleEditorLayoutUpdate();}});}function init() {const firstUsed = localStorage.getItem("LuoguDisplayBetter-FirstUsed") == null;if (firstUsed) {localStorage.setItem("LuoguDisplayBetter-FirstUsed", false);writeDefaultSettings();}loadSettings();startThemeBackgroundObserver();addSettingsNavButton();applyAll();setTimeout(() => {createSettingsPanel();ensurePanelInDom();if (firstUsed && panelElement && panelElement.classList.contains('hidden')) toggleSettingsPanel();}, SETTINGS_PANEL_DELAY);startDomPolling();startResizeObserver();}if (document.readyState === 'loading') {document.addEventListener('DOMContentLoaded', init);} else {init();}})();1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555```java// ==UserScript==// @name JXYCOI Display Better// @namespace https://github.com/zhanjinghan// @version 1.2.0// @description 育才信奥界面美化脚本// @author zhanjinghan// @icon https://cdn.jxycoi.cn/dist/favicon.ico// @match https://www.jxycoi.cn/*// @match http://www.jxycoi.cn/*// @match https://jxycoi.cn/*// @match http://jxycoi.cn/*// @match https://www.ycgeek.top/oj/*// @match http://www.ycgeek.top/oj/*// @grant GM_addStyle// @grant GM_getValue// @grant GM_setValue// @run-at document-start// @noframes// @license MIT// ==/UserScript==(function () {'use strict';/* ============================================================* 默认配置* ============================================================ */const DEFAULT_CONFIG = {enabled: true, // 总开关themeName: '洛谷经典蓝', // 当前主题名// ---- 洛谷主题原始数据(导入时完整保留,可加字段不可少字段)----luoguTheme: null, // 原始洛谷主题 JSON(lNavi/lBody/dNavi/dBody...)luoguExtra: {}, // 扩展字段(name/author/css 等)// ---- 颜色 ----dark: false, // 暗色模式primary: '#3498db', // 主色primaryHover: '#2980b9', // 主色 hoverbgColor: '#f0f2f5', // 页面背景色naviBack: '#ffffff', // 导航背景naviFore: '#333333', // 导航前景navbarColor: '#ffffff', // 导航背景(旧格式兼容别名)textColor: '#1f2733', // 正文颜色secondaryColor: '#6b7280', // 次要文字颜色cardColor: '#ffffff', // 卡片底色// ---- 背景图片设置(以洛谷 midOpts 为标准)----bgImage: '', // 背景图片 URL(留空则纯色)bgPosX: 50, // 图片位置 X(0-100 %)bgPosY: 0, // 图片位置 Y(0-100 %)bgSize: 'cover', // 图片尺寸:auto 自动 / cover 填充 / contain 适应 / custom 自定义bgSizeCustom: '', // 自定义尺寸,如 "100% 100%" 或 "800px 600px"bgRepeat: 'no-repeat', // 图片重复:no-repeat 不重复 / repeat 全部 / repeat-x 横向 / repeat-y 纵向bgBrightness: 0, // 亮度(-100 ~ 100)bgDegree: 0, // 旋转角度(0 ~ 360)bgFade: 0, // 洛谷 fade 语义:0 无 / 1 顶部 400px 渐隐 / -1 底部 400px 渐隐// ---- 效果 ----blur: 12, // 背景模糊度 px (0-40)opacity: 0.86, // 卡片透明度 0-1(0=完全透明,1=不透明)radius: 10, // 卡片圆角 pxshadow: true, // 卡片阴影// ---- 功能开关 ----hideHomeImages: false, // 去除首页图片(轮播/公告大图)cardMode: true, // 卡片化(做题页面自动豁免)customCSS: '' // 用户自定义 CSS};/* ============================================================* 预设主题库(洛谷风格)* ============================================================ */const PRESET_THEMES = {'洛谷经典蓝': {primary: '#3498db', primaryHover: '#2980b9',bgColor: '#f0f2f5', bgImage: '', blur: 12, opacity: 0.86,radius: 10, textColor: '#1f2733', secondaryColor: '#6b7280',cardColor: '#ffffff', naviBack: '#ffffff', naviFore: '#333333',navbarColor: '#ffffff', dark: false, shadow: true,bgSize: 'cover', bgRepeat: 'no-repeat', bgPosX: 50, bgPosY: 0},'洛谷翠绿': {primary: '#27ae60', primaryHover: '#1e8449',bgColor: '#f0f4f2', bgImage: '', blur: 14, opacity: 0.87,radius: 12, textColor: '#1f2733', secondaryColor: '#5f7a6e',cardColor: '#ffffff', naviBack: '#ffffff', naviFore: '#2c3e2f',navbarColor: '#ffffff', dark: false, shadow: true,bgSize: 'cover', bgRepeat: 'no-repeat', bgPosX: 50, bgPosY: 0},'洛谷暮紫': {primary: '#8e44ad', primaryHover: '#732d91',bgColor: '#f3eff6', bgImage: '', blur: 16, opacity: 0.85,radius: 14, textColor: '#2c2433', secondaryColor: '#7a6b8a',cardColor: '#ffffff', naviBack: '#ffffff', naviFore: '#3a2f40',navbarColor: '#ffffff', dark: false, shadow: true,bgSize: 'cover', bgRepeat: 'no-repeat', bgPosX: 50, bgPosY: 0},'洛谷暗夜': {primary: '#61afef', primaryHover: '#4a9be0',bgColor: '#1a1f2b', bgImage: '', blur: 10, opacity: 0.92,radius: 10, textColor: '#d8dee9', secondaryColor: '#9aa5b8',cardColor: '#232a38', naviBack: '#1e2530', naviFore: '#d8dee9',navbarColor: '#1e2530', dark: true, shadow: false,bgSize: 'cover', bgRepeat: 'no-repeat', bgPosX: 50, bgPosY: 0},'毛玻璃亚克力': {primary: '#5b8def', primaryHover: '#4a76d6',bgColor: '#eef2fb', bgImage: '', blur: 22, opacity: 0.55,radius: 16, textColor: '#1f2733', secondaryColor: '#6b7280',cardColor: '#ffffff', naviBack: '#ffffff', naviFore: '#333333',navbarColor: '#ffffff', dark: false, shadow: false,bgSize: 'cover', bgRepeat: 'no-repeat', bgPosX: 50, bgPosY: 0}};/* ============================================================* 彩蛋主题(艾莲·乔)* ============================================================ */const EASTER_EGG_TRIGGERS = ['艾莲', '艾莲乔', '艾莲·乔', '默认'];const EASTER_EGG_THEME = {lNavi: { back: '#ffffff', fore: '#333333' },lBody: {midOpts: { size: 'contain', degree: 0, position: [50, 0], brightness: 0, repeat: 'no-repeat' },back: '#f0f2f5',blur: 0,image: 'https://cdn.luogu.com.cn/upload/image_hosting/h54trnl1.webp'},dNavi: { back: '#ffffff', fore: '#262626' },dBody: { back: '#ffffff', blur: 1000, fade: 1000 },name: '艾莲·乔',__meta: {schema: 'jxycoi-display-better',schemaVersion: 1,appVersion: '1.2.0',exportedAt: '2026-10-19T05:12:04.169Z',name: '艾莲·乔',author: 'zhanjinghan',source: 'luogu-import'},__config: {enabled: true,themeName: '艾莲·乔',luoguTheme: {lNavi: { back: '#ffffff', fore: '#333333' },lBody: { midOpts: { size: 'contain', degree: 0, notEmpty: true, position: [50, 0], brightness: 0 }, back: '#f0f2f5', blur: 1000, image: 'https://cdn.luogu.com.cn/upload/image_hosting/h54trnl1.webp' },dNavi: { back: '#ffffff', fore: '#262626' },dBody: { back: '#ffffff', blur: 1000, fade: 1000 },name: '艾莲·乔'},luoguExtra: { name: '艾莲·乔' },dark: false,primary: '#3498db',primaryHover: '#2980b9',bgColor: '#f0f2f5',naviBack: '#ffffff',naviFore: '#333333',navbarColor: '#ffffff',textColor: '#1f2733',secondaryColor: '#6b7280',cardColor: '#ffffff',bgImage: 'https://cdn.luogu.com.cn/upload/image_hosting/h54trnl1.webp',bgPosX: 50,bgPosY: 0,bgSize: 'contain',bgSizeCustom: '',bgRepeat: 'no-repeat',bgBrightness: 0,bgDegree: 0,bgFade: 0,blur: 0,opacity: 0,radius: 10,shadow: true,hideHomeImages: false,cardMode: true,customCSS: `/* ===== 1. 默认给所有文字加白色描边 ===== */html body * {text-shadow:0.5px 0.5px 0 #fff,-0.5px 0.5px 0 #fff,0.5px -0.5px 0 #fff,-0.5px -0.5px 0 #fff,0 0 4px rgba(255, 255, 255, 0.9) !important;}/* ===== 2. 排除所有本身就是白色文字的区域 ===== *//* 代码块、表单控件 */html body pre,html body pre *,html body code,html body code *,html body kbd,html body kbd *,html body samp,html body samp *,html body button,html body button *,html body input,html body input *,html body textarea,html body textarea *,html body select,html body select *,/* Element UI 标签(难度「简单/中等/困难」等,彩底白字) */html body .el-tag,html body .el-tag *,html body [class*="el-tag--"],html body [class*="el-tag--"] *,/* 下拉导航(你网站里 .subNav 内是白字) */html body .subNav,html body .subNav *,html body .subNav a,/* 顶栏 / 导航 / 页脚 —— 通常是深色背景白字 */html body .navbar,html body .navbar *,html body .top-navbar,html body .top-navbar *,html body header,html body header *,html body nav,html body nav *,html body .footer,html body .footer *,/* 按钮、标签、徽章、主色元素 */html body .btn,html body .btn *,html body .tag,html body .tag *,html body .badge,html body .badge *,html body .label,html body .label *,html body [class*="primary"],html body [class*="primary"] *,html body [class*="button"],html body [class*="button"] *,/* 难度标签(洛谷风格:彩色底 + 白字) */html body .difficulty,html body .difficulty *,html body .problem-difficulty,html body .problem-difficulty *,html body [class*="difficulty"],html body [class*="difficulty"] *,html body [class*="Difficulty"],html body [class*="Difficulty"] *,html body .lg-fg-red,html body .lg-fg-orange,html body .lg-fg-yellow,html body .lg-fg-green,html body .lg-fg-blue,html body .lg-fg-purple,html body .lg-fg-black,html body .lg-fg-gray,html body [class*="lg-fg-"],html body [class*="lg-fg-"] *,/* 状态标签(AC/WA/TLE 等) */html body .status,html body .status *,html body [class*="status"],html body [class*="status"] *,html body .result,html body .result *,html body [class*="result"],html body [class*="result"] *,html body .verdict,html body .verdict *,/* 弹窗、下拉菜单、提示框 */html body .modal,html body .modal *,html body .dropdown,html body .dropdown *,html body .menu,html body .menu *,html body .toast,html body .toast *,html body .alert,html body .alert *,html body .notification,html body .notification *,/* 分页、选项卡 */html body .pagination,html body .pagination *,html body .tab,html body .tab *,/* 暗色/黑色背景容器 */html body [class*="dark"],html body [class*="dark"] *,html body [class*="black"],html body [class*="black"] *,html body [class*="white-text"],html body [class*="white-text"] * {text-shadow: none !important;}/* ===== 3. 选中文字时不要白边 ===== */html body *::selection {text-shadow: none !important;}html body *::-moz-selection {text-shadow: none !important;}`},};/* ============================================================* 存储封装(优先 GM,回退 localStorage)* ============================================================ */const STORE_KEY = 'jxycoi_display_better_config';function loadConfig() {let raw = null;try { raw = GM_getValue(STORE_KEY, null); } catch (e) { /* ignore */ }if (raw == null) {try { raw = localStorage.getItem(STORE_KEY); } catch (e) { /* ignore */ }}if (!raw) return Object.assign({}, DEFAULT_CONFIG);try {const parsed = JSON.parse(raw);return Object.assign({}, DEFAULT_CONFIG, parsed);} catch (e) {return Object.assign({}, DEFAULT_CONFIG);}}function saveConfig(cfg) {const raw = JSON.stringify(cfg);try { GM_setValue(STORE_KEY, raw); } catch (e) { /* ignore */ }try { localStorage.setItem(STORE_KEY, raw); } catch (e) { /* ignore */ }}let config = loadConfig();/* ============================================================* 颜色工具* ============================================================ */function hexToRgb(hex) {let h = String(hex || '').trim().replace(/^#/, '');if (h.length === 3) h = h.split('').map(c => c + c).join('');if (h.length !== 6) return { r: 255, g: 255, b: 255 };const n = parseInt(h, 16);return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255 };}function rgba(hex, alpha) {const c = hexToRgb(hex);return `rgba(${c.r}, ${c.g}, ${c.b}, ${alpha})`;}function darken(hex, amt) {const c = hexToRgb(hex);const f = v => Math.max(0, Math.round(v * (1 - amt)));return `rgb(${f(c.r)}, ${f(c.g)}, ${f(c.b)})`;}function clampNum(v, min, max, def) {const n = Number(v);if (Number.isNaN(n)) return def;return Math.min(max, Math.max(min, n));}/* ============================================================* 样式生成* ============================================================ */// 卡片化选择器:本站真实内容容器(Element el-card / el-tabs + 通用精确类)。// 刻意删除 [class*="card"]/[class*="nav"]/[class*="main"]/[class*="content"]/main > div 等// 子串通杀——它们会误伤 avatar、vxe、el-* 内部类,是头像放大/顶栏不透明/列表行不透明的元凶。const CARD_SELECTORS = ['.card-container', '.card', '.panel', '.module-card','.el-card', '.box-card', '.el-tabs--border-card','.problem-left', '.problem-right'].join(',\n');// 站点识别:ycgeek.top/oj(Hydro OJ)与 jxycoi.cn(HUST 衍生)结构完全不同const IS_GEEK = /ycgeek\.top/.test(location.hostname);// 做题页面(纯白,不做卡片化)——按 URL / data-page 判断function isSolvingPage() {const p = location.pathname;if (IS_GEEK) {// Hydro OJ:优先用 <html data-page>(SSR 稳定写入),URL 正则兜底const dp = (document.documentElement && document.documentElement.getAttribute('data-page')) || '';if (dp === 'problem_detail' || dp === 'contest_problempage' || dp === 'problem_statistics') return true;const path = p.replace(/^\/oj/, '');return /^\/p\/[^/]+$/.test(path) || // /p/1 /p/C0001/^\/contest\/[^/]+\/p\/[^/]+$/.test(path) || // 比赛题/^\/p\/[^/]+\/stat$/.test(path); // 题目统计}return /\/problem\//.test(p) || /\/p\/\d+/.test(p) || /\/contest\/.*\/problem/.test(p) || /\/exam\//.test(p);}/* ============================================================* Hydro OJ(ycgeek.top/oj,cctools)专属样式生成* 结构:页面主体 #panel、顶栏 .nav/.header--mobile、卡片 .section/.geek-*、* 表格 .data-table/.el-table、头像 .el-avatar(Element UI 头像)* ============================================================ */function buildGeekCSS(cfg) {const cardBg = rgba(cfg.cardColor, cfg.opacity);const textColor = cfg.textColor;const secColor = cfg.secondaryColor;const primary = cfg.primary;const primaryHover = cfg.primaryHover;const radius = cfg.radius + 'px';const blurPx = cfg.blur + 'px';const shadow = cfg.shadow? '0 1px 3px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.08)': 'none';// 图片设置(以洛谷 midOpts 为标准)const sizeMap = { auto: 'auto', cover: 'cover', contain: 'contain' };const size = sizeMap[cfg.bgSize] || (cfg.bgSizeCustom || 'cover');const repeatMap = { 'no-repeat': 'no-repeat', repeat: 'repeat', 'repeat-x': 'repeat-x', 'repeat-y': 'repeat-y' };const repeat = repeatMap[cfg.bgRepeat] || 'no-repeat';const pos = `${cfg.bgPosX || 50}% ${cfg.bgPosY || 0}%`;const brightness = cfg.bgBrightness ? ` brightness(${100 + cfg.bgBrightness}%)` : '';const rotate = cfg.bgDegree ? ` rotate(${cfg.bgDegree}deg)` : '';return `/* ===== JXYCOI Display Better (GeekOJ/Hydro) ===== */html {background: ${cfg.bgColor} !important;}body {background: transparent !important;color: ${textColor} !important;}body::before {content: '' !important;position: fixed !important;inset: 0 !important;z-index: -1 !important;background: url('${cfg.bgImage || ''}') ${repeat} ${pos} / ${size} !important;filter: blur(${cfg.blur > 0 ? blurPx : '0px'})${brightness} !important;transform: scale(1.06) ${rotate} !important;pointer-events: none !important;display: ${cfg.bgImage ? 'block' : 'none'} !important;}/* 洛谷 fade 语义:顶部/底部 400px 黑渐隐遮罩(压暗保证文字可读) */body::after {content: '' !important;position: fixed !important;inset: 0 !important;z-index: -1 !important;pointer-events: none !important;background: ${cfg.bgFade > 0? 'linear-gradient(to bottom, rgba(0,0,0,.6) 0, transparent 400px)': cfg.bgFade < 0? 'linear-gradient(to top, rgba(0,0,0,.6) 0, transparent 400px)': 'none'} !important;display: ${cfg.bgFade ? 'block' : 'none'} !important;}/* ============================================================* Hydro OJ(ycgeek.top/oj,cctools):CSS 变量驱动,改 --geek-* 一次解决全站* 关键:--geek-surface 是卡片/表格/弹窗共用的表面色;#panel 是整页包裹层* ============================================================ */:root {--geek-surface: ${cardBg};--geek-bg: transparent;--geek-line: ${rgba(cfg.cardColor, 0.14)};--geek-shadow: ${shadow};--geek-radius-card: ${radius};--geek-ink: ${textColor};--geek-muted: ${secColor};}/* 整页包裹层透明,让 body::before 背景图透出(原 #panel{background:#edf0f2}) */#panel, .main, .main > .row, .main > .row > .columns, html, body {background: transparent !important;}/* 顶栏:精确命中 nav.nav#menu(本体+列表+项),绝不用 header/nav 元素选择器(header 会命中所有 section__header;nav 会命中 .nav--shadow 占位条) */nav.nav#menu {background: ${cardBg} !important;backdrop-filter: blur(${blurPx}) saturate(140%) !important;-webkit-backdrop-filter: blur(${blurPx}) saturate(140%) !important;border-bottom: 1px solid ${rgba(cfg.cardColor, 0.15)} !important;box-shadow: none !important;color: ${textColor} !important;}nav.nav#menu .nav__list,nav.nav#menu .nav__list-item,nav.nav#menu .nav__brand,nav.nav#menu .nav__item {background: transparent !important;border-radius: 0 !important;box-shadow: none !important;}nav.nav#menu .nav__item, nav.nav#menu .nav__brand {color: ${cfg.dark ? textColor : primary} !important;}nav.nav#menu .nav__item:hover, nav.nav#menu .nav__item.nav--active {color: ${primaryHover} !important;background: ${rgba(cfg.primary, 0.10)} !important;}/* 占位条绝对不能上色 */nav.nav--shadow {background: transparent !important;box-shadow: none !important;}/* 移动端顶栏(≤759px)与侧滑抽屉(≤600px 深底) */.header--mobile {background: ${cardBg} !important;backdrop-filter: blur(${blurPx}) !important;-webkit-backdrop-filter: blur(${blurPx}) !important;box-shadow: none !important;}.nav.slideout-menu {background: ${rgba('#252a32', 0.92)} !important;backdrop-filter: blur(${blurPx}) !important;-webkit-backdrop-filter: blur(${blurPx}) !important;}.nav.slideout-menu .nav__item, .nav.slideout-menu .nav__brand { color: #fff !important; }.nav.slideout-menu .nav__item:hover, .nav.slideout-menu .nav__item.nav--active {background: rgba(255,255,255,.12) !important;color: #fff !important;}/* 下拉浮层(导航内 .dropdown-target.menu 是透明的,脱离导航的 .dropdown .menu 是白底) */.dropdown .menu, .dropdown-target.menu,.autocomplete-list, .omnibar-main, .omnibar-content-section {background: ${rgba(cfg.dark ? '#1f2430' : '#ffffff', Math.max(cfg.opacity, 0.96))} !important;backdrop-filter: blur(${blurPx}) !important;-webkit-backdrop-filter: blur(${blurPx}) !important;border-radius: ${radius} !important;box-shadow: 0 8px 32px rgba(0,0,0,.18) !important;}.dropdown .menu a, .dropdown .menu .menu__link, .dropdown-target.menu a,.autocomplete-list a, .autocomplete-list li,.omnibar-main a, .omnibar-content-section a {background: transparent !important;color: ${cfg.dark ? textColor : primary} !important;}.autocomplete-list li[data-focus=true], .omnibar-content-section:hover {background: ${rgba(cfg.primary, 0.10)} !important;}/* 卡片本体:背景已由 --geek-surface 变量控制,这里补毛玻璃与圆角 */.section {backdrop-filter: blur(${blurPx}) saturate(140%) !important;-webkit-backdrop-filter: blur(${blurPx}) saturate(140%) !important;border: 1px solid ${rgba(cfg.cardColor, 0.12)} !important;border-radius: ${radius} !important;box-shadow: ${shadow} !important;color: ${textColor} !important;}/* 卡片内层头部/主体/工具条/元信息全透明,内容落在同一块玻璃上 */.section__header, .section__body, .section__tools,.geek-problem-meta-row, .problem__tags, .problem__tag-item,.geek-panel-head, .geek-announcement__body, .geek-checkin__action,.geek-problem-toolbar, .geek-problem-workspace__head,.geek-class-card__marker, .section__list__item, .contest__item {background: transparent !important;}/* 表格:.data-table(原生 table)透明化;斑马纹/高亮改半透明保留可读性 */.data-table, .data-table thead, .data-table tbody,.data-table th, .data-table td {background: transparent !important;}.data-table tbody tr:nth-child(2n) { background: rgba(255,255,255,.04) !important; }.data-table tbody tr:hover { background: ${rgba(cfg.primary, 0.08)} !important; }.data-table tbody tr.highlight { background: rgba(255,248,220,.45) !important; }.section__table-header {background: ${rgba(cfg.cardColor, 0.55)} !important;backdrop-filter: blur(8px) !important;}.data-table th { color: ${secColor} !important; }/* 头像:本站无头像(纯文本用户名),仅兜底保护文本块不被卡片化误伤 */.user-profile-link, .user-profile-name,nav.nav#menu .nav__item.geek-user-menu-trigger {background: transparent !important;border: 0 !important;border-radius: 0 !important;padding: 0 !important;box-shadow: none !important;backdrop-filter: none !important;-webkit-backdrop-filter: none !important;}/* 代码块:highlight.js pre[class*=language-] 玻璃化,绝不碰 KaTeX 公式 */pre, pre[class*="language-"], :not(pre) > code {background: ${rgba(cfg.cardColor, 0.55)} !important;color: ${textColor} !important;border-radius: 6px !important;}pre { border: 1px solid ${rgba(cfg.cardColor, 0.15)} !important; }.katex, .katex * { background: transparent !important; }/* 输入框 */input, textarea, select {background: ${rgba(cfg.cardColor, 0.85)} !important;color: ${textColor} !important;border: 1px solid ${rgba(primary, 0.3)} !important;border-radius: 6px !important;}input:focus, textarea:focus, select:focus {border-color: ${primary} !important;outline: none !important;box-shadow: 0 0 0 3px ${rgba(primary, 0.15)} !important;}/* 按钮 */button, .btn, [class*="button"], [class*="Button"] {color: ${cfg.dark ? textColor : primary} !important;}button.primary, .btn-primary, [class*="primary"] {background: ${primary} !important;border-color: ${primary} !important;color: #fff !important;border-radius: 6px !important;}button.primary:hover, .btn-primary:hover, [class*="primary"]:hover {background: ${primaryHover} !important;border-color: ${primaryHover} !important;}/* 链接 */a {color: ${primary} !important;}a:hover {color: ${primaryHover} !important;}/* 登录弹窗 */.modal-login, .modal, [class*="modal"] {background: ${rgba(cfg.dark ? cfg.cardColor : '#ffffff', Math.max(cfg.opacity, 0.92))} !important;backdrop-filter: blur(${blurPx}) !important;-webkit-backdrop-filter: blur(${blurPx}) !important;border-radius: ${radius} !important;box-shadow: 0 8px 32px rgba(0,0,0,.18) !important;}/* 状态标签 */[class*="tag"], [class*="label"], [class*="badge"] {border-radius: 4px !important;}/* 滚动条 */::-webkit-scrollbar { width: 10px !important; height: 10px !important; }::-webkit-scrollbar-thumb {background: ${rgba(primary, 0.35)} !important;border-radius: 5px !important;}::-webkit-scrollbar-thumb:hover {background: ${rgba(primary, 0.55)} !important;}::-webkit-scrollbar-track { background: transparent !important; }/* 暗色补充 */${cfg.dark ? `.section, .geek-announcement, .geek-checkin, .geek-class-card,.geek-problem-card, .geek-statistics-card, .geek-statistics-table-card,.geek-generated-pretest-list {border-color: rgba(255,255,255,.08) !important;}.data-table th { background: rgba(255,255,255,.05) !important; }` : ''}/* 自定义 CSS */${cfg.customCSS || ''}`;}function buildCSS(cfg) {if (IS_GEEK) return buildGeekCSS(cfg);const cardBg = rgba(cfg.cardColor, cfg.opacity);const textColor = cfg.textColor;const secColor = cfg.secondaryColor;const primary = cfg.primary;const primaryHover = cfg.primaryHover;const radius = cfg.radius + 'px';const blurPx = cfg.blur + 'px';const shadow = cfg.shadow? '0 1px 3px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.08)': 'none';// 图片设置(以洛谷 midOpts 为标准)const sizeMap = { auto: 'auto', cover: 'cover', contain: 'contain' };const size = sizeMap[cfg.bgSize] || (cfg.bgSizeCustom || 'cover');const repeatMap = { 'no-repeat': 'no-repeat', repeat: 'repeat', 'repeat-x': 'repeat-x', 'repeat-y': 'repeat-y' };const repeat = repeatMap[cfg.bgRepeat] || 'no-repeat';const pos = `${cfg.bgPosX || 50}% ${cfg.bgPosY || 0}%`;const brightness = cfg.bgBrightness ? ` brightness(${100 + cfg.bgBrightness}%)` : '';const rotate = cfg.bgDegree ? ` rotate(${cfg.bgDegree}deg)` : '';return `/* ===== JXYCOI Display Better ===== */html {background: ${cfg.bgColor} !important;}body {background: transparent !important;color: ${textColor} !important;}body::before {content: '' !important;position: fixed !important;inset: 0 !important;z-index: -1 !important;background: url('${cfg.bgImage || ''}') ${repeat} ${pos} / ${size} !important;filter: blur(${cfg.blur > 0 ? blurPx : '0px'})${brightness} !important;transform: scale(1.06) ${rotate} !important;pointer-events: none !important;display: ${cfg.bgImage ? 'block' : 'none'} !important;}/* 洛谷 fade 语义:顶部/底部 400px 黑渐隐遮罩(压暗保证文字可读) */body::after {content: '' !important;position: fixed !important;inset: 0 !important;z-index: -1 !important;pointer-events: none !important;background: ${cfg.bgFade > 0? 'linear-gradient(to bottom, rgba(0,0,0,.6) 0, transparent 400px)': cfg.bgFade < 0? 'linear-gradient(to top, rgba(0,0,0,.6) 0, transparent 400px)': 'none'} !important;display: ${cfg.bgFade ? 'block' : 'none'} !important;}/* 顶栏(本站真实结构是 <div id="header">,内层 Element el-menu;也视为卡片) */#header,#header .el-menu,#header .el-menu--horizontal,.el-menu--popup,.el-menu--popup .el-menu {background: ${cardBg} !important;backdrop-filter: blur(${blurPx}) saturate(140%) !important;-webkit-backdrop-filter: blur(${blurPx}) saturate(140%) !important;box-shadow: none !important;color: ${textColor} !important;}#header {border-bottom: 1px solid ${rgba(cfg.cardColor, 0.15)} !important;border-radius: 0 0 ${radius} ${radius} !important;box-shadow: ${shadow} !important;}#header a, #header .el-menu-item, #header .el-submenu__title,.el-menu--popup a, .el-menu--popup .el-menu-item {color: ${cfg.dark ? textColor : primary} !important;background: transparent !important;}#header a:hover, #header .el-menu-item:hover, #header .el-submenu__title:hover,#header .el-menu--horizontal > .el-menu-item:hover,#header .el-menu--horizontal > .el-submenu .el-submenu__title:hover,.el-menu--popup .el-menu-item:hover {color: ${primaryHover} !important;background: rgba(64,158,255,.10) !important;}/* 顶栏内部导航项(首页/班级/训练/比赛等)透明,避免白底破坏卡片感 */#header ul, #header li, #header .logo, #header .logo .el-image,#header .drop-menu, #header .drop-score, #header .drop-msg {background: transparent !important;}/* ============================================================* vxe-table(题目/训练/比赛/提交记录/排名列表)* 白底画在 wrapper 层,行/单元格默认透明;因此先打掉 wrapper 白底,* 行/单元格保持透明,整表透出背景图(或外层 el-card 玻璃)* ============================================================ */.vxe-table {background: transparent !important;}.vxe-table--render-default .vxe-table--body-wrapper,.vxe-table--render-default .vxe-table--footer-wrapper,.vxe-table--render-default .vxe-table--header-wrapper,.vxe-table--fixed-left-wrapper,.vxe-table--fixed-right-wrapper,.vxe-table--fixed-left-wrapper .vxe-table--body-wrapper,.vxe-table--fixed-right-wrapper .vxe-table--body-wrapper {background: transparent !important;}.vxe-body--row,.vxe-body--column,.vxe-header--row,.vxe-header--column {background: transparent !important;}/* 保留斑马纹/悬停可读性:半透明,不破坏整体玻璃感 */.vxe-body--row.row--stripe { background: rgba(255,255,255,.04) !important; }.vxe-body--row.row--hover { background: rgba(255,255,255,.08) !important; }.vxe-table .notdone-row { background: rgba(64,158,255,.10) !important; }/* 卡片容器(本站真实内容卡片) */${CARD_SELECTORS} {background: ${cardBg} !important;backdrop-filter: blur(${blurPx}) !important;-webkit-backdrop-filter: blur(${blurPx}) !important;border-radius: ${radius} !important;border: 1px solid ${rgba(cfg.cardColor, 0.12)} !important;box-shadow: ${shadow} !important;color: ${textColor} !important;}/* el-card 内层 body/header 与题目页选项卡内容透明,让一整行小标签落在同一块玻璃上 */.el-card__body,.el-card__header,.el-tabs--border-card > .el-tabs__header,.el-tabs--border-card > .el-tabs__content,.el-tabs__content,.js-left {background: transparent !important;}/* 主内容列只透明,不加边框/圆角(避免整体套一层卡) */#main, .flex-container #main, main {background: transparent !important;}/* 元信息标签保持通透(展示ID/题目/类别/语言等同一行小块),语义彩签保留颜色 */.info-rows, .info-rows > div, .info-rows span,.problem-tag, .category-item, .judge-time, .problem-time {background: transparent !important;}/* ============================================================* 头像修复:<avatar> 自定义元素尺寸由内联 width/height 锁定,* 禁止被卡片化规则误伤(放大/变形根因:祖先被加 border/padding/backdrop-filter)* ============================================================ */avatar, .user-avatar, .drop-avatar, .avatar-container,avatar img, .user-avatar img {background: transparent !important;border: 0 !important;border-radius: 0 !important;padding: 0 !important;box-shadow: none !important;backdrop-filter: none !important;-webkit-backdrop-filter: none !important;}avatar { flex: 0 0 auto !important; }avatar > img, avatar img { width: 100% !important; height: 100% !important; }/* 表格(非 vxe 的普通表格透明化;vxe 已在上方单独处理) */table, .table {background: transparent !important;color: ${textColor} !important;}table:not(.vxe-table) th {color: ${secColor} !important;background: ${rgba(cfg.primary, 0.06)} !important;}table:not(.vxe-table) td {background: ${rgba(cfg.cardColor, 0.45)} !important;}table:not(.vxe-table) tr:nth-child(even) td {background: ${rgba(cfg.cardColor, 0.3)} !important;}/* 提交详情测试点小卡(.test-detail-item)合并为同一块玻璃 */.test-detail-item {background: ${rgba(cfg.cardColor, 0.06)} !important;margin: 4px 0 !important;border-radius: 6px !important;}.test-run-static, .test-detail-item h2 { background: transparent !important; }/* 代码块(提交记录、公告等)透明化 */pre, code, kbd, samp,[class*="code"], [class*="Code"],[class*="highlight"], [class*="Highlight"],[class*="hljs"], .hljs, .CodeMirror {background: ${rgba(cfg.cardColor, 0.55)} !important;color: ${textColor} !important;border-radius: 6px !important;}pre {border: 1px solid ${rgba(cfg.cardColor, 0.15)} !important;}/* 输入框 */input, textarea, select {background: ${rgba(cfg.cardColor, 0.85)} !important;color: ${textColor} !important;border: 1px solid ${rgba(primary, 0.3)} !important;border-radius: 6px !important;}input:focus, textarea:focus, select:focus {border-color: ${primary} !important;outline: none !important;box-shadow: 0 0 0 3px ${rgba(primary, 0.15)} !important;}/* 按钮 */button, .btn, [class*="button"], [class*="Button"] {color: ${cfg.dark ? textColor : primary} !important;}button.primary, .btn-primary, [class*="primary"] {background: ${primary} !important;border-color: ${primary} !important;color: #fff !important;border-radius: 6px !important;}button.primary:hover, .btn-primary:hover, [class*="primary"]:hover {background: ${primaryHover} !important;border-color: ${primaryHover} !important;}/* 链接 */a {color: ${primary} !important;}a:hover {color: ${primaryHover} !important;}/* 登录弹窗 */.modal-login, .modal, [class*="modal"] {background: ${rgba(cfg.dark ? cfg.cardColor : '#ffffff', Math.max(cfg.opacity, 0.92))} !important;backdrop-filter: blur(${blurPx}) !important;-webkit-backdrop-filter: blur(${blurPx}) !important;border-radius: ${radius} !important;box-shadow: 0 8px 32px rgba(0,0,0,.18) !important;}/* 状态标签 */[class*="tag"], [class*="label"], [class*="badge"] {border-radius: 4px !important;}/* 滚动条 */::-webkit-scrollbar { width: 10px !important; height: 10px !important; }::-webkit-scrollbar-thumb {background: ${rgba(primary, 0.35)} !important;border-radius: 5px !important;}::-webkit-scrollbar-thumb:hover {background: ${rgba(primary, 0.55)} !important;}::-webkit-scrollbar-track { background: transparent !important; }/* 暗色补充 */${cfg.dark ? `${CARD_SELECTORS} {border-color: rgba(255,255,255,.08) !important;}th { background: rgba(255,255,255,.05) !important; }` : ''}/* 自定义 CSS */${cfg.customCSS || ''}`;}let styleEl = null;function applyStyle() {if (!config.enabled) {if (styleEl) styleEl.textContent = '';return;}// 做题页面:保持纯白,不应用美化if (config.cardMode && isSolvingPage()) {if (styleEl) styleEl.textContent = '';return;}const css = buildCSS(config);if (styleEl) styleEl.textContent = css;else styleEl = GM_addStyle(css);}/* ============================================================* 洛谷主题格式 ↔ 配置 转换* ============================================================ */// 洛谷 blur 是三态枚举(源码确证):0/缺省=无模糊;1010=弱(2px);1000或其它非0=强(10px)function luoguBlurToPx(v) {const n = Number(v);if (!n) return 0; // 0 / 缺省 → 无模糊if (n === 1010) return 2; // 弱 → 2pxreturn 10; // 1000 或任意非 0 ≠1010 → 强 → 10px}function pxToLuoguBlur(px) {const n = Math.round(Number(px) || 0);if (n <= 0) return 0; // 0 → 0(关闭)if (n <= 2) return 1010; // 1-2px → 弱档return 1000; // ≥3px → 强档}// 洛谷 midOpts.size → 我们的 bgSize('custom' 时保存原始值)function luoguSizeToOurs(size) {if (!size) return 'cover';const s = String(size).toLowerCase();if (s === 'cover') return 'cover';if (s === 'contain') return 'contain';if (s === 'auto') return 'auto';return 'custom';}function convertLuoguToConfig(luoguTheme) {const cfg = {};// 纯暗色主题(无 lNavi/lBody)时以 dNavi/dBody 为来源const isDarkOnly = !luoguTheme.lNavi && !luoguTheme.lBody && (luoguTheme.dNavi || luoguTheme.dBody);const lNavi = isDarkOnly ? (luoguTheme.dNavi || {}) : (luoguTheme.lNavi || {});const lBody = isDarkOnly ? (luoguTheme.dBody || {}) : (luoguTheme.lBody || {});const mo = lBody.midOpts || {};if (lNavi.back) cfg.naviBack = lNavi.back;if (lNavi.fore) cfg.naviFore = lNavi.fore;if (lBody.back) cfg.bgColor = lBody.back;if (typeof lBody.blur === 'number') cfg.blur = luoguBlurToPx(lBody.blur);if (lBody.image) cfg.bgImage = lBody.image; // 有无背景图只由 image 字段决定// 重复方式:现网 repeat 优先,旧版 notEmpty 回落(notEmpty===false → 平铺)let repeat = 'no-repeat';if (mo.repeat === 'all') repeat = 'repeat';else if (mo.repeat === 'x') repeat = 'repeat-x';else if (mo.repeat === 'y') repeat = 'repeat-y';else if (mo.repeat === 'no-repeat') repeat = 'no-repeat';else if (mo.notEmpty === false || mo.notEmpty === 0) repeat = 'repeat';cfg.bgRepeat = repeat;if (mo.size) {const s = String(mo.size).toLowerCase();cfg.bgSize = luoguSizeToOurs(s);if (cfg.bgSize === 'custom') cfg.bgSizeCustom = String(mo.size);}if (Array.isArray(mo.position) && mo.position.length >= 2) {cfg.bgPosX = clampNum(mo.position[0], 0, 100, 50);cfg.bgPosY = clampNum(mo.position[1], 0, 100, 0);}if (typeof mo.brightness === 'number') cfg.bgBrightness = clampNum(mo.brightness, -100, 100, 0);// degree 是 lBody.color 多色渐变底色方向角(不是图片旋转角),不映射为 bgDegree// fade:只看正负号(>0 顶部 400px 渐隐 / <0 底部 / 0 无),仅取当前层(浅色 lBody / 纯暗色 dBody)const fade = Number(lBody.fade) || 0;if (fade !== 0) cfg.bgFade = fade > 0 ? 1 : -1;return cfg;}function configToLuogu(cfg) {// 以原始洛谷主题为基础,保留未知字段(可加字段不能少)const base = cfg.luoguTheme && typeof cfg.luoguTheme === 'object' ? JSON.parse(JSON.stringify(cfg.luoguTheme)) : {};if (!base.lNavi) base.lNavi = {};if (!base.lBody) base.lBody = {};if (!base.dNavi) base.dNavi = { back: '#ffffff', fore: '#262626' };if (!base.dBody) base.dBody = { back: '#ffffff', blur: 1000, fade: 1000 };const lBody = base.lBody;if (!lBody.midOpts) lBody.midOpts = {};const lNavi = base.lNavi;lNavi.back = cfg.naviBack || cfg.navbarColor || '#ffffff';lNavi.fore = cfg.naviFore || '#333333';lBody.back = cfg.bgColor || '#efefef';lBody.blur = pxToLuoguBlur(cfg.blur);if (cfg.bgImage) lBody.image = cfg.bgImage;lBody.midOpts.size = cfg.bgSize === 'custom' ? (cfg.bgSizeCustom || 'cover') : (cfg.bgSize || 'cover');// degree 是洛谷渐变底色方向角,非图片旋转:有原值则保留,无则不写if (!(lBody.midOpts.degree >= 0)) lBody.midOpts.degree = 0;// 现网用 repeat 字段表达重复方式;旧版 notEmpty 已废弃,导出时删除(无损升级)const repeatMap = { 'repeat': 'all', 'repeat-x': 'x', 'repeat-y': 'y' };lBody.midOpts.repeat = repeatMap[cfg.bgRepeat] || 'no-repeat';delete lBody.midOpts.notEmpty;lBody.midOpts.position = [cfg.bgPosX || 50, cfg.bgPosY || 0];lBody.midOpts.brightness = cfg.bgBrightness || 0;base.name = cfg.themeName || '';return base;}// 判断是否为洛谷主题格式(含 lBody / lNavi 等字段)function isLuoguTheme(obj) {return !!(obj && (obj.lBody || obj.lNavi || obj.dBody || obj.dNavi));}/* ============================================================* 主题导入 / 导出* ============================================================ */function normalizeTheme(obj) {const t = obj || {};return {name: t.name || '',primary: t.primary || t.mainColor || t.accent || DEFAULT_CONFIG.primary,primaryHover: t.primaryHover || DEFAULT_CONFIG.primaryHover,bgColor: t.bgColor || t.background || t.backgroundColor || DEFAULT_CONFIG.bgColor,bgImage: t.bgImage || t.backgroundImage || '',bgPosX: clampNum(t.bgPosX, 0, 100, DEFAULT_CONFIG.bgPosX),bgPosY: clampNum(t.bgPosY, 0, 100, DEFAULT_CONFIG.bgPosY),bgSize: t.bgSize || DEFAULT_CONFIG.bgSize,bgSizeCustom: t.bgSizeCustom || DEFAULT_CONFIG.bgSizeCustom,bgRepeat: t.bgRepeat || DEFAULT_CONFIG.bgRepeat,bgBrightness: clampNum(t.bgBrightness, -100, 100, DEFAULT_CONFIG.bgBrightness),bgDegree: clampNum(t.bgDegree, 0, 360, DEFAULT_CONFIG.bgDegree),bgFade: clampNum(t.bgFade, -1, 1, DEFAULT_CONFIG.bgFade),blur: clampNum(t.blur, 0, 40, DEFAULT_CONFIG.blur),opacity: clampNum(t.opacity, 0, 1, DEFAULT_CONFIG.opacity),radius: clampNum(t.radius, 0, 30, DEFAULT_CONFIG.radius),textColor: t.textColor || DEFAULT_CONFIG.textColor,secondaryColor: t.secondaryColor || DEFAULT_CONFIG.secondaryColor,cardColor: t.cardColor || DEFAULT_CONFIG.cardColor,navbarColor: t.navbarColor || DEFAULT_CONFIG.navbarColor,naviBack: t.naviBack || t.navbarColor || DEFAULT_CONFIG.naviBack,naviFore: t.naviFore || DEFAULT_CONFIG.naviFore,dark: !!t.dark,shadow: t.shadow !== false,customCSS: t.customCSS || ''};}function parseTheme(text) {let obj = null;try { obj = JSON.parse(text); } catch (e) { /* not json */ }if (!obj) {const m = text.match(/\{[\s\S]*\}/);if (m) { try { obj = JSON.parse(m[0]); } catch (e2) { /* ignore */ } }}if (!obj) throw new Error('无法解析主题:请输入 JSON 格式的主题配置');return obj;}// 导入入口:支持 洛谷格式 / 旧格式 / 彩蛋function importTheme(text) {const trimmed = String(text || '').trim();// 彩蛋:输入触发词并导入if (EASTER_EGG_TRIGGERS.includes(trimmed)) {// 彩蛋主题自带完整 __config 快照,直接无损恢复(与导出 JSON 完全一致)const egg = Object.assign({}, DEFAULT_CONFIG,EASTER_EGG_THEME.__config && typeof EASTER_EGG_THEME.__config === 'object'? EASTER_EGG_THEME.__config: convertLuoguToConfig(EASTER_EGG_THEME));return { cfg: egg, isEgg: true };}const obj = parseTheme(trimmed);// 完整快照格式(本脚本导出):__config 保存完整内部状态,直接无损恢复if (obj && obj.__meta && obj.__meta.schema === 'jxycoi-display-better' &&obj.__config && typeof obj.__config === 'object') {return {cfg: Object.assign({}, DEFAULT_CONFIG, obj.__config),isEgg: false};}if (isLuoguTheme(obj)) {// 洛谷主题格式:保留原始完整对象,映射到配置const mapped = convertLuoguToConfig(obj);// 只有暗色部分(无 lNavi/lBody)时视为暗色主题const isDarkLuogu = !obj.lNavi && !obj.lBody && (obj.dNavi || obj.dBody);const merged = Object.assign({}, config, mapped, {dark: isDarkLuogu || !!config.dark,themeName: obj.name || obj.author || '导入的洛谷主题',luoguTheme: obj,luoguExtra: { name: obj.name, author: obj.author, css: obj.css }});return { cfg: merged, isEgg: false };}// 旧格式:脚本自身的配置 JSONconst theme = normalizeTheme(obj);return {cfg: Object.assign({}, config, theme, { themeName: theme.name || config.themeName }),isEgg: false};}function exportTheme() {const luogu = configToLuogu(config);// 附加完整快照,保证导出→导入完全无损往返(洛谷官方浅合并+按已知键读取,__meta/__config 不影响洛谷渲染)luogu.__meta = {schema: 'jxycoi-display-better',schemaVersion: 1,appVersion: '1.2.0',exportedAt: new Date().toISOString(),name: config.themeName || '',author: 'zhanjinghan',source: config.luoguTheme ? 'luogu-import' : 'native'};luogu.__config = JSON.parse(JSON.stringify(config));return JSON.stringify(luogu, null, 2);}function copyText(text) {try {if (navigator.clipboard && navigator.clipboard.writeText) {return navigator.clipboard.writeText(text).then(() => true, () => fallbackCopy(text));}} catch (e) { /* ignore */ }return fallbackCopy(text);}function fallbackCopy(text) {const ta = document.createElement('textarea');ta.value = text;ta.style.position = 'fixed';ta.style.opacity = '0';document.body.appendChild(ta);ta.select();let ok = false;try { ok = document.execCommand('copy'); } catch (e) { /* ignore */ }document.body.removeChild(ta);return Promise.resolve(ok);}/* ============================================================* 去除首页图片(/api/public/img/xxx.png 等大图)* ============================================================ */let hideImgObserver = null;function applyHideHomeImages() {if (!config.hideHomeImages) return;const imgs = document.querySelectorAll('img');imgs.forEach(img => {const src = img.getAttribute('src') || img.currentSrc || '';// 只看 /api/public/img/ 下的图;小尺寸头像(宽高<80px)不隐藏if (src.indexOf('/api/public/img/') !== -1) {const w = img.naturalWidth || img.width;const h = img.naturalHeight || img.height;if (w >= 80 && h >= 80) img.style.display = 'none';}});if (!hideImgObserver) {hideImgObserver = new MutationObserver(() => applyHideHomeImages());hideImgObserver.observe(document.body, { childList: true, subtree: true });}}function clearHideHomeImages() {if (hideImgObserver) { hideImgObserver.disconnect(); hideImgObserver = null; }document.querySelectorAll('img').forEach(img => {const src = img.getAttribute('src') || img.currentSrc || '';if (src.indexOf('/api/public/img/') !== -1) img.style.display = '';});}/* ============================================================* 设置面板 UI* ============================================================ */let panelEl = null, btnEl = null;function el(tag, attrs, children) {const node = document.createElement(tag);if (attrs) {Object.keys(attrs).forEach(k => {if (k === 'style') node.style.cssText = attrs[k];else if (k === 'class') node.className = attrs[k];else if (k.startsWith('on')) node.addEventListener(k.slice(2), attrs[k]);else node.setAttribute(k, attrs[k]);});}(children || []).forEach(c => {if (typeof c === 'string') node.appendChild(document.createTextNode(c));else if (c) node.appendChild(c);});return node;}function buildPanel() {if (panelEl) return panelEl;const P = panelEl = el('div', { style: `position: fixed; right: 24px; top: 80px; z-index: 2147483647;width: 330px; max-height: 80vh; overflow-y: auto;background: rgba(255,255,255,.94); backdrop-filter: blur(20px);border: 1px solid rgba(0,0,0,.1); border-radius: 14px;box-shadow: 0 12px 40px rgba(0,0,0,.2);font-family: -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;font-size: 13px; color: #1f2733; padding: 16px;display: none;` });const title = el('div', { style: `display:flex; justify-content:space-between; align-items:center;font-weight:600; font-size:15px; margin-bottom:12px;` }, [el('span', null, ['JXYCOI Display Better']),el('button', { style: btnStyle(false), onclick: () => { P.style.display = 'none'; } }, ['✕'])]);P.appendChild(title);// 开关P.appendChild(switchRow('enabled', '启用美化', e => {config.enabled = e.target.checked;refreshAll();}));// 主题选择P.appendChild(sectionTitle('主题'));const themeRow = el('div', { style: 'display:flex; gap:6px; flex-wrap:wrap; margin-bottom:10px;' });Object.keys(PRESET_THEMES).forEach(name => {themeRow.appendChild(el('button', {style: btnStyle(name === config.themeName),'data-theme': name,onclick: () => {config = Object.assign({}, config, PRESET_THEMES[name], { themeName: name });refreshAll();}}, [name]));});P.appendChild(themeRow);P.appendChild(sectionTitle('颜色'));P.appendChild(colorRow('primary', '主题色', () => {config.primary = valueOf('cfg-primary');config.primaryHover = darken(config.primary, 0.12);refreshAll();}));P.appendChild(colorRow('bgColor', '背景色', () => {config.bgColor = valueOf('cfg-bgColor');refreshAll();}));P.appendChild(colorRow('naviBack', '导航背景', () => {config.naviBack = valueOf('cfg-naviBack');refreshAll();}));P.appendChild(sectionTitle('背景图片'));const bgImgWrap = el('div', { style: rowStyle() }, [el('label', { style: 'flex:1;' }, ['图片 URL']),el('input', { type: 'text', id: 'cfg-bgImage', value: config.bgImage, placeholder: '留空为纯色', style: inputStyle(), onchange: e => {config.bgImage = e.target.value.trim();refreshAll();} })]);P.appendChild(bgImgWrap);P.appendChild(sliderRow('bgPosX', '图片位置 X', 0, 100, '%', () => {config.bgPosX = Number(valueOf('cfg-bgPosX'));refreshAll();}));P.appendChild(sliderRow('bgPosY', '图片位置 Y', 0, 100, '%', () => {config.bgPosY = Number(valueOf('cfg-bgPosY'));refreshAll();}));// 图片尺寸下拉const sizeWrap = el('div', { style: rowStyle() }, [el('label', { style: 'flex:1;' }, ['图片尺寸']),el('select', { id: 'cfg-bgSize', style: inputStyle(), onchange: e => {config.bgSize = e.target.value;refreshAll();} }, [el('option', { value: 'auto' }, ['自动']),el('option', { value: 'cover' }, ['填充']),el('option', { value: 'contain' }, ['适应']),el('option', { value: 'custom' }, ['自定义'])])]);P.appendChild(sizeWrap);const sizeCustomWrap = el('div', { style: rowStyle() }, [el('label', { style: 'flex:1;' }, ['自定义尺寸']),el('input', { type: 'text', id: 'cfg-bgSizeCustom', value: config.bgSizeCustom, placeholder: '如 100% 100% / 800px 600px', style: inputStyle(), onchange: e => {config.bgSizeCustom = e.target.value.trim();refreshAll();} })]);P.appendChild(sizeCustomWrap);// 图片重复下拉const repeatWrap = el('div', { style: rowStyle() }, [el('label', { style: 'flex:1;' }, ['图片重复']),el('select', { id: 'cfg-bgRepeat', style: inputStyle(), onchange: e => {config.bgRepeat = e.target.value;refreshAll();} }, [el('option', { value: 'no-repeat' }, ['不重复']),el('option', { value: 'repeat' }, ['全部重复']),el('option', { value: 'repeat-x' }, ['横向重复']),el('option', { value: 'repeat-y' }, ['纵向重复'])])]);P.appendChild(repeatWrap);P.appendChild(sliderRow('bgBrightness', '图片亮度', -100, 100, '', () => {config.bgBrightness = Number(valueOf('cfg-bgBrightness'));refreshAll();}));P.appendChild(sliderRow('bgDegree', '图片旋转', 0, 360, '°', () => {config.bgDegree = Number(valueOf('cfg-bgDegree'));refreshAll();}));P.appendChild(sectionTitle('效果'));P.appendChild(sliderRow('blur', '背景模糊', 0, 40, 'px', () => {config.blur = Number(valueOf('cfg-blur'));refreshAll();}));P.appendChild(sliderRow('opacity', '卡片透明度', 0, 100, '%', () => {config.opacity = Number(valueOf('cfg-opacity')) / 100;refreshAll();}));P.appendChild(sliderRow('radius', '卡片圆角', 0, 30, 'px', () => {config.radius = Number(valueOf('cfg-radius'));refreshAll();}));P.appendChild(sectionTitle('功能'));P.appendChild(switchRow('hideHomeImages', '去除首页图片', e => {config.hideHomeImages = e.target.checked;if (config.hideHomeImages) applyHideHomeImages();else clearHideHomeImages();refreshAll();}));P.appendChild(switchRow('cardMode', '卡片化(做题页自动豁免)', e => {config.cardMode = e.target.checked;refreshAll();}));P.appendChild(sectionTitle('导入 / 导出'));const importWrap = el('div', { style: 'margin-bottom:8px;' }, [el('textarea', { id: 'cfg-import', placeholder: '粘贴洛谷主题 JSON / 本脚本导出 JSON', style: 'width:100%; height:56px; box-sizing:border-box; font-size:12px; border:1px solid #d0d7de; border-radius:6px; padding:6px;' }),el('div', { style: 'display:flex; gap:6px; margin-top:6px;' }, [el('button', { style: btnStyle(false), onclick: () => {try {const r = importTheme(valueOf('cfg-import'));config = r.cfg;refreshAll();toast(r.isEgg ? '彩蛋主题已应用 ✨' : '主题导入成功');} catch (e) {toast('导入失败:' + e.message, true);}} }, ['导入主题']),el('button', { style: btnStyle(false), onclick: () => {copyText(exportTheme()).then(ok => toast(ok ? '主题已复制到剪贴板' : '复制失败,请手动选择文本复制', !ok));} }, ['导出主题'])])]);P.appendChild(importWrap);// 自定义 CSSP.appendChild(sectionTitle('自定义 CSS(可选)'));P.appendChild(el('textarea', { id: 'cfg-customCSS', placeholder: '额外 CSS,直接写入 <style>', style: 'width:100%; height:60px; box-sizing:border-box; font-size:12px; border:1px solid #d0d7de; border-radius:6px; padding:6px;', onchange: e => {config.customCSS = e.target.value;refreshAll();} }, []));// 恢复默认P.appendChild(el('div', { style: 'display:flex; gap:6px; margin-top:10px;' }, [el('button', { style: btnStyle(false), onclick: () => {config = Object.assign({}, DEFAULT_CONFIG);refreshAll();toast('已恢复默认配置');} }, ['恢复默认'])]));document.body.appendChild(P);return P;}function sectionTitle(text) {return el('div', { style: `margin: 12px 0 8px; padding-bottom: 4px;font-weight: 600; font-size: 12px; color: #57606a;border-bottom: 1px solid #eaeef2;` }, [text]);}function rowStyle() {return 'display:flex; align-items:center; gap:8px; margin-bottom:8px;';}function inputStyle() {return 'flex:1; min-width:0; font-size:12px; border:1px solid #d0d7de; border-radius:6px; padding:4px 6px; background:#fff; color:#1f2733;';}function btnStyle(active) {return `background: ${active ? '#3498db' : '#f6f8fa'};color: ${active ? '#fff' : '#24292f'};border: 1px solid ${active ? '#3498db' : '#d0d7de'};border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer;`;}function colorRow(id, label, onChange) {return el('div', { style: rowStyle() }, [el('label', { style: 'flex:1;' }, [label]),el('input', { type: 'color', id: 'cfg-' + id, value: config[id], style: 'width:40px;height:26px;border:none;padding:0;background:none;cursor:pointer;', onchange })]);}function sliderRow(id, label, min, max, unit, onChange) {const val = id === 'opacity' ? Math.round(config[id] * 100) : config[id];const out = el('span', { style: 'width:52px;text-align:right;font-size:12px;color:#57606a;' }, [val + unit]);const input = el('input', {type: 'range', id: 'cfg-' + id, min: String(min), max: String(max), value: String(val),style: 'flex:1;', oninput: e => {out.textContent = e.target.value + unit;onChange();}});return el('div', { style: rowStyle() }, [el('label', { style: 'flex:1;' }, [label]),input, out]);}function switchRow(id, label, onChange) {return el('div', { style: rowStyle() }, [el('label', { style: 'flex:1;' }, [label]),el('input', { type: 'checkbox', id: 'cfg-' + id, checked: config[id], style: 'width:16px;height:16px;', onchange: onChange })]);}function valueOf(id) {const n = document.getElementById(id);return n ? n.value : '';}function refreshAll() {saveConfig(config);syncPanelValues();applyStyle();syncThemeButtons();if (config.hideHomeImages) applyHideHomeImages();else clearHideHomeImages();}function syncPanelValues() {if (!panelEl) return;const set = (id, v) => { const n = document.getElementById(id); if (n) n.value = v; };set('cfg-enabled', config.enabled);set('cfg-primary', config.primary);set('cfg-bgColor', config.bgColor);set('cfg-naviBack', config.naviBack);set('cfg-bgImage', config.bgImage);set('cfg-bgPosX', String(config.bgPosX));set('cfg-bgPosY', String(config.bgPosY));set('cfg-bgSize', config.bgSize);set('cfg-bgSizeCustom', config.bgSizeCustom);set('cfg-bgRepeat', config.bgRepeat);set('cfg-bgBrightness', String(config.bgBrightness));set('cfg-bgDegree', String(config.bgDegree));set('cfg-blur', String(config.blur));set('cfg-opacity', String(Math.round(config.opacity * 100)));set('cfg-radius', String(config.radius));set('cfg-hideHomeImages', config.hideHomeImages);set('cfg-cardMode', config.cardMode);set('cfg-customCSS', config.customCSS);}function syncThemeButtons() {if (!panelEl) return;panelEl.querySelectorAll('[data-theme]').forEach(b => {b.style.cssText = btnStyle(b.getAttribute('data-theme') === config.themeName);});}let toastEl = null;function toast(msg, isError) {if (!toastEl) {toastEl = el('div', { style: `position: fixed; left: 50%; bottom: 48px; transform: translateX(-50%);z-index: 2147483647; padding: 8px 16px; border-radius: 8px;background: rgba(0,0,0,.78); color: #fff; font-size: 13px;font-family: -apple-system, 'PingFang SC', sans-serif;opacity: 0; transition: opacity .25s; pointer-events: none;` });document.body.appendChild(toastEl);}toastEl.textContent = msg;toastEl.style.background = isError ? 'rgba(180,60,60,.92)' : 'rgba(0,0,0,.78)';toastEl.style.opacity = '1';clearTimeout(toastEl._t);toastEl._t = setTimeout(() => { toastEl.style.opacity = '0'; }, 2200);}function buildButton() {if (btnEl) return btnEl;btnEl = el('div', { style: `position: fixed; right: 20px; top: 76px; z-index: 2147483646;width: 44px; height: 44px; border-radius: 50%;background: linear-gradient(135deg, #3498db, #5b8def);color: #fff; display: flex; align-items: center; justify-content: center;cursor: pointer; box-shadow: 0 4px 16px rgba(52,152,219,.4);font-size: 20px; user-select: none; transition: transform .15s;`, onclick: e => {e.stopPropagation();const P = buildPanel();P.style.display = P.style.display === 'none' ? 'block' : 'none';syncPanelValues();syncThemeButtons();} }, ['🎨']);btnEl.title = 'JXYCOI Display Better 设置';document.body.appendChild(btnEl);return btnEl;}/* ============================================================* SPA 适配:MutationObserver 补样式/入口/图片隐藏* ============================================================ */let moTimer = null;function onDomChange() {clearTimeout(moTimer);moTimer = setTimeout(() => {applyStyle();if (config.hideHomeImages) applyHideHomeImages();if (btnEl && !btnEl.isConnected) document.body.appendChild(btnEl);if (panelEl && !panelEl.isConnected) document.body.appendChild(panelEl);}, 300);}/* ============================================================* 初始化* ============================================================ */function init() {if (!document.body) {document.addEventListener('DOMContentLoaded', init);return;}applyStyle();if (config.hideHomeImages) applyHideHomeImages();buildButton();new MutationObserver(onDomChange).observe(document.body, { childList: true, subtree: true });}if (document.readyState === 'loading') {document.addEventListener('DOMContentLoaded', init);} else {init();}})();```