cf shortest codes

添加claude编写的快捷跳转朋友排名、c++、py最短代码的按钮。

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @license MIT
// @name         cf shortest codes
// @namespace    http://tampermonkey.net/
// @version      2024-04-02
// @description 添加claude编写的快捷跳转朋友排名、c++、py最短代码的按钮。
// @author       apxitye,claude
// @match        https://codeforces.com/*/problem/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        GM_log
// ==/UserScript==

(function() {
    'use strict';

    const url = new URL(window.location.href);
    const contestId = url.pathname.split('/').find(part => !isNaN(parseInt(part)));
    const problemId = url.pathname.split('/').pop().toUpperCase();
    //friends standings
    let Btn = document.createElement('li');
    Btn.innerHTML = `<a href="https://codeforces.com/contest/${contestId}/standings/friends/true" target="_blank">Friends Standings</a>`;
    Btn.classList.add('Btn')
    document.querySelector(".second-level-menu-list").appendChild(Btn);
    //py
    const friendBtn = document.createElement('li');
    friendBtn.innerHTML = `<a href="${url.origin}/contest/${contestId}/status/?order=BY_PROGRAM_LENGTH_ASC" target="_blank" id="shortestCodeLink">py</a>`;
    friendBtn.classList.add('friendBtn');
    document.querySelector(".second-level-menu-list").appendChild(friendBtn);

    document.getElementById('shortestCodeLink').addEventListener('click', (e) => {
        e.preventDefault();

        const newWindow = window.open(e.currentTarget.href, '_blank');
        newWindow.addEventListener('load', () => {
            const form = newWindow.document.querySelector('.status-filter');
            if (form) {
                form.querySelector('#frameProblemIndex').value = problemId;
                form.querySelector('#verdictName').value = 'OK';
                form.querySelector('#programTypeForInvoker').value = 'python.3';
                form.querySelector('#comparisonType').value = 'NOT_USED';
                form.querySelector('#participantSubstring').value = '';
                form.submit();
            }
        }, { once: true });
    });
    //c++17
    const friendBtn2 = document.createElement('li');
    friendBtn2.innerHTML = `<a href="${url.origin}/contest/${contestId}/status/?order=BY_PROGRAM_LENGTH_ASC" target="_blank" id="shortestCodeLink2">c++</a>`;
    friendBtn2.classList.add('friendBtn');
    document.querySelector(".second-level-menu-list").appendChild(friendBtn2);

    document.getElementById('shortestCodeLink2').addEventListener('click', (e) => {
        e.preventDefault();

        const newWindow = window.open(e.currentTarget.href, '_blank');
        newWindow.addEventListener('load', () => {
            const form = newWindow.document.querySelector('.status-filter');
            if (form) {
                form.querySelector('#frameProblemIndex').value = problemId;
                form.querySelector('#verdictName').value = 'OK';
                form.querySelector('#programTypeForInvoker').value = 'cpp.g++17';
                form.querySelector('#comparisonType').value = 'NOT_USED';
                form.querySelector('#participantSubstring').value = '';
                form.submit();
            }
        }, { once: true });
    });

})();