DomJudge Collapsible run in/output

Collapsible run in- and output on DomJudge submissions

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         DomJudge Collapsible run in/output
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Collapsible run in- and output on DomJudge submissions
// @author       Sten
// @match        https://domjudge.cs.uu.nl/dj/ds/team/submission_details.php?id=*
// @grant        none
// ==/UserScript==

(function() {
    var expandBtn = document.createElement("a");
    expandBtn.innerText = "[+]";
    expandBtn.setAttribute("href", "#");

    $(".output_text").add($("div > .output_text").parent()).css("display", "none");

    $(".output_text").add($("div > .output_text").parent()).prev("h5").each((index, elem) => {
    elem.innerText += " ";
    let newExpandBtn = expandBtn.cloneNode(true);
		newExpandBtn.addEventListener("click", function(event){
            event.preventDefault();
            let nextElem = event.target.parentElement.nextElementSibling;
			      if (nextElem.tagName.toLowerCase() === "div") nextElem = nextElem.nextElementSibling;
            let nextVis = nextElem.style.display == "";
            event.target.innerText = nextVis ? "[+]" : "[-]";
            nextElem.style.display = nextVis ? "none" : "";
		});
        elem.appendChild(newExpandBtn);
    });
})();