Discord Hide Channel List Button

Hides the channel list at the press of a button

Fra 11.04.2017. Se den seneste versjonen.

// ==UserScript==
// @name         Discord Hide Channel List Button
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Hides the channel list at the press of a button
// @author       20kdc
// @match        https://discordapp.com/channels/*/*
// @grant        none
// ==/UserScript==

// I release this user-script into the public domain.

var mainFunc;
var lastTryParent;
mainFunc = function() {
    'use strict';
    // Toolbar instance tends to change
    setTimeout(mainFunc, 5000);
    const v = document.querySelector(".header-toolbar");
    if (!v)
        return;
    if (lastTryParent == v)
        return;
    lastTryParent = v;
    const d = document.createElement("button");
    d.type = "button";
    d.class = "active";
    // How Discord makes this work, I have no idea. (Also note this could break horribly if they change the SVG file of the cat.)
    d.innerHTML = "<span style=\"background-image: url('/assets/a860a4e9c04e5cc2c8c48ebf51f7ed46.svg');\"></span>";
    v.appendChild(d);
    
    var toggleState = true;
    d.addEventListener("click", () => {
        const v2 = document.querySelector(".channels-wrap");
        if (!v2)
            return;
        toggleState = !toggleState;
        if (toggleState) {
            d.class = "active";
            v2.style.display = "inherit";
        } else {
            d.class = "";
            v2.style.display = "none";
        }
    });
};
mainFunc();