omegleuser / Chat Random - One-click Text Buttons

// ==UserScript==
// @name         Chat Random - One-click Text Buttons
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Adds buttons to the Chat Random screen that if you click them will put text into the chat window. Now also supports pressing the numpad to send the text buttons (from right to left, 0 to 5)
// @author       Omegle User
// @include		https://*chatrandom.com*
// @license     MIT
// @grant        none

// ==/UserScript==

(function() {
    'use strict';

    function addGlobalStyle(css) {
        var head, style;
        head = document.getElementsByTagName('head')[0];
        if (!head) { return; }
        style = document.createElement('style');
        style.type = 'text/css';
        style.innerHTML = css.replace(/;/g, ' !important;');
        head.appendChild(style);
    }
    addGlobalStyle(".textbtns { z-index:99999;background: #25A6E1; background: -moz-linear-gradient(top,#25A6E1 0%,#188BC0 100%); background: -webkit-gradient(linear,left top,left bottom,color-stop(0%,#25A6E1),color-stop(100%,#188BC0)); background: -webkit-linear-gradient(top,#25A6E1 0%,#188BC0 100%); background: -o-linear-gradient(top,#25A6E1 0%,#188BC0 100%); background: -ms-linear-gradient(top,#25A6E1 0%,#188BC0 100%); background: linear-gradient(top,#25A6E1 0%,#188BC0 100%); filter: progid: DXImageTransform.Microsoft.gradient( startColorstr='#25A6E1',endColorstr='#188BC0',GradientType=0); padding:1px 3px; color:#fff; font-family:'Helvetica Neue',sans-serif; font-size:12.5px; border-radius:3px; -moz-border-radius:3px; -webkit-border-radius:3px; border:1px solid #1A87B9; cursor:pointer; text-decoration:none; }");
    addGlobalStyle(".textbtns:hover { background: #0886c0; background: -moz-linear-gradient(top,#0886c0 0%,#188BC0 100%); background: -webkit-gradient(linear,left top,left bottom,color-stop(0%,#0886c0),color-stop(100%,#188BC0)); background: -webkit-linear-gradient(top,#0886c0 0%,#188BC0 100%); background: -o-linear-gradient(top,#0886c0 0%,#188BC0 100%); background: -ms-linear-gradient(top,#0886c0 0%,#188BC0 100%); background: linear-gradient(top,#0886c0 0%,#188BC0 100%); filter: progid: DXImageTransform.Microsoft.gradient( startColorstr='#0886c0',endColorstr='#188BC0',GradientType=0); }");
    addGlobalStyle(".textbtns:disabled { cursor: not-allowed; filter: alpha(opacity=65); opacity: .65; -webkit-box-shadow: none; box-shadow: none; }");
    addGlobalStyle("#partialcover { background-color:#fff;z-index:99999; }");


    window.addEventListener("click", function(e) {

        if(document.querySelector("#chatMessage")) {
            document.getElementById('textdiv').style.visibility = 'visible';
        }

    }, false);

    // create text buttons
    var textdiv = document.createElement( 'div' );
    textdiv.setAttribute( 'id', 'textdiv' );
    textdiv.setAttribute( 'style', "position: absolute;z-index: 999999999999;right: 3px;bottom:88px;");
    textdiv.style.visibility = 'hidden';
    document.body.appendChild( textdiv );

    var btnsText = [
        "Brkfst",
        "Jn 3:16",
        "Church",
        "John",
        "ESV",
        "needGod.net"
    ];

    var btnsVals = [
        "no Bible, no breakfast",
        "John 3:16 - For God so loved the world, that he gave his only Son, that whoever believes in him should not perish but have eternal life.",
        "to find a good church in your area: 9marks.org/church-search/",
        'start in "John" in the second half of the Bible',
        '"ESV Bible" in the app store, or at ESV.org',
        "needGod.net"
    ];

    var btnsSecondary = [
        "no read, no feed",
        null,
        null,
        null,
        "it's free",
        null
    ];


    var textbtn;
    var index;
    for (index = 0; index < btnsText.length; ++index) {
        textbtn = document.createElement( 'input' );
        textbtn.setAttribute( 'value', btnsText[index] );
        textbtn.setAttribute( 'type', 'button' );
        textbtn.setAttribute( 'id', index );
        textbtn.setAttribute( 'class', "textbtns");
        document.getElementById('textdiv').appendChild( textbtn );
        document.getElementById('textdiv').appendChild(document.createTextNode (" "));
        document.getElementById(index).addEventListener ("click", setText , false);
    }

    function sendMsg() {
        document.getElementById("send_btn").click();
        if(currentBtnId !== null) {
            if(btnsSecondary[currentBtnId] !== null) {
                var el = document.getElementsByClassName("emoji-wysiwyg")[0];
                el.innerHTML = btnsSecondary[currentBtnId];
                document.getElementById("send_btn").click();
                currentBtnId = null;
                setTimeout(function() {
                    sendMsg();
                }, Math.floor((Math.random() * 500) + 1500));
            }
        }
    }

    var currentBtnId;
    function setText(e) {
        var el = document.getElementsByClassName("emoji-wysiwyg")[0];
        el.innerHTML = btnsVals[this.id];
        var evt = document.createEvent("Events");
        evt.initEvent("change", true, true);
        el.dispatchEvent(evt);
        currentBtnId = this.id;
        setTimeout(function() {
            sendMsg();
        }, Math.floor((Math.random() * 200) + 200));
    }

    document.addEventListener("keydown", function (e) {
        for(var n = 0;n<btnsText.length;n++) {
            if (e.code == 'Numpad'+n) {
                e.preventDefault();
                document.getElementById(((btnsText.length-1)-n)).click();
            }
        }
    });

})();