前言
个人一直比较喜欢模糊效果,尤其是在macOS和iOS中滑动页面顶栏也能模糊下方内容,于是和DeepSeek一起写了这个Tampermonkey脚本,能够给洛谷添加高斯模糊效果。
功能
本脚本做了如下美化:
- 大部分界面和组件使用16px圆角。
- 顶栏、侧边栏模糊效果。
- 部分弹出菜单模糊效果。
- 弹窗背景高斯模糊效果。
截图
浅色模式
深色模式
在Dark Reader下的效果
使用
现在浏览器中安装Tampermonkey。然后点击Tampermonkey扩展图标,在弹出的菜单中点击“添加新脚本”,在编辑页面中删掉原来的内容,将以下内容粘贴进去,然后按下Ctrl + S保存,刷新原有页面即可生效。
脚本
// ==UserScript==
// @name 洛谷圆角高斯模糊美化
// @namespace https://www.luogu.com.cn/user/1816684
// @version 1.0
// @description 为洛谷提供毛玻璃、圆角、透明滚动条等视觉美化。
// @match *://www.luogu.com.cn/*
// @match *://www.luogu.com/*
// @run-at document-start
// @grant none
// ==/UserScript==
(function() {
'use strict';
const style = document.createElement('style');
style.textContent = `
/* 全局滚动条透明(WebKit) */
::-webkit-scrollbar {
width: 8px;
height: 8px;
background: transparent !important;
}
::-webkit-scrollbar-track {
background: transparent !important;
}
::-webkit-scrollbar-thumb {
background: rgba(0, 0, 0, 0.2) !important;
border-radius: 10px !important;
}
::-webkit-scrollbar-thumb:hover {
background: rgba(0, 0, 0, 0.3) !important;
}
/* Firefox 滚动条透明 */
* {
scrollbar-width: thin !important;
scrollbar-color: rgba(0, 0, 0, 0.2) transparent !important;
}
/* 顶栏毛玻璃 */
.top-bar {
background: rgba(255, 255, 255, 0.65) !important;
backdrop-filter: blur(10px) !important;
-webkit-backdrop-filter: blur(10px) !important;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08) !important;
border-bottom: 1px solid rgba(0, 0, 0, 0.05) !important;
}
/* 侧边栏毛玻璃 */
.sidebar.lside, .lside.drawer {
background: rgba(255, 255, 255, 0.7) !important;
backdrop-filter: blur(10px) !important;
-webkit-backdrop-filter: blur(10px) !important;
border-right: 1px solid rgba(0, 0, 0, 0.06) !important;
}
.user-nav.rside {
background: rgba(255, 255, 255, 0.7) !important;
backdrop-filter: blur(10px) !important;
-webkit-backdrop-filter: blur(10px) !important;
border-left: 1px solid rgba(0, 0, 0, 0.06) !important;
}
/* 修复侧边栏收起后宽度不足导致省略号,同时保留原生展开行为 */
.sidebar.lside.bar.hide {
min-width: 67px !important;
}
/* 弹窗背景遮罩(无模糊) */
.swal2-container,
.am-modal-overlay,
.cs-dialog-container,
.modal-backdrop,
.v--modal-overlay,
.el-overlay,
[class*="backdrop"][style*="fixed"],
[class*="overlay"][style*="fixed"] {
backdrop-filter: none !important;
-webkit-backdrop-filter: none !important;
}
/* 毛玻璃弹窗(排除用户中心面板) */
.swal2-popup,
.l-card.container.type-burger,
.cover-upload,
#lg-alert .am-modal-dialog,
.cs-dialog,
.dropdown:not(.dropdown:has(.dropdown-operations)):not(.dropdown:has(.l-card.float-card)):not(.dropdown:has(ul.setting-dropdown)),
.popup-wrap .popup {
background: rgba(255, 255, 255, 0.85) !important;
backdrop-filter: blur(12px) !important;
-webkit-backdrop-filter: blur(12px) !important;
border: 1px solid rgba(255, 255, 255, 0.2) !important;
border-radius: 16px !important;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1) !important;
}
.popup-wrap .apps {
background: transparent !important;
}
/* 用户中心面板:无模糊,但保留圆角与阴影 */
.center {
background: var(--lfe-color--card, #fff) !important;
border-radius: 16px !important;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
backdrop-filter: none !important;
-webkit-backdrop-filter: none !important;
border: none !important;
}
.center * {
text-shadow: none !important;
}
.dropdown:has(.center) {
background: transparent !important;
backdrop-filter: none !important;
border: none !important;
border-radius: 0 !important;
box-shadow: none !important;
position: absolute !important;
}
/* SweetAlert2 图标修复 */
.swal2-success-circular-line-left,
.swal2-success-fix,
.swal2-success-circular-line-right,
.swal2-error-circular-line-left,
.swal2-error-fix,
.swal2-error-circular-line-right {
background: transparent !important;
}
/* 文字清晰度优化(排除 .center) */
.l-card.container.type-burger *,
.cover-upload *,
.swal2-popup *,
#lg-alert .am-modal-dialog *,
.cs-dialog *,
.mp-dialog-header *,
.mp-dialog-body *,
.dropdown-operations *,
.l-card:not(.float-card) *,
.card *,
.info-rows *,
.popup-wrap * {
text-shadow: 0 0 1px rgba(255, 255, 255, 0.6);
}
/* 统一圆角(排除 .center) */
.l-card:not(.float-card):not(.l-card.container.type-burger),
.card,
.lg-article,
.lg-index-stat,
.info-rows {
border-radius: 16px !important;
overflow: hidden !important;
}
.am-input-group {
border-radius: 16px !important;
overflow: visible !important;
}
input, select, textarea {
border-radius: 8px !important;
}
button, .l-button, .am-modal-btn, .cs-dialog-button, .mp-dialog-button,
.swal2-confirm, .swal2-cancel, button[class*="lform-size"], .btn-checkbox,
.solid, .toolbar button, .page-bar button, .am-btn, .am-btn-primary,
.am-btn-danger, .am-btn-sm, .am-btn-xs {
border-radius: 8px !important;
}
/* 洛谷推荐卡片圆角 */
div[data-v-ce0b4304] {
border-radius: 16px !important;
overflow: hidden !important;
}
div[data-v-ce0b4304] > a:first-child img {
border-radius: 16px 16px 0 0 !important;
display: block;
width: 100%;
}
/* 语言选择器 */
.combo-wrapper .text {
border-radius: 8px !important;
background: #ffffff !important;
border: 1px solid #b0b0b0 !important;
}
.combo-wrapper .arrow {
background: transparent !important;
}
/* 下拉菜单滚动条透明(已包含在全局中) */
/* 插入图片弹窗 */
.mp-dialog-header, .mp-dialog-body {
background: rgba(255, 255, 255, 0.85) !important;
backdrop-filter: blur(12px) !important;
}
.mp-dialog-header:first-child {
border-top-left-radius: 8px;
border-top-right-radius: 8px;
}
.mp-dialog-body:last-child {
border-bottom-left-radius: 8px;
border-bottom-right-radius: 8px;
}
/* 强制收缩左侧导航栏菜单 */
.dropdown:has(ul.setting-dropdown) {
background: transparent !important;
backdrop-filter: none !important;
border: none !important;
border-radius: 0 !important;
}
ul.setting-dropdown {
background: rgba(255, 255, 255, 0.85) !important;
backdrop-filter: blur(12px) !important;
border-radius: 12px !important;
}
ul.setting-dropdown * {
text-shadow: 0 0 1px rgba(255, 255, 255, 0.6);
}
/* 庆祝弹窗透明 */
.swal2-popup:has(.swal2-image[src*="ac-congrats"]) {
background: transparent !important;
backdrop-filter: none !important;
border: none !important;
border-radius: 0 !important;
box-shadow: none !important;
}
.swal2-popup:has(.swal2-image[src*="ac-congrats"]) * {
text-shadow: none !important;
}
/* 用户卡片 */
.dropdown:has(.l-card.float-card) {
background: transparent !important;
backdrop-filter: none !important;
border: none !important;
border-radius: 0 !important;
}
.l-card.float-card {
background: rgba(255, 255, 255, 0.85) !important;
backdrop-filter: blur(12px) !important;
border-radius: 16px !important;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1) !important;
overflow: hidden !important;
}
.l-card.float-card * {
text-shadow: 0 0 1px rgba(255, 255, 255, 0.6);
}
/* 操作菜单 */
.dropdown:has(.dropdown-operations) {
background: transparent !important;
backdrop-filter: none !important;
border: none !important;
border-radius: 0 !important;
}
.dropdown-operations {
background: rgba(255, 255, 255, 0.85) !important;
backdrop-filter: blur(12px) !important;
border-radius: 12px !important;
padding: 4px 0 !important;
}
.dropdown-operations li:hover {
background: rgba(255, 255, 255, 0.25) !important;
}
/* 全局滚动条额外优化(已包含) */
/* 保留原有文字阴影 */
.top-bar .left, .top-bar .right, .top-bar .breadcrumb, .top-bar .user-nav,
.sidebar.lside, .lside.drawer, .user-nav.rside {
text-shadow: 0 0 1px rgba(255, 255, 255, 0.5);
}
`;
document.head.appendChild(style);
// 动态修正 toast 容器的遮罩背景(解决首次闪现问题)
function fixToastContainer(container) {
if (!container) return;
if (container.querySelector('.swal2-toast')) {
container.style.background = 'transparent';
container.style.backdropFilter = 'none';
} else if (container.querySelector('.swal2-popup')) {
container.style.background = 'rgba(0, 0, 0, 0.4)';
container.style.backdropFilter = 'none';
}
}
const observer = new MutationObserver(mutations => {
for (const mutation of mutations) {
for (const node of mutation.addedNodes) {
if (node.nodeType === 1 && node.classList && node.classList.contains('swal2-container')) {
fixToastContainer(node);
}
if (node.nodeType === 1 && node.querySelectorAll) {
node.querySelectorAll('.swal2-container').forEach(fixToastContainer);
}
}
}
});
observer.observe(document.body, { childList: true, subtree: true });
document.querySelectorAll('.swal2-container').forEach(fixToastContainer);
})();注意事项
由于使用了 backdrop-filter 和 :has() 选择器等较新的CSS特性,建议使用最新版浏览器。如果通过题目弹窗也有模糊,则说明你的浏览器不支持 :has(),不是脚本的问题。
结语
欢迎大家使用,如果有问题请在评论区反馈。







