正文
增加 83 行删除 24 行
268 行未改动全部展开269270271272273274275276114 行未改动全部展开39139239339439539639739839940040140240340440540640740840911 行未改动421422423424425426427428429122 行未改动全部展开5525535545555565575585595602 行未改动5635645655665675685695705714 行未改动57657757857958058158258318 行未改动602603604605606607608609610611612613614615616144 行未改动全部展开761762763764765766767768769770771772773143 行未改动全部展开917918919920921922923924126 行未改动全部展开10511052105310541055105610571058105995 行未改动115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119477 行未改动127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307277 行未改动全部展开1585158615871588158915901591159293 行未改动268 行未改动全部展开background: rgba(255,255,255,0.05);border-color: #30363d;}}`;// ---------- 工具函数 ----------function getUserIdFromUrl() {114 行未改动全部展开}function addShikiCopyButtons(doc) {if (!doc || !doc.body) return;const shikiBlocks = doc.querySelectorAll('pre.shiki');shikiBlocks.forEach(pre => {if (pre.parentElement && pre.parentElement.classList.contains('shiki-wrapper')) return;const wrapper = doc.createElement('div');wrapper.className = 'shiki-wrapper';pre.parentNode.insertBefore(wrapper, pre);wrapper.appendChild(pre);const btn = doc.createElement('button');btn.className = 'shiki-copy-btn';btn.textContent = '复制';btn.addEventListener('click', () => {const code = pre.textContent || '';navigator.clipboard.writeText(code).then(() => {btn.textContent = '已复制';setTimeout(() => { btn.textContent = '复制'; }, 2000);11 行未改动});});wrapper.appendChild(btn);});console.log('[LGSinLG] 代码块复制按钮已添加');}// ---------- 个人介绍卡片 ----------const CARD_ID = 'lgsinlg-intro-card';122 行未改动全部展开if (isAdminUser()) { removeUserCardIfExists(); return; }const elements = getOrCreateCard(uid);if (!elements) {// 容器尚未就绪,延迟 300ms 后重试(最多尝试 10 次)if (!fetchAndUpdateCard._retryCount) fetchAndUpdateCard._retryCount = 0;if (fetchAndUpdateCard._retryCount < 10) {fetchAndUpdateCard._retryCount++;setTimeout(() => fetchAndUpdateCard(uid), 300);2 行未改动fetchAndUpdateCard._retryCount = 0;}return;}fetchAndUpdateCard._retryCount = 0; // 成功时重置计数elements.contentDiv.innerHTML = '加载中...';GM_xmlhttpRequest({method: 'GET',4 行未改动if (data.code === 200 && data.data) {const intro = data.data.renderedIntroduction || '<p>暂无个人介绍</p>';elements.contentDiv.innerHTML = intro;constrainImages(elements.contentDiv);} else {elements.contentDiv.innerHTML = '<p>获取简介失败</p>';}} catch (e) {18 行未改动const data = JSON.parse(res.responseText);if (data.code === 200) {GM_xmlhttpRequest({method: 'GET',url: `https://api.luogu.me/user/${uid}`,onload: function(resp) {try {const p = JSON.parse(resp.responseText);if (p.code === 200 && p.data) {contentDiv.innerHTML = p.data.renderedIntroduction || '<p>暂无个人介绍</p>';constrainImages(contentDiv);} else {contentDiv.innerHTML = '<p>获取简介失败</p>';}} catch (e) {144 行未改动全部展开if (!markedDiv || !timeCaption || !actionsDiv) return false;markedDiv.innerHTML = pasteData.renderedContent || '<p>暂无内容</p>';constrainImages(markedDiv);forceExternalLinks(markedDiv);// 移除所有内部锚点链接(href 以 # 开头)const internalAnchors = markedDiv.querySelectorAll('a[href^="#"]');internalAnchors.forEach(a => {a.replaceWith(document.createTextNode(a.textContent));});injectShikiCSS(doc);const authorCaption = doc.querySelector('.author .lfe-caption.author-margin');if (authorCaption) {const color = USER_CONFIG.colorMap[pasteData.author.color] || '#000';143 行未改动全部展开if (titleEl) { titleEl.textContent = articleData.title; if (doc.title) doc.title = articleData.title; }contentDiv.innerHTML = articleData.renderedContent || '<p>暂无内容</p>';constrainImages(contentDiv);forceExternalLinks(contentDiv);const headingAnchors = contentDiv.querySelectorAll('a.heading-anchor');headingAnchors.forEach(a => a.remove());injectShikiCSS(doc);const headings = contentDiv.querySelectorAll('h1, h2, h3, h4, h5, h6');126 行未改动全部展开document.getElementById('lgsinlg-loading').style.display = 'none';iframe.style.display = '';window.__LGSinLG_active = true;console.log('[LGSinLG] 文章接管完成');// 评论区接管setupComments(doc, articleId);}} catch (e) {clearInterval(interval);95 行未改动const commentContainer = doc.querySelector('.article-comment');if (!commentContainer || commentContainer.dataset.lgsProcessed) return;commentContainer.dataset.lgsProcessed = 'true';// ---------- 禁用排序下拉 ----------const sortWrapper = commentContainer.querySelector('.combo-wrapper');if (sortWrapper) {sortWrapper.style.pointerEvents = 'none';sortWrapper.style.opacity = '0.5';sortWrapper.title = '评论区已接管,排序不可用';}// ---------- 精确禁用评论输入框(通过 textarea 向上查找父容器) ----------const textarea = commentContainer.querySelector('textarea');if (textarea) {const replyForm = textarea.closest('.l-card')|| textarea.closest('form')|| textarea.closest('.reply-box')|| textarea.closest('.comment-editor');if (replyForm) {replyForm.style.pointerEvents = 'none';replyForm.style.opacity = '0.5';replyForm.title = '评论区已由脚本接管,暂不支持发表';}}// 移除原生加载更多(初次尝试)const nativeLoadMoreLink = commentContainer.querySelector('p[style*="text-align: center"] a[href="javascript:void 0"]');if (nativeLoadMoreLink && nativeLoadMoreLink.parentElement) {nativeLoadMoreLink.parentElement.remove();}const rowWrap = commentContainer.querySelector('.row-wrap');if (!rowWrap) return;// 初始化函数(需要 articleId)const doInit = (templateRow) => {rowWrap.innerHTML = '';const countSpan = commentContainer.querySelector('.comment-filter-line span[style*="flex"]');77 行未改动wrapper.appendChild(loadMoreBtn);commentContainer.appendChild(wrapper);}// 初始加载fetchReplies(articleId).then(replies => {appendReplies(replies);}).catch(err => {console.error('[LGSinLG] 初始评论加载失败', err);if (countSpan) countSpan.textContent = '评论加载失败,点击刷新重试';});// ----- 持续监听并移除后出现的原生“加载更多”按钮 -----const nativeCleaner = new MutationObserver(() => {const nativeLink = commentContainer.querySelector('p[style*="text-align: center"] a[href="javascript:void 0"]');if (nativeLink && nativeLink.parentElement) {console.log('[LGSinLG] 移除后出现的原生加载更多按钮');nativeLink.parentElement.remove();}});nativeCleaner.observe(commentContainer, { childList: true, subtree: true });// -------------------------------------------------------};// 尝试立即获取模板const templateRow = rowWrap.querySelector('.row');if (templateRow) {doInit(templateRow);return;}// 否则观察 rowWrap,等待懒加载完成(不设超时)const observer = new MutationObserver((mutations, obs) => {const row = rowWrap.querySelector('.row');if (row) {obs.disconnect();277 行未改动全部展开console.log('[LGSinLG] 自己的主页,跳过卡片');removeUserCardIfExists();return;}if (!document.querySelector('.sidebar-container > .main')) {setTimeout(() => processRoute(), 300);return;}93 行未改动268 行未改动全部展开269270271272273274275276277278279280281282283284285286287288289290291292293114 行未改动全部展开40840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846911 行未改动481482483484485486487488489122 行未改动全部展开6126136146156166176186192 行未改动6226236246256266276286296304 行未改动63563663763863964064164264364464518 行未改动664665666667668669670671672673674675676677678679680681144 行未改动全部展开826827828829830831832833834835836143 行未改动全部展开980981982983984985986987988126 行未改动全部展开1115111611171118111911201121112295 行未改动12181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125677 行未改动13341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365277 行未改动全部展开16431644164516461647164816491650165193 行未改动268 行未改动全部展开background: rgba(255,255,255,0.05);border-color: #30363d;}}/* 行号边距微调 */.shiki .line {display: block;padding-left: 3.5em; /* 为行号留出固定空间,原来的 ::before 用了 2em + margin-right 1em,这里再加一点内边距 */text-indent: -3.5em; /* 让行号向左突出,保持代码对齐 */}/* 深色模式下普通 pre 的补充 */pre:not(.shiki) {background-color: #f6f8fa !important;border-color: #d0d7de;}@media (prefers-color-scheme: dark) {pre:not(.shiki) {background-color: #0d1117 !important;border-color: #30363d;}}`;// ---------- 工具函数 ----------function getUserIdFromUrl() {114 行未改动全部展开}function addShikiCopyButtons(doc) {if (!doc || !doc.body) return;const allPres = doc.querySelectorAll('pre');allPres.forEach(pre => {// 已处理过则跳过if (pre.dataset.lgsCopyProcessed) return;pre.dataset.lgsCopyProcessed = 'true';// 如果 pre 中还没有 .line 结构(即非 Shiki 渲染),则为其生成行号结构if (!pre.querySelector('.line') && !pre.classList.contains('shiki')) {// 获取纯文本(保留换行)const text = pre.textContent || '';const lines = text.split('\n');// 清空 pre 内容pre.innerHTML = '';lines.forEach((line, i) => {const span = doc.createElement('span');span.className = 'line';span.textContent = line;pre.appendChild(span);// 除了最后一行,插入换行节点,模拟原始换行if (i < lines.length - 1) {pre.appendChild(doc.createTextNode('\n'));}});// 添加 .shiki 类,复用已写好的行号 CSS(.shiki .line::before)pre.classList.add('shiki');}// 避免重复包裹if (pre.parentElement && pre.parentElement.classList.contains('shiki-wrapper')) return;// 包裹 wrapper 并添加按钮const wrapper = doc.createElement('div');wrapper.className = 'shiki-wrapper';pre.parentNode.insertBefore(wrapper, pre);wrapper.appendChild(pre);// 如果 pre 没有 .shiki 类(极少情况),补充基础样式if (!pre.classList.contains('shiki')) {pre.style.padding = '16px';pre.style.borderRadius = '8px';pre.style.border = '1px solid #d0d7de';pre.style.backgroundColor = '#f6f8fa';pre.style.overflowX = 'auto';pre.style.fontFamily = '"SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace';pre.style.fontSize = '13px';pre.style.lineHeight = '1.5';pre.style.margin = '1em 0';}const btn = doc.createElement('button');btn.className = 'shiki-copy-btn';btn.textContent = '复制';btn.addEventListener('click', () => {// 复制时只取纯文本,自动忽略行号(伪元素)const code = pre.textContent || '';navigator.clipboard.writeText(code).then(() => {btn.textContent = '已复制';setTimeout(() => { btn.textContent = '复制'; }, 2000);11 行未改动});});wrapper.appendChild(btn);});console.log('[LGSinLG] 代码块复制按钮已添加(含行号适配)');}// ---------- 个人介绍卡片 ----------const CARD_ID = 'lgsinlg-intro-card';122 行未改动全部展开if (isAdminUser()) { removeUserCardIfExists(); return; }const elements = getOrCreateCard(uid);if (!elements) {if (!fetchAndUpdateCard._retryCount) fetchAndUpdateCard._retryCount = 0;if (fetchAndUpdateCard._retryCount < 10) {fetchAndUpdateCard._retryCount++;setTimeout(() => fetchAndUpdateCard(uid), 300);2 行未改动fetchAndUpdateCard._retryCount = 0;}return;}fetchAndUpdateCard._retryCount = 0;elements.contentDiv.innerHTML = '加载中...';GM_xmlhttpRequest({method: 'GET',4 行未改动if (data.code === 200 && data.data) {const intro = data.data.renderedIntroduction || '<p>暂无个人介绍</p>';elements.contentDiv.innerHTML = intro;constrainImages(elements.contentDiv);// 移除 heading-anchor 锚点const headingAnchors = elements.contentDiv.querySelectorAll('a.heading-anchor');headingAnchors.forEach(a => a.remove());} else {elements.contentDiv.innerHTML = '<p>获取简介失败</p>';}} catch (e) {18 行未改动const data = JSON.parse(res.responseText);if (data.code === 200) {GM_xmlhttpRequest({method: 'GET',url: `https://api.luogu.me/user/query/${uid}`,onload: function(resp) {try {const p = JSON.parse(resp.responseText);if (p.code === 200 && p.data) {contentDiv.innerHTML = p.data.renderedIntroduction || '<p>暂无个人介绍</p>';constrainImages(contentDiv);// 刷新后同样移除 heading-anchorconst headingAnchors = contentDiv.querySelectorAll('a.heading-anchor');headingAnchors.forEach(a => a.remove());} else {contentDiv.innerHTML = '<p>获取简介失败</p>';}} catch (e) {144 行未改动全部展开if (!markedDiv || !timeCaption || !actionsDiv) return false;markedDiv.innerHTML = pasteData.renderedContent || '<p>暂无内容</p>';constrainImages(markedDiv);forceExternalLinks(markedDiv);// 移除 heading-anchor 锚点const headingAnchors = markedDiv.querySelectorAll('a.heading-anchor');headingAnchors.forEach(a => a.remove());injectShikiCSS(doc);const authorCaption = doc.querySelector('.author .lfe-caption.author-margin');if (authorCaption) {const color = USER_CONFIG.colorMap[pasteData.author.color] || '#000';143 行未改动全部展开if (titleEl) { titleEl.textContent = articleData.title; if (doc.title) doc.title = articleData.title; }contentDiv.innerHTML = articleData.renderedContent || '<p>暂无内容</p>';constrainImages(contentDiv);forceExternalLinks(contentDiv);// 移除 heading-anchor 锚点(文章接管中保留原有处理)const headingAnchors = contentDiv.querySelectorAll('a.heading-anchor');headingAnchors.forEach(a => a.remove());injectShikiCSS(doc);const headings = contentDiv.querySelectorAll('h1, h2, h3, h4, h5, h6');126 行未改动全部展开document.getElementById('lgsinlg-loading').style.display = 'none';iframe.style.display = '';window.__LGSinLG_active = true;console.log('[LGSinLG] 文章接管完成');setupComments(doc, articleId);}} catch (e) {clearInterval(interval);95 行未改动const commentContainer = doc.querySelector('.article-comment');if (!commentContainer || commentContainer.dataset.lgsProcessed) return;commentContainer.dataset.lgsProcessed = 'true';// 禁用排序下拉const sortWrapper = commentContainer.querySelector('.combo-wrapper');if (sortWrapper) {sortWrapper.style.pointerEvents = 'none';sortWrapper.style.opacity = '0.5';sortWrapper.title = '评论区已接管,排序不可用';}// 禁用评论输入区域const textarea = commentContainer.querySelector('textarea');if (textarea) {const replyForm = textarea.closest('.l-card')|| textarea.closest('form')|| textarea.closest('.reply-box')|| textarea.closest('.comment-editor');if (replyForm) {replyForm.style.pointerEvents = 'none';replyForm.style.opacity = '0.5';replyForm.title = '评论区已由脚本接管,暂不支持发表';}}// 尝试移除原生加载更多(可能此时还未渲染)const nativeLoadMoreLink = commentContainer.querySelector('p[style*="text-align: center"] a[href="javascript:void 0"]');if (nativeLoadMoreLink && nativeLoadMoreLink.parentElement) {nativeLoadMoreLink.parentElement.remove();}const rowWrap = commentContainer.querySelector('.row-wrap');if (!rowWrap) return;const doInit = (templateRow) => {rowWrap.innerHTML = '';const countSpan = commentContainer.querySelector('.comment-filter-line span[style*="flex"]');77 行未改动wrapper.appendChild(loadMoreBtn);commentContainer.appendChild(wrapper);}fetchReplies(articleId).then(replies => {appendReplies(replies);}).catch(err => {console.error('[LGSinLG] 初始评论加载失败', err);if (countSpan) countSpan.textContent = '评论加载失败,点击刷新重试';});// 持续监听并移除后出现的原生“加载更多”按钮const nativeCleaner = new MutationObserver(() => {const nativeLink = commentContainer.querySelector('p[style*="text-align: center"] a[href="javascript:void 0"]');if (nativeLink && nativeLink.parentElement) {console.log('[LGSinLG] 移除后出现的原生加载更多按钮');nativeLink.parentElement.remove();}});nativeCleaner.observe(commentContainer, { childList: true, subtree: true });};const templateRow = rowWrap.querySelector('.row');if (templateRow) {doInit(templateRow);return;}const observer = new MutationObserver((mutations, obs) => {const row = rowWrap.querySelector('.row');if (row) {obs.disconnect();277 行未改动全部展开console.log('[LGSinLG] 自己的主页,跳过卡片');removeUserCardIfExists();return;}// 等待侧边栏容器就绪,否则稍后再试if (!document.querySelector('.sidebar-container > .main')) {setTimeout(() => processRoute(), 300);return;}93 行未改动