Roll20 Quick Character Selection

Pressing the graves key (`) in the chatbox will query the character list for a Roll20 game and select the first match. Easy.

As of 17.07.2018. See ბოლო ვერსია.

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         Roll20 Quick Character Selection
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Pressing the graves key (`) in the chatbox will query the character list for a Roll20 game and select the first match. Easy.
// @author       Ephemeralis
// @match        https://app.roll20.net/editor/
// @grant        none
// ==/UserScript==

console.log("Roll20 Quick Char Selection loaded!");
window.G20_ClearChat = false;

function searchForCharacter(qn)
{
    var changed = false;
        $('#speakingas > option').each(function () {
            if (this.text.toLowerCase().indexOf(qn.toLowerCase()) !== -1)
            {
                //found a match, so set the speaking as value and we're good
                //$('#textchat-input > textarea').text = "test"
                $('#speakingas').val(this.value).change();
                //then clear the textbox of the search value afterwards
                //$('#textchat-input > textarea').text("").change();
                changed = true;
                return false;
            }
        } );
   return changed;
}

window.searchForCharacter = searchForCharacter;

function doc_keyDown(e)
{
    switch (e.keyCode)
    {
        case 192: //graves `
            if (document.activeElement.parentNode.id == "textchat-input")
            {
                var search = $('#textchat-input > textarea').val();
                console.log(search);
                if (searchForCharacter(search))
                {
                    console.log("search term matched! clearing textbox on keyup...");
                    window.G20_ClearChat = true;
                }
            }
            break;
    }
}

function doc_keyUp(e)
{
    switch (e.keyCode)
    {
        case 192:
            if (document.activeElement.parentNode.id == "textchat-input" && window.G20_ClearChat == true)
            {
                //reset the chatbox text on good match
                console.log("Resetting R20 chat text area...");
                $('#textchat-input > textarea').val("").change();
                window.G20_ClearChat = false;
            }
          break;
    }
}


document.addEventListener('keydown', doc_keyDown, false);
document.addEventListener('keyup', doc_keyUp, false);