AtCoder for Large Display

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

As of 2022-01-25. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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