fore.st/www/js/fembed.js
rainbownapkin 9455fd8964 fore.st - Panama Red (v1)
changelist:
-pseudo-random name colors
-layout fixes(moved chat after the video on the .pug. also disabled said
feature in fcyp.js)
-theme updates(tokebot flair, changed modflair, more compact layout,
unfucked cytube provided css (srsly, WTF calzoneman? Why?)
link decorations, made things moar unified)
-added image embedding, disabling fcyp image embed (nothing new from a
user standpoint, simply slowly stripping fcyp.js out)
-moved emote button to chatbar, added send button as well
-chatpaste & chatsmack functions allowing clickable usernames/
-fixed raw video controls
-ripped out chat processing logic from fcyp.js, it was breaking a lot of
shit and everything it did has been implemented by this update and moar

devnotes:
Biggest update yet, also made some good steps towards fully ripping
fcyp.js out completely. Played around with an image upload button. I
might have to setup a cors relay to get that working, I'll have to play
around more :p
2022-02-03 02:32:27 +00:00

54 lines
2.1 KiB
JavaScript

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 '<img src="' + word + '" style="max-height: 13em">';//embed media
}else if(!isEmote){
return '<a href="' + word + '">' + word + '</a>';//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] + '<span id="' + getColor(stripd) + '" onclick="chatpaste(\'' + stripd + '\')">' + stripd + '</span>' + 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] + '<a id="toke" onclick="chatsmack(\'' + tstripd + '\')">' + tstripd + '</a>' + 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
}