cf shortest codes

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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

})();