版本比较
在洛谷内无缝访问所有文章
正文
增加 17 行删除 3 行
54 行未改动5556575859605960616263643 行未改动6869707172727374757651 行未改动128129130131132133134135136137138139140141142143144145170 行未改动全部展开31631731831932032132232332426 行未改动351352353354355356357358359148 行未改动全部展开508509510511512513514515516155 行未改动全部展开672673674675676677678679680558 行未改动全部展开54 行未改动```javascript// ==UserScript==// @name LGSinLG// @namespace https://www.luogu.com.cn/user/1816684// @version 1.0.4// @description 洛谷国内站:用户主页添加个人介绍卡片;陌生剪切板/文章通过 iframe + API 替换内容,支持 CP OAuth 自动登录和工作流更新;修复多实例刷新问题;替换文章分类、点赞收藏数(纯数字)并禁止交互;支持多操作栏;动态替换右侧目录(保留原生样式);修复加载卡死和跨域自动刷新;iframe 内非锚点链接在顶层跳转;修复 heading-anchor 锚点;安全页超时放弃接管,不再刷新;修改页面标题格式;头像链接放行保留抽屉菜单;修复时间显示为本地时间;使用全局事件委托彻底解决编辑按钮跳转;主页更新按钮宽度自适应;恢复点赞收藏数及禁用交互功能;检测自己主页不再追加个人介绍卡片;修复浏览器返回后页面不更新的问题;修复 getLoginUid 选择器以适配新版导航栏;修复未保存文章/剪切板时页面卡死在加载中,增加“保存”按钮,修复后退与重试// @version 1.0.5// @description 洛谷国内站:用户主页添加个人介绍卡片;陌生剪切板/文章通过 iframe + API 替换内容,支持 CP OAuth 自动登录和工作流更新;修复多实例刷新问题;替换文章分类、点赞收藏数(纯数字)并禁止交互;支持多操作栏;动态替换右侧目录(保留原生样式);修复加载卡死和跨域自动刷新;iframe 内非锚点链接在顶层跳转;修复 heading-anchor 锚点;安全页超时放弃接管,不再刷新;修改页面标题格式;头像链接放行保留抽屉菜单;修复时间显示为本地时间;使用全局事件委托彻底解决编辑按钮跳转;主页更新按钮宽度自适应;恢复点赞收藏数及禁用交互功能;检测自己主页不再追加个人介绍卡片;修复浏览器返回后页面不更新的问题;修复 getLoginUid 选择器以适配新版导航栏;修复未保存文章/剪切板时页面卡死在加载中,增加“保存”按钮,修复后退与重试;修复图片宽度溢出问题// @author https://www.luogu.com.cn/user/1816684// @match *://*.luogu.com.cn/*// @match *://*.luogu.me/*// @grant GM_xmlhttpRequest3 行未改动
(function() { 'use strict';
console.log('[LGSinLG] 脚本启动,版本 1.0.4', new Date().toISOString()); console.log('[LGSinLG] 脚本启动,版本 1.0.5', new Date().toISOString());
window.addEventListener('unhandledrejection', function(event) { console.error('[LGSinLG] 未捕获的 Promise 拒绝:', event.reason); console.error('[LGSinLG] 当前 URL:', location.href);51 行未改动 const pad = n => String(n).padStart(2, '0'); return `${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`; }
// 限制容器内所有图片的宽度,防止溢出 function constrainImages(container) { if (!container) return; const imgs = container.querySelectorAll('img'); imgs.forEach(img => { img.style.maxWidth = '100%'; img.style.height = 'auto'; }); }
function forceExternalLinks(container) { if (!container) return; const links = container.querySelectorAll('a'); links.forEach(a => {170 行未改动全部展开 const data = JSON.parse(res.responseText); 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) {26 行未改动 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) {148 行未改动全部展开 const timeCaption = doc.querySelector('.content-card-top .author .lfe-caption:not(.author-margin)'); const actionsDiv = doc.querySelector('.actions'); if (!markedDiv || !timeCaption || !actionsDiv) return false; markedDiv.innerHTML = pasteData.renderedContent || '<p>暂无内容</p>'; constrainImages(markedDiv); forceExternalLinks(markedDiv); const authorCaption = doc.querySelector('.author .lfe-caption.author-margin'); if (authorCaption) { const color = USER_CONFIG.colorMap[pasteData.author.color] || '#000';155 行未改动全部展开 const updateInfo = doc.querySelector('.update-info'); if (!contentDiv) return false; if (titleEl) { titleEl.textContent = articleData.title; if (doc.title) doc.title = articleData.title; } contentDiv.innerHTML = articleData.renderedContent || '<p>暂无内容</p>'; constrainImages(contentDiv); forceExternalLinks(contentDiv); const headings = contentDiv.querySelectorAll('h1, h2, h3, h4, h5, h6'); headings.forEach((heading, index) => { const newId = `lgs-toc-${index}`;558 行未改动全部展开