CodeChef → VJudge Redirect

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

目前為 2025-09-12 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
})();