img_ext = ['jpg', 'jpg:large', 'jpeg', 'png', 'tiff', 'gif']; vid_ext = ['webm', 'gifv', 'mp4']; proto = ['http', 'https']; function checkMedia(fname){//check if link points ot media var fext = fname.split('.').pop().toLowerCase();//pop file ext if(img_ext.includes(fext)){//if its an img return 1; }else if(vid_ext.includes(fext)){//if its a vid return 2; }else{//nada return 0; } } function checkEmbed(word, isEmote){ let regex = /[!"#$%&'()*+,./:;<=>?@[\]^`{|}~]/g;//symbol mask for username let tregex = /["#$%&'()*+,-./:;<=>?@[\]^_`{|}~]/g;//symbol mask for tokes let stripd = word.replace(regex, '');//stripped word for username detection let tstripd = word.replace(tregex, '');//stripeed word for !toke command detection if(word.includes(proto[0]) || word.includes(proto[1])){//check if it starts with a supported proto if(checkMedia(word) != 0){//check if media return '';//embed media }else if(!isEmote){//if its a link if(word.includes("imgur.com")){ if(word.length > 20 && word.length < 28){ return '';//embed media } } return '' + word + '';//embed link }else{ return word; } }else if(usrColors[0].includes(stripd)){//if username let usersplit = word.split(stripd,2);//split word by stripd, array of before and after name return usersplit[0] + '' + stripd + '' + usersplit[1];//decorate name }else if(tstripd.charAt(0) === '!'){//if !toke command(same logic as above) let tokesplit = word.split(tstripd,2); return tokesplit[0] + '' + tstripd + '' + tokesplit[1]; }else{ return word; } } function findEmbed(str){//check entire string for embeds let isEmote = str.includes('class="channel-emote"'); var splts = str.split(/\s/g);//split string by whitespace let baked = checkEmbed(splts[0], isEmote) + ' ';//work string, set first item to checkEmbed of first word for(i = 1; i < splts.length; i++){//run through words baked += checkEmbed(splts[i], isEmote) + ' ';//checkEmbed() and add to baked with a space after it } return baked;//return baked ;p }