CodeChef → VJudge Redirect

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

As of 2025-09-12. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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);
})();