CodeChef → VJudge Redirect

从 CodeChef 题目页面自动跳转到对应的 VJudge 页面

当前为 2025-09-12 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         CodeChef → VJudge Redirect
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  从 CodeChef 题目页面自动跳转到对应的 VJudge 页面
// @author       znzryb
// @match        https://www.codechef.com/problems/*
// @grant        none
// @license GPL-3.0
// ==/UserScript==

(function() {
    'use strict';

    // 从 URL 中提取题目标识符
    const pathParts = window.location.pathname.split('/');
    // URL 格式通常是 /problems/PERMCNTEZ 或带参数中的 /problems/PERMCNTEZ?tab=statement
    const problemCode = pathParts[2];
    if (!problemCode) return;

    // 构造 VJudge 的链接
    const vjudgeUrl = `https://vjudge.net/problem/CodeChef-${problemCode}`;

    // 自动跳转(可根据需要取消注释)
    // window.location.href = vjudgeUrl;

    // 或者添加一个按钮,供用户点击跳转
    const btn = document.createElement('button');
    btn.textContent = 'Jump to VJudge';
    Object.assign(btn.style, {
        position: 'fixed',
        top: '100px',
        right: '20px',
        padding: '10px 15px',
        backgroundColor: '#28a745',
        color: '#fff',
        border: 'none',
        borderRadius: '4px',
        cursor: 'pointer',
        fontSize: '14px',
        zIndex: 10000
    });
    btn.onclick = () => window.open(vjudgeUrl, '_blank');
    document.body.appendChild(btn);
})();