AtCoder Beautiful Code View

AtCoderの提出コードを美しい表示にします

Stan na 01-05-2022. Zobacz najnowsza wersja.

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

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

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==
// @name    AtCoder Beautiful Code View
// @namespace    http://tampermonkey.net/
// @version    0.2
// @description    AtCoderの提出コードを美しい表示にします
// @author     Chippppp
// @license    MIT
// @match    https://atcoder.jp/contests/*/submissions/*
// @grant    none
// ==/UserScript==

"use strict";

(function() {
    // Monaco Editor in cdnjs
    // Copyright (c) 2016 - present Microsoft Corporation
    let script = document.createElement("script");
    script.src = "https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.33.0/min/vs/loader.min.js";
    document.head.prepend(script);

    let header = document.createElement("script");
    header.innerHTML = `
        document.getElementsByClassName("linenums")[0].style.display = "none";
        document.getElementsByClassName("btn-text toggle-btn-text source-code-expand-btn")[0].style.display = "none";
        document.getElementsByClassName("btn-copy btn-pre")[0].style.zIndex = "1";
        document.getElementsByClassName("btn-copy btn-pre")[0].style.borderRadius = "0";
        document.getElementsByClassName("btn-copy btn-pre")[1].style.zIndex = "1";
        document.getElementsByClassName("btn-copy btn-pre")[1].style.borderRadius = "0";
    `
    document.head.prepend(header);

    let div = document.createElement("div");
    div.style.marginTop = "10px";
    div.style.marginBottom = "30px";
    document.getElementById("submission-code").after(div);

    let arr = new Array;
    for (let i = 0; i < 10; ++i) {
        arr.push(document.getElementsByClassName("L" + i.toString()));
    }
    let str = ""
    let idx;
    for (idx = 0; ; ++idx) {
        if (Math.floor(idx / 10) < arr[idx % 10].length) {
            str += arr[idx % 10][Math.floor(idx / 10)].innerText;
            str += "\n";
        } else break;
    }
    div.style.height = Math.min(510, (idx + 1) * 21 + 6).toString() + "px";
    console.log(idx);

    let lang = document.getElementsByClassName("text-center")[3].innerText;
    lang = lang.slice(0, lang.indexOf(" ")).toLocaleLowerCase().replace("#", "sharp");
    if (lang.startsWith("pypy")) lang = "python";
    else if (lang == "c++") lang = "cpp";

    script.onload = function() {
        require.config({ paths: { "vs": "https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.33.0/min/vs" } });

        require(["vs/editor/editor.main"], function() {
            monaco.editor.create(div, {
                value: str,
                language: lang,
                theme: "vs-dark",
                readOnly: true,
                lineHeight: 21,
            });
            document.getElementsByClassName("monaco-editor")[0].style.paddingTop = "20px";
        });
    };
})();