正文
增加 16 行删除 131 行
3 行未改动45678910111213145 行未改动20212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541553 行未改动显示个人介绍,让个人介绍从新变得有用。## 版本### 0.1.1$\texttt{2025.10.18}$显示个人介绍 Markdown 源码。### 0.1.25 行未改动$\texttt{2025.10.19}$支持大部分 md 渲染。(虽然有些和 luogu 不太一样。):::info[源码]```javascript// ==UserScript==// @name 洛谷个人介绍显示插件// @namespace http://tampermonkey.net/// @version 0.2// @description 显示洛谷个人介绍// @author liuyuhan1522// @match https://www.luogu.com.cn/user/*// @grant GM_xmlhttpRequest// @require https://cdn.jsdelivr.net/npm/marked@4.0.0/marked.min.js// @connect luogu.com.cn// ==/UserScript==(function() {'use strict';let nowurl = window.location.href;let nowurluid='';for(let i=0;i<nowurl.length;i++){if(nowurl[i]>='0'&&nowurl[i]<='9') nowurluid+=nowurl[i];}// 配置参数const CONFIG = {targetSelector: '#app > div.main-container.lside-nav > main > div > div.sidebar-container.reverse > div.main',apiUrl: 'https://www.luogu.com.cn/api/user/info/' + nowurluid,maxRetries: 5,retryInterval: 1000,divStyle: {padding: '15px',margin: '10px 0',background: '#ffffff',borderRadius: '5px',border: '1px solid #e1e4e8',fontSize: '14px',lineHeight: '2.0',color: '#24292e'}};let retryCount = 0;// 创建介绍div元素function createIntroDiv(content) {const div = document.createElement('div');div.className = 'luogu-user-intro';// 应用样式Object.assign(div.style, CONFIG.divStyle);// 使用marked.js转换Markdown为HTMLtry {div.innerHTML = marked.parse(content || '该用户暂无个人介绍');} catch (e) {console.error('Markdown转换失败:', e);div.innerHTML = content.replace(/\n/g, '<br>');}return div;}// 获取用户数据function fetchUserData() {GM_xmlhttpRequest({method: 'GET',url: CONFIG.apiUrl,headers: {'Accept': 'application/json','X-Requested-With': 'XMLHttpRequest'},onload: function(response) {try {const data = JSON.parse(response.responseText);if (data?.user?.introduction) {injectIntroDiv(data.user.introduction);} else {console.warn('API响应中未找到用户介绍内容');}} catch (e) {console.error('解析用户数据失败:', e);retryOrAbort();}},onerror: function(error) {console.error('获取用户数据失败:', error);retryOrAbort();}});}// 重试或放弃function retryOrAbort() {if (retryCount < CONFIG.maxRetries) {retryCount++;setTimeout(fetchUserData, CONFIG.retryInterval);}}// 注入介绍divfunction injectIntroDiv(content) {const targetElement = document.querySelector(CONFIG.targetSelector);if (!targetElement) {if (retryCount < CONFIG.maxRetries) {retryCount++;setTimeout(() => injectIntroDiv(content), CONFIG.retryInterval);}return;}// 检查是否已存在if (targetElement.querySelector('.luogu-user-intro')) {return;}targetElement.prepend(createIntroDiv(content));console.log('用户介绍内容已成功注入');}// 初始化function init() {if (document.readyState === 'complete') {fetchUserData();} else {document.addEventListener('DOMContentLoaded', fetchUserData);window.addEventListener('load', fetchUserData);}}init();})();```3 行未改动456789101112131415161718192021225 行未改动282930313233343536373839403 行未改动显示个人介绍,让个人介绍从新变得有用。## 源码<https://github.com/liuyuhan1522/->## 使用方法详见源码注释,以后会详细介绍。## 版本### 0.1.1$\texttt{2025.10.18}$显示个人介绍 Markdown 源码。### 0.1.25 行未改动$\texttt{2025.10.19}$支持大部分 md 渲染。(虽然有些和 luogu 不太一样。)### 0.3$\texttt{2025.10.19}$在个人介绍前添加了“个人介绍”四个字,并把一些部分改成了与 luogu 相同的样式。### 0.4$\texttt{2025.10.23}$可以不显示自己的个人介绍。