Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- String.prototype.capitalizeFirstLetter = function() {
- return this.charAt(0).toUpperCase() + this.slice(1);
- }
- var chat = document.getElementById("chat");
- var form = document.getElementById("chatter");
- var messageBox = document.getElementById("message");
- var status = document.getElementById("status");
- function addChatMessage(from, text) {
- li = document.createElement("li");
- user = document.createElement("span");
- user.className = "from";
- user.innerText = from;
- li.appendChild(user);
- message = document.createElement("span");
- message.className = "message";
- message.innerText = text;
- li.appendChild(message);
- chat.appendChild(li);
- chat.scrollTop = chat.scrollHeight;
- }
- var waifuMessages = 0;
- function typingWaifuMessage() {
- waifuMessages++;
- status.innerHTML = '<strong>Waifu</strong> is typing...';
- setTimeout(sendWaifuMessage, Math.random() * (3200 - 1200) + 1200);
- }
- function generateWan(comma = false) {
- wans = Math.floor(Math.random() * 3 + 1);
- wan = "wan ".repeat(wans);
- if (!comma) wan = wan.capitalizeFirstLetter();
- wan = wan.trim();
- punct = Math.floor(Math.random() * 5);
- if (punct == 3) {
- wan += "?";
- } else if (punct == 4) {
- wan += ", ";
- wan += generateWan(true);
- } else {
- wan += "!";
- }
- if (comma) return wan;
- emote = Math.floor(Math.random() * 4);
- if (emote == 3) {
- wan += " ^-^";
- } else if (emote == 2) {
- wan += " :3";
- }
- return wan;
- }
- function sendWaifuMessage() {
- wan = generateWan();
- addChatMessage("Waifu", wan);
- waifuMessages--;
- if (waifuMessages == 0) {
- status.innerText = "";
- }
- }
- form.addEventListener("submit", function(evt) {
- evt.preventDefault();
- if (messageBox.value == "") return;
- addChatMessage("You", messageBox.value);
- messageBox.value = "";
- setTimeout(typingWaifuMessage, Math.random() * (1200 - 100) + 100);
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement