洛谷增强工具
洛谷增强工具功能说明
功能概览
1. 全局保存站链接
在网站顶部导航栏添加"洛谷保存站"链接,方便快速访问保存站。
2. 安全中心链接自动替换
访问安全中心页面时,自动将外部链接替换为安全的保存站链接,按钮文字改为"通过保存站访问"。
3. 个人主页优化
查看他人主页(非管理员)时,在个人介绍卡片中添加"在保存站打开"按钮。
4. 侧边栏保存站入口
侧边栏添加洛谷保存站菜单和图标。
5. 日志输出
使用 F12 打开 检查 的 控制台 可以方便地查看日志以查找问题。
运行特性
- 自动检测页面并添加功能
- 日志去重:相同日志30秒内仅输出一次
- 支持重试机制,确保功能稳定运行
- 适配洛谷现有页面布局
- 支持氧洛谷、exlg、Oiso++等大多数插件
使用说明
安装篡改猴插件后添加此脚本即可,无需额外配置,访问洛谷时自动生效。
源代码
// ==UserScript==
// @name 洛谷增强工具
// @namespace http://tampermonkey.net/
// @version 2.2
// @description 1.全局添加洛谷保存站链接 2.安全中心自动替换链接 3.个人主页优化 4.侧边栏添加保存站入口 5.深色侧边栏添加保存站链接
// @author Gavinbeta
// @match https://www.luogu.com.cn/*
// @match https://luogu.com.cn/*
// @grant none
// @run-at document-end
// ==/UserScript==
console.log("[洛谷增强工具] 脚本开始加载...");
(function() {
'use strict';
// ==================== 配置常量 ====================
const CONFIG = {
checkInterval: 1000,
retryMaxCount: 10,
logColor: '#FFA500',
securityPathKeywords: ['paste', 'article'],
userProfilePath: 'user',
oldDomains: ['luogu.com.cn', 'luogu.com'],
newDomain: 'luogu.me',
saveStationUrl: 'https://www.luogu.me/',
logCooldown: 30000 // 30秒内不重复输出相同日志
};
// 状态管理
const state = {
securityRetryCount: 0,
saveLinkAdded: false,
sidebarSaveLinkAdded: false,
darkSidebarSaveLinkAdded: false
};
// 日志缓存 - 存储最近30秒内已输出的日志
const logCache = new Map();
// 定期清理过期的日志缓存
function cleanExpiredLogCache() {
const now = Date.now();
for (const [message, timestamp] of logCache.entries()) {
if (now - timestamp > CONFIG.logCooldown) {
logCache.delete(message);
}
}
}
// SVG图标定义
const SVG_ICON = {
light: `<path d="M0 0 C0.92 -0.02 1.84 -0.05 2.79 -0.07 C9.87 -0.1 15.42 1.16 20.66 6.13 C21.06 6.73 21.46 7.32 21.88 7.94 C22.36 8.63 22.84 9.33 23.33 10.05 C24.37 11.67 25.38 13.31 26.39 14.95 C30.16 21.11 34.29 26.27 39.24 31.53 C44.25 37.08 48.66 43.15 52.81 49.38 C53.85 48.25 53.85 48.25 54.91 47.09 C55.9 46.02 56.89 44.95 57.88 43.88 C58.41 43.3 58.94 42.72 59.48 42.13 C62.52 38.83 65.57 35.57 68.67 32.34 C75.66 25.01 82.16 17.81 87.81 9.38 C92.8 1.94 92.8 1.94 96.81 0.38 C100.07 -0.04 103.34 0.05 106.62 0.06 C107.5 0.05 108.38 0.03 109.28 0.01 C114.9 0.01 118.83 0.75 123.81 3.38 C124.81 4.38 124.81 4.38 125.11 7.52 C124.77 11.89 123.43 14.5 121 18 C120.4 18.9 120.4 18.9 119.79 19.81 C115.69 25.81 111.06 31.33 106.24 36.76 C105.24 37.89 104.26 39.03 103.28 40.17 C99.14 45.02 94.73 49.41 90.04 53.73 C81.38 61.78 72.95 70.05 64.59 78.41 C62.23 80.77 59.85 83.13 57.48 85.48 C44.01 97.28 44.01 97.28 35.81 112.38 C36.36 112.71 36.9 113.05 37.46 113.4 C39.96 114.95 42.45 116.5 44.94 118.06 C45.79 118.59 46.65 119.12 47.53 119.67 C61.38 128.35 61.38 128.35 62.81 133.38 C63.59 140.32 63.59 140.32 61.54 143.1 C58.46 145.37 54.61 144.72 50.94 144.62 C50.06 144.61 49.18 144.6 48.28 144.58 C46.41 144.54 44.55 144.5 42.69 144.45 C39.82 144.38 36.96 144.34 34.1 144.32 C32.26 144.28 30.41 144.23 28.56 144.19 C27.71 144.18 26.85 144.18 25.97 144.17 C16.82 143.84 10.92 139.14 4.78 132.68 C0.33 127.46 -4.47 121.83 -5 114.75 C-3.95 105.67 3.99 98.79 10.2 92.73 C10.99 91.95 11.77 91.17 12.58 90.37 C15.07 87.9 17.57 85.45 20.06 83 C22.57 80.53 25.08 78.05 27.58 75.57 C29.14 74.03 30.69 72.5 32.25 70.97 C33.3 69.94 33.3 69.94 34.38 68.88 C34.99 68.27 35.61 67.67 36.25 67.04 C38.01 65.25 38.01 65.25 39.81 62.38 C39.04 62.29 38.27 62.2 37.47 62.11 C27.02 60.7 20.9 57.42 14.07 49.41 C10.56 44.68 7.54 39.65 4.47 34.62 C0.49 28.21 -3.97 22.55 -9.01 16.94 C-13.21 11.99 -13.7 8.74 -13.19 2.38 C-8.88 -0.5 -5.07 0.01 0 0 Z " fill="#000000" transform="translate(43.1875,-0.375)"></path><path d="M0 0 C1.04 -0.02 1.04 -0.02 2.09 -0.05 C11.26 -0.06 16.86 4.22 23.25 10.31 C23.96 10.99 24.68 11.67 25.41 12.38 C27.63 14.52 29.82 16.69 32 18.88 C32.74 19.6 33.48 20.33 34.25 21.08 C40.3 27.12 45.25 32.32 45.69 41.25 C45.55 50.79 40.91 57.97 34.38 64.62 C32.11 66.77 29.82 68.85 27.4 70.83 C22.04 75.3 18.01 80.22 13.94 85.88 C12.63 87.65 11.32 89.43 10.01 91.2 C9.05 92.5 9.05 92.5 8.08 93.83 C-8.16 115.87 -8.16 115.87 -16.75 119.31 C-21.65 119.87 -26.22 119.94 -30.81 118.06 C-33.68 115.47 -34.62 113.33 -35.12 109.5 C-35.3 101 -33.65 94.83 -29.75 87.31 C-29.13 86.08 -29.13 86.08 -28.5 84.83 C-20.5 70.27 -7.66 58.61 5.44 48.72 C7.35 47.29 7.35 47.29 9.25 45.31 C9.27 43.09 9.27 43.09 8.88 40.69 C8.76 39.87 8.65 39.05 8.54 38.21 C8.44 37.58 8.35 36.96 8.25 36.31 C7.68 36.19 7.11 36.08 6.53 35.95 C-2.74 33.35 -8.83 27.16 -13.73 19.18 C-15.91 15.17 -16.22 11.81 -15.75 7.31 C-11.02 1.56 -7.25 -0.03 0 0 Z " fill="000000" transform="translate(117.75,80.6875)"></path>`,
dark: `<path d="M0 0 C0.92 -0.02 1.84 -0.05 2.79 -0.07 C9.87 -0.1 15.42 1.16 20.66 6.13 C21.06 6.73 21.46 7.32 21.88 7.94 C22.36 8.63 22.84 9.33 23.33 10.05 C24.37 11.67 25.38 13.31 26.39 14.95 C30.16 21.11 34.29 26.27 39.24 31.53 C44.25 37.08 48.66 43.15 52.81 49.38 C53.85 48.25 53.85 48.25 54.91 47.09 C55.9 46.02 56.89 44.95 57.88 43.88 C58.41 43.3 58.94 42.72 59.48 42.13 C62.52 38.83 65.57 35.57 68.67 32.34 C75.66 25.01 82.16 17.81 87.81 9.38 C92.8 1.94 92.8 1.94 96.81 0.38 C100.07 -0.04 103.34 0.05 106.62 0.06 C107.5 0.05 108.38 0.03 109.28 0.01 C114.9 0.01 118.83 0.75 123.81 3.38 C124.81 4.38 124.81 4.38 125.11 7.52 C124.77 11.89 123.43 14.5 121 18 C120.4 18.9 120.4 18.9 119.79 19.81 C115.69 25.81 111.06 31.33 106.24 36.76 C105.24 37.89 104.26 39.03 103.28 40.17 C99.14 45.02 94.73 49.41 90.04 53.73 C81.38 61.78 72.95 70.05 64.59 78.41 C62.23 80.77 59.85 83.13 57.48 85.48 C44.01 97.28 44.01 97.28 35.81 112.38 C36.36 112.71 36.9 113.05 37.46 113.4 C39.96 114.95 42.45 116.5 44.94 118.06 C45.79 118.59 46.65 119.12 47.53 119.67 C61.38 128.35 61.38 128.35 62.81 133.38 C63.59 140.32 63.59 140.32 61.54 143.1 C58.46 145.37 54.61 144.72 50.94 144.62 C50.06 144.61 49.18 144.6 48.28 144.58 C46.41 144.54 44.55 144.5 42.69 144.45 C39.82 144.38 36.96 144.34 34.1 144.32 C32.26 144.28 30.41 144.23 28.56 144.19 C27.71 144.18 26.85 144.18 25.97 144.17 C16.82 143.84 10.92 139.14 4.78 132.68 C0.33 127.46 -4.47 121.83 -5 114.75 C-3.95 105.67 3.99 98.79 10.2 92.73 C10.99 91.95 11.77 91.17 12.58 90.37 C15.07 87.9 17.57 85.45 20.06 83 C22.57 80.53 25.08 78.05 27.58 75.57 C29.14 74.03 30.69 72.5 32.25 70.97 C33.3 69.94 33.3 69.94 34.38 68.88 C34.99 68.27 35.61 67.67 36.25 67.04 C38.01 65.25 38.01 65.25 39.81 62.38 C39.04 62.29 38.27 62.2 37.47 62.11 C27.02 60.7 20.9 57.42 14.07 49.41 C10.56 44.68 7.54 39.65 4.47 34.62 C0.49 28.21 -3.97 22.55 -9.01 16.94 C-13.21 11.99 -13.7 8.74 -13.19 2.38 C-8.88 -0.5 -5.07 0.01 0 0 Z " fill="#DFDFDF" transform="translate(43.1875,-0.375)"></path><path d="M0 0 C1.04 -0.02 1.04 -0.02 2.09 -0.05 C11.26 -0.06 16.86 4.22 23.25 10.31 C23.96 10.99 24.68 11.67 25.41 12.38 C27.63 14.52 29.82 16.69 32 18.88 C32.74 19.6 33.48 20.33 34.25 21.08 C40.3 27.12 45.25 32.32 45.69 41.25 C45.55 50.79 40.91 57.97 34.38 64.62 C32.11 66.77 29.82 68.85 27.4 70.83 C22.04 75.3 18.01 80.22 13.94 85.88 C12.63 87.65 11.32 89.43 10.01 91.2 C9.05 92.5 9.05 92.5 8.08 93.83 C-8.16 115.87 -8.16 115.87 -16.75 119.31 C-21.65 119.87 -26.22 119.94 -30.81 118.06 C-33.68 115.47 -34.62 113.33 -35.12 109.5 C-35.3 101 -33.65 94.83 -29.75 87.31 C-29.13 86.08 -29.13 86.08 -28.5 84.83 C-20.5 70.27 -7.66 58.61 5.44 48.72 C7.35 47.29 7.35 47.29 9.25 45.31 C9.27 43.09 9.27 43.09 8.88 40.69 C8.76 39.87 8.65 39.05 8.54 38.21 C8.44 37.58 8.35 36.96 8.25 36.31 C7.68 36.19 7.11 36.08 6.53 35.95 C-2.74 33.35 -8.83 27.16 -13.73 19.18 C-15.91 15.17 -16.22 11.81 -15.75 7.31 C-11.02 1.56 -7.25 -0.03 0 0 Z " fill="#DFDFDF" transform="translate(117.75,80.6875)"></path>`
};
// ==================== 工具函数 ====================
const utils = {
log(message) {
try {
// 清理过期的日志缓存
cleanExpiredLogCache();
// 检查是否在冷却期内
const now = Date.now();
const lastLogTime = logCache.get(message);
if (lastLogTime && (now - lastLogTime < CONFIG.logCooldown)) {
// 相同日志在30秒内已输出过,跳过
return;
}
// 输出日志并更新缓存
console.log(`%c[洛谷增强工具] ${message}`, `color: ${CONFIG.logColor}`);
logCache.set(message, now);
} catch {
console.log(`[洛谷增强工具] ${message}`);
}
},
elementContainsText(element, text) {
return element?.textContent?.trim().includes(text) || false;
},
replaceDomainInUrl(url) {
if (!url) return '';
let newUrl = url;
CONFIG.oldDomains.forEach(oldDomain => {
const regex1 = new RegExp(`https://www.${oldDomain}`, 'gi');
const regex2 = new RegExp(`https://${oldDomain}`, 'gi');
newUrl = newUrl.replace(regex1, `https://www.${CONFIG.newDomain}`)
.replace(regex2, `https://${CONFIG.newDomain}`);
});
return newUrl;
},
createElement(tag, attributes = {}, innerHTML = '') {
const element = document.createElement(tag);
Object.entries(attributes).forEach(([key, value]) => {
if (value !== null && value !== undefined) {
element.setAttribute(key, value);
}
});
if (innerHTML) element.innerHTML = innerHTML;
return element;
},
insertAfter(newNode, referenceNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}
};
// ==================== 页面检查函数 ====================
const pageChecks = {
isSecurityPage() {
const pathname = window.location.pathname.toLowerCase();
return CONFIG.securityPathKeywords.some(keyword => pathname.includes(`/${keyword}/`));
},
isUserProfilePage() {
const pathParts = window.location.pathname.toLowerCase().split('/').filter(Boolean);
return pathParts.includes(CONFIG.userProfilePath);
},
isHomeTabSelected() {
const pathParts = window.location.pathname.toLowerCase()
.replace(/^\/|\/$/g, '')
.split('/')
.filter(Boolean);
return pathParts.length === 2 &&
pathParts[0] === CONFIG.userProfilePath &&
/^\d+$/.test(pathParts[1]);
},
isAdmin() {
const userInfoRows = document.querySelectorAll('.l-flex-info-row');
for (const row of userInfoRows) {
const label = row.querySelector('span');
if (label && utils.elementContainsText(label, '用户类型')) {
const value = row.querySelector('.right');
return value && utils.elementContainsText(value, '管理员');
}
}
return false;
},
isOwnProfile() {
const targetTitles = ['个人介绍', '个人介绍(仅国际站可见)', '编辑个人介绍(仅国际站可见)'];
const headers = document.querySelectorAll('div[data-v-f4fefeb2].header');
for (const header of headers) {
const title = header.querySelector('h3[data-v-f4fefeb2]');
if (!title || !targetTitles.includes(title.textContent.trim())) continue;
const buttonContainer = header.querySelector('span[data-v-f4fefeb2].edit-button');
if (!buttonContainer) continue;
const buttons = buttonContainer.querySelectorAll('button[data-v-505b6a97][data-v-f4fefeb2]');
const buttonTexts = Array.from(buttons).map(btn => btn.textContent.trim());
const hasEditButtons = buttonTexts.some(text => ['编辑', '保存', '取消'].includes(text));
if (hasEditButtons) {
utils.log('判定为自己的主页');
return true;
}
}
return false;
},
hasModifiedProfile() {
const buttons = document.querySelectorAll('button[data-v-505b6a97][data-v-f4fefeb2]');
return Array.from(buttons).some(btn => utils.elementContainsText(btn, '在保存站打开'));
}
};
// ==================== 功能函数 ====================
const functions = {
addGlobalSaveLink() {
if (state.saveLinkAdded) return;
const linkContainer = document.querySelector('div[data-v-1d35343d].link-container');
if (!linkContainer) {
utils.log("未找到头部link-container容器,暂不添加保存站链接");
return;
}
if (linkContainer.querySelector('a[href*="luogu.me"]')) {
utils.log("保存站链接已存在,无需重复添加");
state.saveLinkAdded = true;
return;
}
const saveLink = utils.createElement('a', {
'data-v-0640126c': '',
'data-v-1d35343d': '',
'href': '//luogu.me',
'target': '_blank',
'colorscheme': 'none',
'class': 'header-link color-none'
}, '洛谷保存站');
const helperElem = linkContainer.querySelector('span.helper');
if (helperElem) {
linkContainer.insertBefore(saveLink, helperElem);
} else {
linkContainer.appendChild(saveLink);
}
utils.log('全局保存站链接添加成功');
state.saveLinkAdded = true;
},
addSidebarSaveLink() {
if (state.sidebarSaveLinkAdded) return;
const navGroup = document.querySelector('div[data-v-a119941e].nav-group');
if (!navGroup) {
utils.log("未找到侧边栏nav-group容器");
return;
}
const recordItem = Array.from(navGroup.querySelectorAll('li[data-v-40281d0d][data-v-a119941e]')).find(li =>
li.getAttribute('title') === '评测记录' || utils.elementContainsText(li, '评测记录')
);
if (!recordItem) {
utils.log("未找到评测记录项");
return;
}
if (navGroup.querySelector('li[title="洛谷保存站"]')) {
utils.log("侧边栏保存站链接已存在");
state.sidebarSaveLinkAdded = true;
return;
}
const saveStationLi = utils.createElement('li', {
'data-v-40281d0d': '',
'data-v-a119941e': '',
'title': '洛谷保存站'
}, `
<a data-v-12b24cc3="" data-v-40281d0d="" href="${CONFIG.saveStationUrl}" class="" disabled="false">
<span data-v-40281d0d="" class="icon">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="23" height="23" viewBox="0 0 200 200">
${SVG_ICON.light}
</svg>
</span>
<span data-v-40281d0d="" class="title">洛谷保存站</span>
</a>
`);
utils.insertAfter(saveStationLi, recordItem);
utils.log('侧边栏保存站链接添加成功');
state.sidebarSaveLinkAdded = true;
},
addDarkSidebarSaveLink() {
if (state.darkSidebarSaveLinkAdded) return;
const darkSidebar = document.querySelector('nav[data-v-12f19ddc][data-v-d2a4e43a][data-v-7ddab1d5].lfe-body');
if (!darkSidebar) {
utils.log("未找到深色侧边栏容器");
return;
}
const columnLink = Array.from(darkSidebar.querySelectorAll('a[data-v-0640126c][data-v-639bc19b][data-v-d2a4e43a]')).find(link =>
link.getAttribute('href') === '/article' || utils.elementContainsText(link, '专栏')
);
if (!columnLink) {
utils.log("未找到专栏链接项");
return;
}
if (darkSidebar.querySelector('a[href="https://www.luogu.me/"][data-v-12f19ddc]')) {
utils.log("深色侧边栏保存站链接已存在");
state.darkSidebarSaveLinkAdded = true;
return;
}
const darkSidebarSaveLink = utils.createElement('a', {
'data-v-0640126c': '',
'data-v-639bc19b': '',
'data-v-d2a4e43a': '',
'href': CONFIG.saveStationUrl,
'colorscheme': 'none',
'class': 'color-none',
'data-v-12f19ddc': '',
'style': 'color: inherit;'
}, `
<span data-v-639bc19b="" data-v-0640126c="" class="icon">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="23" height="23" viewBox="0 0 200 200">
${SVG_ICON.dark}
</svg>
</span>
<span data-v-639bc19b="" data-v-0640126c="" class="text">保存站</span>
`);
utils.insertAfter(darkSidebarSaveLink, columnLink);
utils.log('深色侧边栏保存站链接添加成功');
state.darkSidebarSaveLinkAdded = true;
},
modifySecurityAccessLink() {
if (state.securityRetryCount >= CONFIG.retryMaxCount) {
utils.log(`安全中心链接替换达到最大重试次数(${CONFIG.retryMaxCount}),停止尝试`);
return true;
}
const goButton = document.getElementById('go');
let goButtonLink = goButton?.closest('a');
if (!goButtonLink) {
const targetButton = Array.from(document.querySelectorAll('button')).find(btn =>
utils.elementContainsText(btn, '继续访问') || utils.elementContainsText(btn, '访问')
);
goButtonLink = targetButton?.closest('a');
}
if (!goButtonLink?.href) {
state.securityRetryCount++;
utils.log(`安全中心: 未找到有效链接,将进行第${state.securityRetryCount}次重试`);
return false;
}
const originalUrl = goButtonLink.href;
const newUrl = utils.replaceDomainInUrl(originalUrl);
if (newUrl === originalUrl) {
utils.log(`安全中心: 域名替换失败,原URL: ${originalUrl}`);
state.securityRetryCount++;
return false;
}
if (goButtonLink.href === newUrl) {
utils.log(`安全中心: 链接已替换为保存站地址: ${newUrl}`);
return true;
}
// 强制替换链接
goButtonLink.href = newUrl;
goButtonLink.setAttribute('href', newUrl);
// 修改按钮文本
const button = goButton || goButtonLink.querySelector('button');
if (button) button.textContent = '通过保存站访问';
// 修改URL显示文本
let urlDisplay = document.getElementById('url');
if (!urlDisplay) {
urlDisplay = Array.from(document.querySelectorAll('p')).find(p =>
utils.elementContainsText(p, '将访问以下链接') || utils.elementContainsText(p, '访问地址')
);
}
if (urlDisplay) urlDisplay.textContent = newUrl;
// 修改提示文本
const tipParagraph = Array.from(document.querySelectorAll('.card p')).find(p =>
utils.elementContainsText(p, '安全风险') || utils.elementContainsText(p, '风险提示')
);
if (tipParagraph) {
tipParagraph.innerHTML = `
你访问的网站可能包含未知的安全风险,如需继续访问,请点击按钮确认,并注意保护账号和隐私信息。<br>
原链接已自动替换为保存站链接。如需访问原链接请点击<a href="${originalUrl}" target="_blank" style="color: #3498db;">这里</a>。
`;
}
utils.log(`安全中心: 链接替换成功,新地址: ${newUrl}`);
return true;
},
modifyUserProfile() {
const mainContent = document.querySelector('div[data-v-754e1ea4].main');
if (!mainContent) {
utils.log('未找到主内容区域');
return;
}
let introCard = Array.from(mainContent.querySelectorAll('.l-card')).find(card => {
const header = card.querySelector('div[data-v-f4fefeb2].header');
return header?.querySelector('h3') && utils.elementContainsText(header, '个人介绍');
});
if (!introCard) {
introCard = utils.createElement('div', {
'data-v-b62e56e7': '',
'data-v-f4fefeb2': '',
'data-v-754e1ea4-s': '',
'class': 'l-card'
}, `
<div data-v-f4fefeb2="" class="header">
<h3 data-v-f4fefeb2="" style="margin: 0px;">个人介绍</h3>
<span data-v-f4fefeb2="" class="edit-button"></span>
</div>
<div data-v-f4fefeb2="" class="lfe-marked-wrap introduction">
<div class="lfe-marked"></div>
</div>
`);
mainContent.appendChild(introCard);
}
const saveStationButton = utils.createElement('button', {
'data-v-505b6a97': '',
'data-v-f4fefeb2': '',
'class': 'lform-size-small',
'type': 'button'
}, '在保存站打开');
saveStationButton.addEventListener('click', () => {
window.open(utils.replaceDomainInUrl(window.location.href), '_blank');
});
const editButtonContainer = introCard.querySelector('.edit-button');
const existingButton = editButtonContainer.querySelector('button');
if (existingButton) {
editButtonContainer.replaceChild(saveStationButton, existingButton);
} else {
editButtonContainer.appendChild(saveStationButton);
}
utils.log('个人主页修改成功');
}
};
// ==================== 主逻辑 ====================
function performCheck() {
try {
// 1. 全局添加保存站链接
functions.addGlobalSaveLink();
// 2. 侧边栏添加保存站链接
functions.addSidebarSaveLink();
// 3. 深色侧边栏添加保存站链接
functions.addDarkSidebarSaveLink();
// 4. 安全中心页面处理
if (pageChecks.isSecurityPage()) {
utils.log("检测到安全中心页面,尝试修改链接");
const replaceSuccess = functions.modifySecurityAccessLink();
if (!replaceSuccess && state.securityRetryCount < CONFIG.retryMaxCount) {
setTimeout(performCheck, 500);
return;
}
if (replaceSuccess) state.securityRetryCount = 0;
}
// 5. 个人主页处理
else if (pageChecks.isUserProfilePage() && !pageChecks.isAdmin() &&
!pageChecks.isOwnProfile() && pageChecks.isHomeTabSelected() &&
!pageChecks.hasModifiedProfile()) {
functions.modifyUserProfile();
}
setTimeout(performCheck, CONFIG.checkInterval);
} catch (e) {
utils.log(`performCheck 出错: ${e.message}`);
setTimeout(performCheck, CONFIG.checkInterval);
}
}
// ==================== 启动逻辑 ====================
function init() {
try {
utils.log("开始初始化...");
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
utils.log("DOMContentLoaded事件触发,启动检查");
performCheck();
});
} else {
utils.log("文档已加载,立即启动检查");
performCheck();
}
if (!window._luoguEnhanceStarted) {
window._luoguEnhanceStarted = true;
setTimeout(() => {
utils.log("备用启动机制触发");
performCheck();
}, 3000);
}
} catch (e) {
utils.log(`初始化出错: ${e.message}`);
setTimeout(performCheck, 1000);
}
}
init();
})();
其他
- 演示使用的图片均为未加载其他插件时的情况。
- 如果使用氧洛谷的深色模式,侧边栏新图标也能够保持和其他图标颜色一致。
- 如果使用了洛谷自定义的图标颜色,侧边栏新图标目前不会自主修改颜色。