let commentFormID; function commentForm(form) { commentFormID = form; }; async function getGif(searchTerm) { if (searchTerm !== undefined) { document.getElementById('gifSearch').value = searchTerm; } else { document.getElementById('gifSearch').value = null; } var loadGIFs = document.getElementById('gifs-load-more'); var noGIFs = document.getElementById('no-gifs-found'); var container = document.getElementById('GIFs'); var backBtn = document.getElementById('gifs-back-btn'); var cancelBtn = document.getElementById('gifs-cancel-btn'); container.innerHTML = ''; if (searchTerm == undefined) { container.innerHTML = '
Agree
Laugh
Confused
Sad
Happy
Awesome
Yes
No
Love
Please
Scared
Angry
Awkward
Cringe
OMG
Why
Gross
Meh
' backBtn.innerHTML = null; cancelBtn.innerHTML = null; noGIFs.innerHTML = null; loadGIFs.innerHTML = null; } else { backBtn.innerHTML = ''; cancelBtn.innerHTML = ''; let response = await fetch("/giphy?searchTerm=" + searchTerm + "&limit=48"); let data = await response.json() var max = data.length - 1 data = data.data var gifURL = []; if (max <= 0) { noGIFs.innerHTML = '

Aw shucks. No GIFs found...

'; container.innerHTML = null; loadGIFs.innerHTML = null; } else { for (var i = 0; i < 48; i++) { gifURL[i] = "https://media.giphy.com/media/" + data[i].id + "/giphy.webp"; if (data[i].username==''){ container.innerHTML += ('
'); } else { container.innerHTML += ('
'); } noGIFs.innerHTML = null; loadGIFs.innerHTML = '

Thou've reached the end of the list!

'; } } } } function insertGIF(url,form) { const commentBox = document.getElementById(form); const old = commentBox.value; if (old) commentBox.value = `${old}\n${url}`; else commentBox.value = url if (typeof checkForRequired === "function") checkForRequired(); }