Spawner / MTLNovel - Entity Colorizer

// ==UserScript==
// @name        MTLNovel - Entity Colorizer
// @namespace   mtlcolorizer
// @match       https://www.mtlnovel.com/*/*/
// @grant       GM_xmlhttpRequest
// @grant       GM_addStyle
// @version     1.0
// @license     MIT
// @author      Spawner
// @description 3/18/2020, 16:10:42 AM
// ==/UserScript==

/*
    ChangeLog 
    
      1.0 - Initial Release

*/

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

const colorName     = "rgb(211, 84, 0)";
const colorLocation = "rgb(142, 68, 173)";

var hashTableWords;

window.onload = function()
{
    hashTableWords = new Map();
    
    var getText = Array.from(document.getElementsByClassName('post-content')[0].getElementsByClassName('en'), e => e.innerText).toString();
    runScript(getText);
};

function runScript(text) 
{
    GM_xmlhttpRequest(
    {
        method  : "POST",
        url     : "https://api.explosion.ai/displacy/ent",
        data    : JSON.stringify(
        { 
            "model" : "en_core_web_md",
            "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" )
                {
                    var entityData = text.slice( obj.start, obj.end );
                    hashTableWords.set( entityData, entityType );
                } 
            });

            for (const [key, value] of hashTableWords.entries()) 
            {   
                var color = (value[0] == "P") ? colorName : colorLocation;
              
                document.getElementsByClassName('post-content')[0].innerHTML = 
                  document.getElementsByClassName('post-content')[0].innerHTML.replace
                  (
                          new RegExp(key, "ig"), '<hgltr style="color:' + color + '">' + key + '</hgltr>'
                  );
            }
         }
    });
}