跳到正文

科技·工程

丝滑的vjudge界面

_CLion_约 6 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年6月1日
篇幅
约 6 分钟

版本

  1. v1当前
JavaScript
// ==UserScript==
// @name         VJudge.net UI Enhancer
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  增强 VJudge 界面:悬停下划线、滑动指示器、Comfortaa 字体、导航渐变背景
// @match        https://vjudge.net/*
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    //
    // 1. 加载 Comfortaa 圆滑英文字体
    //
    const fontLink = document.createElement('link');
    fontLink.rel  = 'stylesheet';
    fontLink.href = 'https://fonts.googleapis.com/css2?family=Comfortaa:wght@300;400;700&display=swap';
    document.head.appendChild(fontLink);

    //
    // 2. 注入全局样式
    //
    GM_addStyle(`
        /* 渐变背景:可根据喜好调整颜色 */
        .navbar, .header, header {
            background: linear-gradient(90deg, #6a11cb, #2575fc) !important;
        }

        /* 全局 Comfortaa 字体 */
        body, input, button, select, textarea {
            font-family: 'Comfortaa', cursive !important;
        }

        /* 悬停下划线效果 */
        a, .nav-link {
            position: relative;
            overflow: hidden;
            color: inherit;
        }
        a::after, .nav-link::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 0;
            height: 2px;
            background: currentColor;
            transition: width 0.3s ease;
        }
        a:hover::after, .nav-link:hover::after {
            width: 100%;
        }
    `);

    //
    // 3. 导航滑动指示器
    //
    function initNavIndicator() {
        const nav = document.querySelector('.navbar-nav');
        if (!nav) return;

        // 确保父容器有定位
        nav.style.position = 'relative';

        // 创建指示器
        const indicator = document.createElement('div');
        indicator.className = 'nav-indicator';
        nav.appendChild(indicator);

        // 指示器样式
        GM_addStyle(`
            .nav-indicator {
                position: absolute;
                bottom: 0;
                height: 3px;
                width: 0;
                background: #ffffff;
                transition: transform 0.3s ease, width 0.3s ease;
            }
        `);

        // 计算并移动指示器
        function moveIndicator(el) {
            const navRect = nav.getBoundingClientRect();
            const rect    = el.getBoundingClientRect();
            const offsetX = rect.left - navRect.left;
            indicator.style.transform = 'translateX(' + offsetX + 'px)';
            indicator.style.width     = rect.width + 'px';
        }

        // 初始定位到当前激活项
        const active = nav.querySelector('.nav-link.active');
        if (active) {
            setTimeout(() => moveIndicator(active), 0);
        }

        // 点击或切换时更新位置
        nav.querySelectorAll('.nav-link').forEach(link => {
            link.addEventListener('click', () => {
                moveIndicator(link);
            });
        });

        // 窗口大小变化时重新对齐
        window.addEventListener('resize', () => {
            const curr = nav.querySelector('.nav-link.active');
            if (curr) moveIndicator(curr);
        });
    }

    // DOM 完全加载后初始化
    document.addEventListener('DOMContentLoaded', initNavIndicator);
})();

效果

原文