跳到正文

个人记录

JXYCOI display better

zhanjinghan约 44 分钟
原文

这是 2026年10月16日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年10月16日
收录
2026年10月16日
更新
2026年11月13日
篇幅
约 44 分钟
获赞
1

版本

  1. v5当前
  2. v4
  3. v3
  4. v2
更早的 1 个版本
  1. v1

// ==UserScript== // @name JXYCOI Display Better // @namespace https://www.jxycoi.cn/ // @version 1.0.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/* // @grant GM_addStyle // @grant GM_getValue // @grant GM_setValue // @run-at document-start // @noframes // ==/UserScript==

(function () { ‘use strict’;

/* ============================================================

  • 默认配置
  • ============================================================ */ const DEFAULT_CONFIG = { enabled: true, // 总开关 themeName: ‘洛谷经典蓝’, // 当前主题名 dark: false, // 暗色模式 primary: ‘#3498db’, // 主色 primaryHover: ‘#2980b9’, // 主色 hover bgColor: ‘#f0f2f5’, // 页面背景色 bgImage: ”, // 背景图片 URL(留空则纯色) blur: 12, // 背景模糊度 px (0-40) opacity: 0.86, // 卡片透明度 0.3-1 radius: 10, // 卡片圆角 px textColor: ‘#1f2733’, // 正文颜色 secondaryColor: ‘#6b7280’, // 次要文字颜色 cardColor: ‘#ffffff’, // 卡片底色 navbarColor: ‘#ffffff’, // 顶栏底色 shadow: 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’, navbarColor: ‘#ffffff’, dark: false, shadow: true }, ‘洛谷翠绿’: { primary: ‘#27ae60’, primaryHover: ‘#1e8449’, bgColor: ‘#f0f4f2’, bgImage: ”, blur: 14, opacity: 0.87, radius: 12, textColor: ‘#1f2733’, secondaryColor: ‘#5f7a6e’, cardColor: ‘#ffffff’, navbarColor: ‘#ffffff’, dark: false, shadow: true }, ‘洛谷暮紫’: { primary: ‘#8e44ad’, primaryHover: ‘#732d91’, bgColor: ‘#f3eff6’, bgImage: ”, blur: 16, opacity: 0.85, radius: 14, textColor: ‘#2c2433’, secondaryColor: ‘#7a6b8a’, cardColor: ‘#ffffff’, navbarColor: ‘#ffffff’, dark: false, shadow: true }, ‘洛谷暗夜’: { primary: ‘#61afef’, primaryHover: ‘#4a9be0’, bgColor: ‘#1a1f2b’, bgImage: ”, blur: 10, opacity: 0.92, radius: 10, textColor: ‘#d8dee9’, secondaryColor: ‘#9aa5b8’, cardColor: ‘#232a38’, navbarColor: ‘#1e2530’, dark: true, shadow: false }, ‘毛玻璃亚克力’: { primary: ‘#5b8def’, primaryHover: ‘#4a76d6’, bgColor: ‘#eef2fb’, bgImage: ”, blur: 22, opacity: 0.55, radius: 16, textColor: ‘#1f2733’, secondaryColor: ‘#6b7280’, cardColor: ‘#ffffff’, navbarColor: ‘#ffffff’, dark: false, shadow: false } };

/* ============================================================

  • 存储封装(优先 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)}); }

/* ============================================================

  • 样式生成
  • ============================================================ / const CARD_SELECTORS = ‘.card-container, .card, .panel, .module-card, [class=“card”], [class*=“Card”]’;

function buildCSS(cfg) { const cardBg = rgba(cfg.cardColor, cfg.opacity); const navbarBg = rgba(cfg.navbarColor, 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’;

代码
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∣∣′′′)no−repeatfixedcenter/cover!important;filter:blur({cfg.bgImage || ''}') no-repeat fixed center/cover !important; filter: blur({cfg.blur > 0 ? blurPx : ‘0px’}) !important; transform: scale(1.06) !important; pointer-events: none !important; display: {cfg.bgImage ? 'block' : 'none'} !important; } /* 顶栏 */ .top-navbar, header, nav, .navbar { background: {navbarBg} !important; backdrop-filter: blur(blurPx)saturate(140−webkit−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: 0 1px 4px rgba(0,0,0,.06) !important; } .top-navbar a, header a, nav a, .navbar a { color: {cfg.dark ? textColor : primary} !important; } .top-navbar a:hover, header a:hover, nav a:hover, .navbar a:hover { color: {primaryHover} !important; } /* 卡片容器 */ {CARD_SELECTORS} { background: cardBg!important;backdrop−filter:blur({cardBg} !important; backdrop-filter: blur({blurPx}) !important; -webkit-backdrop-filter: blur(blurPx)!important;border−radius:{blurPx}) !important; border-radius: {radius} !important; border: 1px solid rgba(cfg.cardColor,0.12)!important;box−shadow:{rgba(cfg.cardColor, 0.12)} !important; box-shadow: {shadow} !important; color: {textColor} !important; } /* 表格 */ table, .table { background: transparent !important; color: {textColor} !important; } th { color: secColor!important;background:{secColor} !important; background: {rgba(cfg.primary, 0.06)} !important; } tr:nth-child(even) td { background: {rgba(cfg.cardColor, 0.35)} !important; } /* 输入框 */ input, textarea, select { background: {rgba(cfg.cardColor, 0.85)} !important; color: textColor!important;border:1pxsolid{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:0003px{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; -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; } const css = buildCSS(config); if (styleEl) styleEl.textContent = css; else styleEl = GM_addStyle(css); }

/* ============================================================

  • 主题导入 / 导出
  • ============================================================ / 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 || ”, blur: clampNum(t.blur, 0, 40, DEFAULT_CONFIG.blur), opacity: clampNum(t.opacity, 0.3, 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, dark: !!t.dark, shadow: t.shadow !== false, customCSS: t.customCSS || ” }; } function clampNum(v, min, max, def) { const n = Number(v); if (Number.isNaN(n)) return def; return Math.min(max, Math.max(min, n)); } 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 normalizeTheme(obj); } function exportTheme() { const { themeName, …rest } = config; return JSON.stringify({ name: themeName, …rest }, 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); }

/* ============================================================

  • 设置面板 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);

// 开关
const enabledWrap = el('div', { style: rowStyle() }, [
  el('label', { style: 'flex:1;' }, ['启用美化']),
  el('input', { type: 'checkbox', id: 'cfg-enabled', checked: config.enabled, onchange: e => {
    config.enabled = e.target.checked;
    saveConfig(config);
    applyStyle();
  } })
]);
P.appendChild(enabledWrap);

// 主题选择
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(sectionTitle('背景'));
P.appendChild(colorRow('bgColor', '背景色', () => {
  config.bgColor = valueOf('cfg-bgColor');
  refreshAll();
}));
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(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('导入 / 导出'));
const importWrap = el('div', { style: 'margin-bottom:8px;' }, [
  el('textarea', { id: 'cfg-import', placeholder: '粘贴主题 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 theme = parseTheme(valueOf('cfg-import'));
        config = Object.assign({}, config, theme, { themeName: theme.name || config.themeName });
        refreshAll();
        toast('主题导入成功');
      } catch (e) {
        toast('导入失败:' + e.message, true);
      }
    } }, ['导入主题']),
    el('button', { style: btnStyle(false), onclick: () => {
      copyText(exportTheme()).then(ok => toast(ok ? '主题已复制到剪贴板' : '复制失败,请手动选择文本复制', !ok));
    } }, ['导出主题'])
  ])
]);
P.appendChild(importWrap);

// 自定义 CSS
P.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 valueOf(id) { const n = document.getElementById(id); return n ? n.value : ”; }

function refreshAll() { saveConfig(config); syncPanelValues(); applyStyle(); syncThemeButtons(); } 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-bgImage’, config.bgImage); set(‘cfg-blur’, String(config.blur)); set(‘cfg-opacity’, String(Math.round(config.opacity * 100))); set(‘cfg-radius’, String(config.radius)); 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’; }, 2000); }

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; }

/* ============================================================

  • 初始化
  • ============================================================ */ function init() { if (!document.body) { document.addEventListener(‘DOMContentLoaded’, init); return; } applyStyle(); buildButton(); }

if (document.readyState === ‘loading’) { document.addEventListener(‘DOMContentLoaded’, init); } else { init(); } })();