JSFiddle - React, Tailwind, and code Playground

HTML

<textarea id="post-msg" style="width:300px;height:100px"></textarea>
<div id="charcnt-wrap"> 
    <span class="shortenlinks">Links will appear shortened:</span><br> 
    <ul id="linkstoshort"> 
    </ul> 
    <h5 style="margin-bottom:0;">Facebook Limit: <span id="fb-char">420</span></h5><br> 
    <h5 style="margin-top:-12px;">Twitter Limit: <span id="tw-char">140</span></h5> 
</div>

JavaScript

function checkPostForURL(post){
    var matches = [],
        urlexp = new RegExp("(^|[ \t\r\n])((http|https):(([A-Za-z0-9$_.+!*(),;/?:@&~=-])|%[A-Fa-f0-9]{2}){2,}(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*(),;/?:@&~=%-]*))?([A-Za-z0-9$_+!*();/?:~-]))","g"),
        $linkShort = $('#linkstoshort'),
        matchIdx = 0;
    
    if ( post !== undefined ){
        if ( urlexp.test(post) ){
               var offset = 0;
               $('.shortenlinks').show();
               matches = post.match(urlexp);
    
               $linkShort.html('');
    
                for(; matchIdx < matches.length; matchIdx++) {
                    var match = matches[matchIdx],
                        matchOffset = match.length - 23;
                    
                    offset += matchOffset;
                    
                    $linkShort.append('<li>'+match+'</li>');
                }
    
                return offset;
        }
    }
 }

$(function(){
    var $postMsg = $('#post-msg'),
        message = $postMsg.text(),
        twstartchars = 140 - message.length,
        fbstartchars = 420 - message.length,
        $fbCount = $("#fb-char"),
        $twCount = $("#tw-char"),
        setRemainingChars = function (evt) {
            var post = $postMsg.val(),
                postLen = post.length;
        
            var offset = checkPostForURL(post);
            if ( offset ){
                postLen = postLen - offset;
            }
        
            $fbCount.text((420 - postLen));
            $twCount.text((140 - postLen));
            if ( postLen > 120 ){
                    $fbCount.css('color','red');
                    if ( a > 380 ){
                            $fbCount.css('color','red');
                    }
            }else{
                    $fbCount.css('color','#333');
                    $twCount.css('color','#333');
            }
        };
    
    $fbCount.text(fbstartchars);
    $twCount.text(twstartchars);
    
    $postMsg.on('keypress change',...