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.

Από την 17/07/2018. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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);