AtCoder for Large Display

サンプルなどを二列に並べます。

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

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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==
// @name         AtCoder for Large Display
// @namespace    http://atcoder.jp/
// @version      0.1
// @description  サンプルなどを二列に並べます。
// @author       magurofly
// @match        https://atcoder.jp/contests/*/tasks/*
// @icon         https://www.google.com/s2/favicons?domain=atcoder.jp
// @grant        unsafeWindow
// @license      CC0 1.0 Universal
// ==/UserScript==

(function() {
    'use strict';

    function hasHeadingMatching(e, pattern) {
        for (const heading of e.querySelectorAll("h1,h2,h3,h4,h5,h6")) {
            if (heading.textContent.match(pattern)) return true;
        }
        return false;
    }

    function moveTo(container, elements) {
        for (const element of elements) {
            if (element.parentElement) element.parentElement.removeChild(element);
            container.appendChild(element);
        }
    }

    for (const container of document.querySelectorAll(".lang>span")) {
        container.classList.add("row");
        const testcases = [];
        let inputStyle, outputStyle;
        for (const col of container.querySelectorAll(".part,.io-style")) {
            if (col.querySelector(".btn-copy")) {
                testcases.push(col);
                col.classList.add("col-md-6");
            } else if (hasHeadingMatching(col, /入力|Input/i)) {
                inputStyle = col;
                col.classList.add("col");
            } else if (hasHeadingMatching(col, /出力|Output/i)) {
                outputStyle = col;
                col.classList.add("col");
            } else {
                col.classList.add("col");
            }
        }
        if (inputStyle && outputStyle) {
            inputStyle.classList.remove("col");
            inputStyle.classList.add("col-xs-6");
            outputStyle.classList.remove("col");
            outputStyle.classList.add("col-xs-6");
            const row = document.createElement("div");
            row.className = "row";
            inputStyle.parentElement.appendChild(row);
            moveTo(row, [inputStyle, outputStyle]);
        }
        for (let i = 0; i < testcases.length; i += 2) {
            const input = testcases[i];
            const output = testcases[i + 1];
            const row = document.createElement("div");
            row.className = "row";
            input.parentElement.appendChild(row);
            moveTo(row, [input, output]);
        }
    }
})();