JSFiddle - React, Tailwind, and code Playground

by Wesley Smith

HTML

<li class="message-list-item needsclick status-message join">
        <div class="header">
            <div class="username"><span class="username-text">UserNameRemoved2</span></div>
        </div>
        <div class="message" tabindex="0" role="button">
            <span class="message-text">UserNameRemoved2 is in the chat</span> &nbsp;
            <span class="time-since">Just now</span>
            <div class="down-arrow"></div>
        </div>
        <div class="thumbnail">
            <img class="thumbnail-img"/>
            <div class="user-icon"></div>
        </div>
    </li>
    <li class="message-list-item needsclick status-message join">
        <div class="header">
            <div class="username"><span class="username-text">Guest_UserNameRemoved1</span></div>
        </div>
        <div class="message" tabindex="0" role="button">
            <span class="message-text">Guest_UserNameRemoved1 is in the chat</span> &nbsp;
            <span class="time-since">Just now</span>
            <div class="down-arrow"></div>
        </div>
        <div class="thumbnail">
            <img class="thumbnail-img"/>
            <div class="user-icon"></div>
        </div>
    </li>
    <li class="message-list-item needsclick my-user status-message join">
        <div class="header">
            <div class="username"><span class="username-text">VanessaCxo</span></div>
        </div>
        <div class="message" tabindex="0" role="button">
            <span class="message-text">You joined the chat</span> &nbsp;
            <span class="time-since">Just now</span>
            <div class="down-arrow"></div>
        </div>
        <div class="thumbnail">
            <img class="thumbnail-img"/>
            <div class="user-icon"></div>
        </div>
    </li>
    <li class="message-list-item needsclick my-user">
        <div class="header">
            <div class="username"><span class="username-text">NikolaTeslaX</span></div>
        </div>
        <div class="message"...

JavaScript

var last_cmd_count =0;
var monitoring = true;
var processing_commands= false;

function verifyCommand() {
  if ($(".message-list-item").length > last_cmd_count && !processing_commands) {
	processing_commands = true; // you should set this immediately 
    var new_length = $('.message-list-item').length;
    console.log("Begin processing commands... ** SYSTEM LOCK **");
    console.log('Lastcommand count: '+ last_cmd_count +',   New Length: '+new_length);
	var newMessages = $('.message-text:not(.processed)'); // get all of the message elements that do not have the class "processed" 
	// loop through each of the message elements
	
    newMessages.each(function(index, element){
         console.log('Processing new element at index '+index );
		 try {
			  var callinguser = $(this).parent().parent('li').find('.username-text').text().replace("Guest_", "");
			  var messagetext = $(this).text();
              $(this).addClass('processed'); //  add processed class to the element so we know not to process it again later   
			  if (callinguser != "USERNAME REMOVED") {
				if (messagetext.match(/^\//)) {
				  if (callinguser.match(/IMVU User/i)) {
					die();
				  }
				  processCommand(messagetext.substr(1), callinguser);
				} 
				else {
				  if (messagetext.match(/room\s?greet/i)) {
					if (detectFlirt()) {
					  sendMsgRaw('Please do not hit on me, ' + callinguser + '.');
					  if (!isAdmin(callinguser)) {
						logIdiot(callinguser);
					  }
					} 
					else if (messagetext.match('what is ')) {
					  sendMsgRaw('Please use /solve or /advsolve for math.');
					} 
					else {
					  if (callinguser != "USERNAME REMOVED") {
						ident();
					  }
					}
				  }
				  if (messagetext.match(/free|credits|http:\//i)) {
					sendMsgFrom("*** SCAM ALERT ***", callinguser);
				  }
				}
			  }
         } 
		 catch (ex) {
             console.log('caught error');
	     } 
		 finally {
	     }
	});
    last_cmd_count = new_length;
    console.log("Finish processing...