Spawner / Wuxiaworld - Entity Colorizer

// ==UserScript==
// @name        Wuxiaworld - Entity Colorizer
// @namespace   entitycolorizer
// @match       https://www.wuxiaworld.com/novel/*/*
// @grant       GM_xmlhttpRequest
// @grant       GM_addStyle
// @version     1.0
// @license     MIT
// @author      Spawner
// @description 3/19/2020, 10:14:00 PM
// ==/UserScript==

GM_addStyle("hgltr { text-shadow: 0 0 0px #34495e, 0 0 1px #34495e }");

var myColors = [];
var hashTableWords;

window.onload = function()
{
    hashTableWords = new Map();

    myColors['person'] = "rgb(211, 84, 0)";
    myColors['loc']    = "rgb(142, 68, 173)";
    myColors['date']   = "rgb(39, 174, 96)";
      
    runScript($('.fr-view').text());
};

function runScript(text) 
{
    GM_xmlhttpRequest(
    {
        method  : "POST",
        url     : "https://api.explosion.ai/displacy/ent",
        data    : JSON.stringify(
        { 
            "model" : "en_core_web_lg",
            "text"  : text
        }),
        headers : { "Content-Type": "application/json;charset=UTF-8" },
        onload: function(response) 
        { 
            var jsonArray = JSON.parse(response.responseText);

            jsonArray.forEach(function(obj) 
            {
                var entityType = obj.label;
                if( entityType == "PERSON" || entityType == "LOC" || entityType == "DATE" )
                {
                    var entityData = text.slice( obj.start, obj.end );
                    hashTableWords.set( entityData, entityType );
                } 
            });

            for (const [key, value] of hashTableWords.entries()) 
            {
                document.getElementById('chapter-content').innerHTML = 
                  document.getElementById('chapter-content').innerHTML.replace
                  (
                          new RegExp('(\\b)(' + key + ')(\\b)','ig'), '<hgltr style="color:' + myColors[value.toLowerCase()] + '">' + key + '</hgltr>'
                  );
            }
         }
    });
}