omegleuser / Discord quick reaction

// ==UserScript==
// @name         Discord quick reaction
// @namespace    http://tampermonkey.net/
// @version      0.6
// @description  React with a random emoji (change in code window.location.href URL if want to use on another discord page or comment out that line). Press ` (the key below Esc) to hide/show the sidebar. Ctrl and Alt keys now do different reactions.
// @author       You
// @match        https://discord.com/*
// @grant        none
// @license     MIT
// ==/UserScript==

(function() {
    'use strict';
    var ctrl = 0;
    var rand;
    var emojis;
    var observer = new MutationObserver(function (mutations, me) {

        if(window.location.href == "https://discord.com/channels/745817528135319603/791136208067624970") {
            if(document.querySelector('[aria-label="nature"]')) {
                if(ctrl === 1) {
                    document.querySelector('[aria-label="travel"]').click();
                    setTimeout(function() {
                        emojis = document.querySelectorAll('button[data-type="emoji"]');
                        rand = Math.floor(Math.random() * emojis.length);
                        if(emojis[rand]) {
                            emojis[rand].click();
                        }
                    },0);
                } else if(ctrl === 2) {
                    document.querySelector('[aria-label="food"]').click();
                    setTimeout(function() {
                        emojis = document.querySelectorAll('button[data-type="emoji"]');
                        rand = Math.floor(Math.random() * emojis.length);
                        if(emojis[rand]) {
                            emojis[rand].click();
                        }
                    },0);
                } else {
                    document.querySelector('[aria-label="nature"]').click();
                    setTimeout(function() {
                        emojis = document.querySelectorAll('button[data-type="emoji"]');
                        rand = Math.floor(Math.random() * emojis.length);
                        if(emojis[rand]) {
                            emojis[rand].click();
                        }
                    },0);
                }
            }
        }
    });

    // start observing
    observer.observe(document, {
        childList: true,
        subtree: true
    });

    //document.querySelector('.sidebar-2K8pFh').style.display = "block";

    document.onkeydown = checkKey;

    function checkKey(e) {
        if(e.key == "`") {
            var sidebar = document.querySelector('[class^="sidebar-"]');
            if((sidebar.style.display === "block") || (sidebar.style.display === "")) { //Sidebar hide
                sidebar.style.display = "none";
            } else {
                sidebar.style.display = "block";
            }
            e.preventDefault();
        } else if(e.key == "Control") {
            ctrl = 1;
            setTimeout(function() {
                ctrl = 0;
            }, 1500);
        } else if(e.key == "Alt") {
            ctrl = 2;
            setTimeout(function() {
                ctrl = 0;
            }, 1500);
        }
    }


})();