CodeChef → VJudge Redirect

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

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