JSFiddle - React, Tailwind, and code Playground

by neonDog

HTML

<input type="text" class="js-chats__search-users-input">

JavaScript

var recipientSplitter = function(recipients, maxLength=100) {
	
  const arr = [];
  let curCharCount = 0;
  let cursor = 0;
  let currentRecipient;
  
  while (recipients.length) {
  	//Remove first from array
    curRecipient = recipients.shift();
    
    //Do we need to increment?
    if (curCharCount + curRecipient.length + 1 >= maxLength) {
    	//Increment cursor
      ++cursor;
      //Insert new string
      arr.push('');
      //Reset counter
      curCharCount = 0;
    }
    
    //Increase length counter
    curCharCount += curRecipient.length + 1;
    //Add to current array / string
    arr[cursor] += curRecipient + ' ';
    
  }
  
  return arr;
  
};

var triggerEvent = function (el, eventType) {

  var ev = new Event(eventType, {
    bubbles: true,
    cancelable: true,
});

  el.dispatchEvent(ev);
  
};

var str = 'u150657597 u93498265 u72424458 u77888588 u88166330 soricjames pceluvempath u121524908 u19835288 u41456184 u20206145 envi24 u153365871 u9993179 gusano187 u5837302 u152323769 u87889732 u76807373 grumpy_gaz u150321391 u104609930 spookycrowguy u47285187 u8631619 robeagles u59522599 u1873240 u118916018 u12021804 u16673025 u72071205 ty-strong giggawhat charmlessman42 hybrid_nephilim thediamond523 xeiro mallorybiscuit u125862013 dbxdevil u32221147 thepeacock108 diksenormous u151813011 u46104605 u99717214 null_one_zero_one penguinius twinksplay2000 u78463233 u33554383';

var timeout = function(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
};

var automaticMsgFiller = async function(recipients, uncheck=true) {

	var result = recipientSplitter(recipients, 100);

	var inputBox = document.body.querySelector('.js-chats__search-users-input');
  
  for (let i=0, l=result.length; i < l; i++) {
  	
    inputBox.click();
    inputBox.value = result[i];
    
    await timeout(300);
    triggerEvent(inputBox, 'input');
    await timeout(5000);
    let selectedClass = uncheck ? '.selected' : ':not(.selected)';
    let checkboxes =...