版本比较
Luogu-to-Vjudge:一键跳转 VJudge 脚本
标题
增加 1 行删除 1 行
11Luogu-to-Vjudge:平替 RMJ 刷题效率神器Luogu-to-Vjudge:一键跳转 VJudge 脚本正文
增加 75 行删除 65 行
1234545678910910111112131413151615171819201921222324256 行未改动3233343534363738394041424342444546474847495049505152535455565758596059606162636263646566676566676869707172737475767778798081828384858687888990919293949596697071727374757677787980818283848586878889909197939498991001019610210310410510698991001071081091101111121131141151161021031041051061071081091171181191111121201211221231141151161171181191241251261271281291301311321338 行未改动# 一键跳转 VJudge 脚本
> 新版同步于 [GitHub 仓库](https://github.com/Justskr/Luogu-to-Vjudge),可以去 Star 一下。> > 保命声明:完全开源免费,拒绝商业化。仅供学术研究,严禁用于一切非正当行为。>> 保命声明:完全开源免费,拒绝商业化。仅供学术研究,严禁用于一切非正当行为。脚本使用了 AI 辅助制作,本文章仅作为分享,希望可以优化各位的做题体验。>> 2025-11-24 upt:更新了脚本源码,修复了一些跳转bug。重新提交审核,感谢管理员。
## 脚本简介
**洛谷** 和 **VJudge** 是两大高频使用的平台: - 洛谷题量丰富、社区活跃; - VJudge 支持多平台题目聚合、组队训练。 **洛谷** 和 **VJudge** 是两大高频使用的平台:- 洛谷题量丰富、社区活跃;- VJudge 支持多平台题目聚合、组队训练。
二者结合能大幅提升刷题效率。 二者结合能大幅提升刷题效率。
随着洛谷 RMJ 下线,刷其他 OJ 的题目不再方便,而 VJudge 仍可提交 CF、AT、SPOJ 等题目,自由度较高。于是就有了这个脚本(网上旧脚本因洛谷新版 UI 已失效)。优点如下:随着洛谷 RMJ 下线,刷其他 OJ 的题目不再方便,而 VJudge 仍可提交 CF、AT、SPOJ 等题目,自由度较高。于是就有了这个脚本(网上旧脚本因洛谷新版 UI 已失效)。
### 方便快捷
手动在两个平台间切换、查找对应编号耗时费力。 手动在两个平台间切换、查找对应编号耗时费力。**「洛谷一键跳转 VJudge」** 脚本适配洛谷新版 UI,支持 **CF / SPOJ / AtCoder / UVA** 四大平台题目一键跳转,自动识别题目编号并拼接 VJudge 链接,让跨平台刷题一步到位。
### 美观大气
6 行未改动## 使用指南
### 步骤 1:安装脚本管理器
在浏览器扩展商店搜索并安装 **Tampermonkey** 或 **Violentmonkey**。 在浏览器扩展商店搜索并安装 **Tampermonkey** 或 **Violentmonkey**。
相信很多人都喜欢用脚本优化做题体验。比如我:

### 步骤 2:添加脚本
1. 打开 [GitHub 仓库](https://github.com/Justskr/Luogu-to-Vjudge) 下载源文件,脚本管理器会自动接管安装; 1. 打开 [GitHub 仓库](https://github.com/Justskr/Luogu-to-Vjudge) 下载源文件,脚本管理器会自动接管安装;2. 若未自动安装,可在脚本管理器内「新建用户脚本」,粘贴以下内容后保存:
```javascript// ==UserScript==// @name 洛谷 RMJ 一键跳转 VJudge// @name 洛谷rmj一键跳转VJudge// @namespace http://tampermonkey.net/// @version 3.0// @description 支持洛谷 CF / SPOJ / AtCoder / UVA 题目跳转 VJudge,自动匹配各平台链接格式// @version 3.1// @description 支持洛谷CF/SPOJ/AtCoder/UVA题目跳转VJudge,修复CF带数字后缀的编号匹配// @author Justskr// @match https://www.luogu.com.cn/problem/CF*// @match https://www.luogu.com.cn/problem/SP*// @match https://www.luogu.com.cn/problem/AT*// @match https://www.luogu.com.cn/problem/UVA*// @grant none// ==/UserScript==
(function () { 'use strict';(function() { 'use strict';
function getVjudgeUrl() { const path = location.pathname; function getVjudgeUrl() { const luoguUrl = window.location.href; const luoguPath = window.location.pathname;
if (path.startsWith('/problem/AT_')) { const m = path.match(/AT_(\w+)/); return m ? `https://vjudge.net/problem/AtCoder-${m[1]}` : null; if (luoguPath.startsWith('/problem/AT_')) { const atMatch = luoguPath.match(/AT_(\w+)/); return atMatch ? `https://vjudge.net/problem/AtCoder-${atMatch[1]}` : null; } else if (luoguPath.startsWith('/problem/UVA')) { const uvaMatch = luoguPath.match(/UVA(\d+)/); return uvaMatch ? `https://vjudge.net/problem/UVA-${uvaMatch[1]}` : null; } else if (luoguPath.startsWith('/problem/CF')) { // 修复CF编号匹配 const cfMatch = luoguPath.match(/CF(\d+[A-Za-z\d]*)/); return cfMatch ? `https://vjudge.net/problem/CodeForces-${cfMatch[1]}` : null; } else if (luoguPath.startsWith('/problem/SP')) { let spojId = null; const originalLink = document.querySelector('a[href*="spoj.com/problems/"]'); if (originalLink) { spojId = originalLink.href.split('/problems/')[1].replace('/', ''); } else { const pageText = document.body.innerText; const spojTextMatch = pageText.match(/SPOJ\s*[-\s:]([A-Za-z0-9_-]+)/i); spojId = spojTextMatch ? spojTextMatch[1].trim() : null; } return spojId ? `https://vjudge.net/problem/SPOJ-${spojId}` : null; }
return null; } if (path.startsWith('/problem/UVA')) { const m = path.match(/UVA(\d+)/); return m ? `https://vjudge.net/problem/UVA-${m[1]}` : null; } if (path.startsWith('/problem/CF')) { const m = path.match(/CF(\d+[A-Za-z]*)/); return m ? `https://vjudge.net/problem/CodeForces-${m[1]}` : null; } if (path.startsWith('/problem/SP')) { // 优先抓取页面中的 spoj.com/problems/ 链接 const link = document.querySelector('a[href*="spoj.com/problems/"]'); if (link) { const id = link.href.split('/problems/')[1].replace(/\/$/, ''); return `https://vjudge.net/problem/SPOJ-${id}`; } // 兜底:从正文文本匹配 const text = document.body.innerText; const m = text.match(/SPOJ\s*[-:\s]([A-Za-z0-9_-]+)/i); if (m) return `https://vjudge.net/problem/SPOJ-${m[1].trim()}`; return null; } return null; }
const copyBtn = [...document.querySelectorAll('button')] .find(btn => btn.textContent.trim() === '复制题目'); const copyBtn = Array.from(document.querySelectorAll('button')).find( btn => btn.innerText.trim() === '复制题目' );
const vjudgeUrl = getVjudgeUrl(); const vjudgeUrl = getVjudgeUrl(); if (copyBtn && vjudgeUrl) { const jumpBtn = document.createElement('button'); jumpBtn.innerText = '跳转VJudge';
if (copyBtn && vjudgeUrl) { const jumpBtn = document.createElement('button'); jumpBtn.textContent = '跳转 VJudge'; const copyStyles = window.getComputedStyle(copyBtn); [ 'backgroundColor', 'color', 'border', 'borderRadius', 'padding', 'fontSize', 'fontFamily', 'cursor', 'height', 'lineHeight', 'textAlign', 'whiteSpace', 'verticalAlign', 'display', 'marginTop', 'marginBottom' ].forEach(styleProp => { jumpBtn.style[styleProp] = copyStyles[styleProp]; });
// 复制样式 const cs = getComputedStyle(copyBtn); [ 'backgroundColor', 'color', 'border', 'borderRadius', 'padding', 'fontSize', 'fontFamily', 'cursor', 'height', 'lineHeight', 'textAlign', 'whiteSpace', 'verticalAlign', 'display', 'marginTop', 'marginBottom' ].forEach(k => jumpBtn.style[k] = cs[k]); jumpBtn.style.marginLeft = '5px'; jumpBtn.style.minWidth = copyStyles.minWidth || '80px';
jumpBtn.style.marginLeft = '6px'; jumpBtn.style.minWidth = cs.minWidth || '80px'; jumpBtn.addEventListener('click', () => { window.open(vjudgeUrl, '_blank'); });
jumpBtn.addEventListener('click', () => window.open(vjudgeUrl, '_blank')); copyBtn.parentNode.insertBefore(jumpBtn, copyBtn.nextSibling); } else if (!vjudgeUrl) { const pf = location.pathname.match(/\/problem\/(\w+)/)?.[1].slice(0, 2) || '??'; console.warn(`[Luogu2VJ] 未识别到有效题目标识符(平台:${pf})`); } copyBtn.parentNode.insertBefore(jumpBtn, copyBtn.nextSibling); } else if (!vjudgeUrl) { const platform = luoguPath.match(/\/problem\/(\w+)/)[1].slice(0, 2); console.warn(`洛谷${platform}题目跳转VJudge:未找到有效题目标识符,请检查页面格式`); }})();```
### 步骤 3:一键跳转,即刻体验8 行未改动