cf shortest codes

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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

})();