AtCoder Problem Buttons

問題選択を一度に行えるボタンを追加します

Από την 18/05/2022. Δείτε την τελευταία έκδοση.

// ==UserScript==
// @name    AtCoder Problem Buttons
// @namespace    http://tampermonkey.net/
// @version    0.1
// @description    問題選択を一度に行えるボタンを追加します
// @author    Chippppp
// @license    MIT
// @match    https://atcoder.jp/contests/*/submit*
// @grant    none
// ==/UserScript==

(function() {
    "use strict";
    let problemButton = document.getElementsByClassName("select2 select2-container select2-container--bootstrap")[0];
    let problemButtons = [];
    for (let i of document.getElementById("select-task").children) {
        let button = document.createElement("button");
        if (problemButtons.length == 0) problemButton.after(button);
        else problemButtons.slice(-1)[0].after(button);
        button.className = "btn btn-default";
        button.type = "button";
        button.innerText = i.innerText;
        button.value = i.value;
        problemButtons.push(button);
    }
    for (let i of problemButtons) {
        i.addEventListener("click", function() {
            for (let button of problemButtons) button.className = "btn btn-default";
            this.className = "btn btn-success";
            document.getElementById("select-task").value = this.value;
            document.getElementById("select2-select-task-container").innerText = i.innerText;
        });
        if (i.innerText == problemButton.innerText) i.click();
    }
    let observer = new MutationObserver(function() {
        for (let i of problemButtons) if (i.innerText == problemButton.innerText) i.click();
    });
    const config = {
        attributes: true,
        childList: true,
        characterData: true,
    };
    observer.observe(document.getElementsByClassName("select2-selection select2-selection--single")[0], config);
})();