document.write(`
Forgotten password ?
Enter email
Register for new account
Forgotten password ?
Enter email
`); var Chat = function (room, username, avatar) { (async()=>{ if (localStorage.getItem('email')) { jQuery('#shoutboxEmailAdmin').val(localStorage.getItem('email')) } if (localStorage.getItem('password')) { jQuery('#shoutboxPasswordAdmin').val(localStorage.getItem('password')) } const server = 'https://www.shoutbox.com'; const $shoutBoxContainer = jQuery('.shoutBoxContainer'); const $shoutboxLoginPanel = jQuery('#shoutboxLoginPanel'); const $shoutboxAdminPasswordChangePanel = jQuery('#shoutboxAdminPasswordChangePanel'); const $shoutboxForgottenPassword = jQuery('#shoutboxForgottenPassword'); this.AJAX = `${server}/chat/ajax.php`; window.shoutbox = this; username = username || ''; avatar = avatar || `${server}/avatars/` + Math.ceil(Math.random() * 29) + '.svg'; this.myUser = {username: username, room: room, avatar: avatar, password: '', id: new Date().getTime()}; const sprintf = (str, ...argv) => !argv.length ? str : sprintf(str = str.replace(sprintf.token || "%s", argv.shift()), ...argv); this.showAd = () => { let html = `Get your free shoutbox with no ads for 9.90€/year`; this.serverMessage(html); }; String.prototype.replaceAll = function (target, replacement) { return this.split(target).join(replacement); }; this.ago = (date) => { let seconds = Math.floor((new Date() - date) / 1000); let interval = Math.floor(seconds / 31536000); if (interval > 0) { return interval + ' y. ago'; } interval = Math.floor(seconds / 2592000); if (interval > 0) { return interval + ' mon. ago'; } interval = Math.floor(seconds / 86400); if (interval > 0) { return interval + ' d. ago'; } interval = Math.floor(seconds / 3600); if (interval > 0) { return interval + ' h ago'; } interval = Math.floor(seconds / 60); if (interval > 0) { return interval + ' min. ago'; } return 'now'; }; // traductions this.traductions = { welcome: "Welcome %s. ", userOnline: "%s user online", usersOnline: "%s users online", enterYourTextHere: "Enter your text here", serverMessage: "
%s
", enterAdminPassword: "Enter admin password", imageAvatar: "", youAreAdminNow: "You are admin now.", mp3: "https://www.shoutbox.com/chat/mp3/dink.mp3", addUser: "
%s %s
", banText: "", receivedText: "
%s%s %s: %s
", youBannedUser: "You banned %s" }; // smileys this.smileys = { ':)': '🙂', ';)': '🙂', ':D': '😃', 'xD': '😆', ':(': '😟', ":'(": '😢', '>:(': "😠", ':O': "😮", ':$': "😳", ':|': "😐", '<3': "❤", }; this.parseSmileys = (text) => { for (let symbol in this.smileys) { let image = this.smileys[symbol]; text = text.replaceAll(symbol, image); } return text; }; this.stripHTML = (html) => { let div = document.createElement('div'); div.innerHTML = html; return div.textContent || div.innerText || ''; }; this.clearChat = () => { document.querySelector('#shoutChat').innerHTML = ''; }; this.refreshChat = async () => { this.clearChat(); let formData = new FormData(); formData.append('a', 'getLastMessages'); formData.append('id', this.myUser.room); let response = await fetch(this.AJAX, { method: 'POST', body: formData, }); let messages = await response.json(); for (let i = messages.length - 1; i >= 0; i--) { let message = messages[i]; this.receiveText(message.username, message.message, message.date, 0, message.avatar, message.ip, message.id); } }; this.getLastMessages = async () => { let formData = new FormData(); formData.append('a', 'getLastMessages'); formData.append('id', this.myUser.room); let response = await fetch(this.AJAX, { method: 'POST', body: formData, }); let messages = await response.json(); for (let i = messages.length - 1; i >= 0; i--) { let message = messages[i]; this.receiveText(message.username, message.message, message.date, 0, message.avatar, message.ip, message.id); } if (this.myUser.username !== '') { this.welcome(); } }; jQuery('#shoutBoxInput').on('keypress', (e) => { let keyCode = e.keyCode || e.which; if (keyCode === 13) { this.sendText(); } }); this.sendText = () => { let $shoutBoxInput = jQuery('#shoutBoxInput'); let text = $shoutBoxInput.val().trim(); text = (this.stripHTML(text)); if (text === '') { return; } if (this.myUser.username === '') { this.myUser.username = text; $shoutBoxInput.val(''); this.welcome(); this.shoutboxSocket.emit('changeUser', this.myUser); return; } $shoutBoxInput.val(''); this.shoutboxSocket.emit('send', this.myUser, text); $shoutBoxInput.prop('disabled', true); setTimeout(function () { $shoutBoxInput.prop('disabled', false); $shoutBoxInput.focus(); }, 2500) }; this.welcome = () => { let $shoutBoxInput = jQuery('#shoutBoxInput'); $shoutBoxInput.attr('placeholder', this.traductions.enterYourTextHere); localStorage.setItem('username', this.myUser.username); this.serverMessage(sprintf(this.traductions.welcome, this.myUser.username)); $shoutBoxInput.removeClass('shoutInputRed'); localStorage.setItem('username', this.myUser.username); }; this.serverMessage = (text) => { let $shoutChat = jQuery('#shoutChat'); $shoutChat.append(sprintf(this.traductions.serverMessage, text)); $shoutChat.animate({scrollTop: $shoutChat[0].scrollHeight}, 1000); }; this.receiveText = (username, message, date, scrollTimer, avatar, ip, id) => { username = this.stripHTML(username); message = this.parseSmileys(message); if (avatar !== '') { avatar = this.getAvatar(avatar, username); } if (date !== '') { date = sprintf('(%s)', date); } let text = sprintf(this.traductions.receivedText, id, ip, avatar, date, username, message); //console.log(text); let $shoutChat = jQuery('#shoutChat'); $shoutChat.animate({scrollTop: $shoutChat[0].scrollHeight}, scrollTimer); jQuery(text).hide().appendTo('#shoutChat').fadeIn(2000); if (this.myUser.isAdmin) { let temp = `div[data-id=${id}]`; jQuery(temp).addClass('shoutboxAdmin'); } }; this.getRandomUsername = () => { let a = ['Small', 'Blue', 'Ugly', 'Big', 'Red', 'Yellow', 'Green', 'Nice', 'Cool']; let b = ['Bear', 'Dog', 'Banana', 'John', 'Joe','Jack', 'Chatter', 'Fish', 'Bird']; let rA = Math.floor(Math.random()*a.length); let rB = Math.floor(Math.random()*b.length); return a[rA] + b[rB]; }; this.addUser = (user) => { if (user.username === '') { user.username = this.getRandomUsername(); } this.updateNumberUsersDisplay(); let avatar = user.avatar; if (avatar !== '') { let image = user.avatar || 'avatars/' + Math.ceil(Math.random() * 29) + '.svg'; avatar = this.getAvatar(image, user.username); } let txt = sprintf(this.traductions.addUser, user.id, user.id, avatar, user.username); jQuery('#shoutBoxUserList').append(txt); }; this.getColor = (username) => { let colors = ['#FFB900', '#D83B01', '#B50E0E', '#E81123', '#B4009E', '#5C2D91', '#0078D7', '#00B4FF', '#008272', '#107C10']; let sum = 0; for (let index in username) { sum += username.charCodeAt(index); } return colors[sum % colors.length]; }; this.getAvatar = (image, username = '') => { let color = this.getColor(username); if (image.indexOf(server) === 0) { let firstLetter = username.charAt(0).toUpperCase() + username.charAt(1).toUpperCase(); return `
${firstLetter}
`; } return sprintf(this.traductions.imageAvatar, image); }; this.getLastMessages(); this.users = []; this.shoutboxSocket = io.connect(server + ':8443'); this.shoutboxSocket.on('connect', () => { let username = this.stripHTML(localStorage.getItem('username')); if (username) { this.myUser.username = this.stripHTML(username); } this.shoutboxSocket.emit('enterRoom', this.myUser); }); this.shoutboxSocket.on('roomEntered', () => { let username = this.stripHTML(localStorage.getItem('username')); if (username) { this.welcome(); } }); this.shoutboxSocket.on('del', (id) => { let temp = `[data-id=${id}]`; jQuery(temp).remove(); }); this.shoutboxSocket.on('ban', (ip) => { let temp = `[data-ip=${ip}}]`; jQuery(temp).remove(); }); this.shoutboxSocket.on('receiveText', (user, message, ip, id) => { this.receiveText(user.username, message, '', 200, user.avatar, ip, id); let snd = new Audio(this.traductions.mp3); snd.play(); }); this.setAdminMode = (password) => { this.myUser.password = password; this.serverMessage(this.traductions.youAreAdminNow); jQuery('#shoutboxAdminLoginBtn').toggle(); }; $shoutBoxContainer.on('click', '.shoutboxBanBtn', (e) => { let $this = jQuery(e.currentTarget); let ip = $this.closest('div').data('ip'); this.shoutboxSocket.emit('ban', ip); let username = jQuery(this).parent().find('.shoutUserText').text(); let msg = sprintf(this.traductions.youBannedUser, username); this.serverMessage(msg); }); $shoutBoxContainer.on('click', '.shoutboxDelBtn', (e) => { let id = jQuery(e.currentTarget).closest('div').data('id'); this.shoutboxSocket.emit('del', id); }); this.shoutboxSocket.on('userChanged', (user) => { let avatar = user.avatar; if (avatar !== '') { avatar = this.getAvatar(avatar, user.username); } let txt = sprintf(this.traductions.addUser, user.id, user.id, avatar, user.username); jQuery('#shoutBoxUser' + user.id).html(txt); }); this.shoutboxSocket.on('setAdminMode', (password) => { this.setAdminMode(password); jQuery('div.shoutText').addClass('shoutboxAdmin'); }); this.shoutboxSocket.on('error', (errorMessage) => { console.log(errorMessage); }); this.shoutboxSocket.on('addUser', (user) => { this.users[user.id] = user; this.addUser(user); }); jQuery(document).on('click', '.shoutboxChangeUsernameBtn', () => { localStorage.clear(); this.myUser.username = ''; let $shoutBoxInput = jQuery('#shoutBoxInput'); $shoutBoxInput.addClass('shoutInputRed'); $shoutBoxInput.val(''); $shoutBoxInput.attr('placeholder', 'Enter new username'); $shoutBoxInput.focus(); }); this.updateNumberUsersDisplay = () => { let len = Object.keys(this.users).length; let text = (len > 1) ? sprintf(this.traductions.usersOnline, len) : sprintf(this.traductions.userOnline, len); jQuery('#shoutBoxHeaderText').text(text); }; this.shoutboxSocket.on('getUsers', (usersInRoom) => { this.users = usersInRoom; this.updateNumberUsersDisplay(); for (let id in usersInRoom) { this.addUser(usersInRoom[id]); } }); this.sortUsers = () => { this.users.sort((user1, user2) => { return user1.avatar < user2.avatar; }); }; this.shoutboxSocket.on('removeUser', (user) => { delete this.users[user.id]; this.updateNumberUsersDisplay(); jQuery(`#shoutBoxUser${user.id}`).remove(); }); $shoutBoxContainer.on('click', '.shoutBoxUserItem', (e) => { e.stopImmediatePropagation(); let userid = jQuery(e.currentTarget).data('id'); this.openPrivateChat(userid); }); this.openPrivateChat = function (userid) { }; this.displayError = ($_element, message) => { $_element.html(message); setTimeout(function () { $_element.empty(); }, 3000); }; jQuery('#shoutboxForgottenBtn').click(() => { $shoutboxForgottenPassword.slideToggle(200); }); jQuery('#shoutboxSaveConfigBtn').click(async (e) => { let $_element = jQuery(e.currentTarget).parent().parent().find('.error'); let shoutboxUserMustRegister = jQuery('#shoutboxUserMustRegister').is(':checked'); let oldPassword = jQuery('#shoutboxChangeOldPassword').val(); let newPassword = jQuery('#shoutboxChangeNewPassword').val(); if (oldPassword.length < 3 || newPassword.length < 3) { this.displayError($_element, 'Invalid Password'); return; } jQuery('.error').empty(); let formData = new FormData(); formData.append('a', 'updateAdmin'); formData.append('shoutboxUserMustRegister', shoutboxUserMustRegister); formData.append('oldPassword', oldPassword); formData.append('newPassword', newPassword); let response = await fetch(this.AJAX, { method: 'POST', body: formData, }); let user = await response.text(); if (user === 'ko') { this.displayError($_element, 'Invalid email/password'); return; } user = JSON.parse(user); this.myUser.password = user.password; this.myUser.shoutboxUserMustRegister = user.shoutboxUserMustRegister; $shoutboxAdminPasswordChangePanel.slideToggle(200); $shoutboxLoginPanel.hide(); }); jQuery('#shoutboxLoginAdminBtn').click(async (e) => { let $_element = jQuery(e.currentTarget).parent().parent().find('.error'); let email = jQuery('#shoutboxEmailAdmin').val(); let password = jQuery('#shoutboxPasswordAdmin').val(); if (password.length < 3) { this.displayError($_element, 'Invalid Password'); return; } var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; if (!re.test(email)) { this.displayError($_element, 'Invalid email'); return; } jQuery('.error').empty(); let formData = new FormData(); formData.append('a', 'loginAdmin'); formData.append('email', email); formData.append('password', password); let response = await fetch(this.AJAX, { method: 'POST', body: formData, }); let user = await response.text(); if (user === 'ko') { this.displayError($_element, 'Invalid email/password'); return; } user = JSON.parse(user); this.myUser.username = 'admin'; this.myUser.password = user.password; this.myUser.shoutboxUserMustRegister = user.shoutboxUserMustRegister; this.myUser.isAdmin = true; this.myUser.avatar = `${server}/avatars/admin.svg`; $shoutboxLoginPanel.hide(); this.serverMessage(this.traductions.youAreAdminNow); localStorage.setItem('email', email); localStorage.setItem('password', password); this.shoutboxSocket.emit('checkPassword', password); }); jQuery('#sendMyPasswordBtn').click(async () => { let $_element = jQuery(this).parent().parent().find('.error'); let re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; let email = jQuery('#shoutboxForgottenEmail').val(); if (!re.test(email)) { this.displayError($_element, 'Invalid email'); return; } let formData = new FormData(); formData.append('a', 'forgottenshoutboxPasswordAdmin'); formData.append('email', email); let response = await fetch(this.AJAX, { method: 'POST', body: formData, }); let res = await response.text(); if (res === 'ko') { this.displayError($_element, 'No such email !'); return; } $shoutboxForgottenPassword.hide(200); }); jQuery('#shoutboxAdminLoginBtn').click((e) => { e.stopImmediatePropagation(); if (this.myUser.isAdmin) { $shoutboxLoginPanel.hide(); $shoutboxAdminPasswordChangePanel.slideToggle(); $shoutboxForgottenPassword.hide(); } else { $shoutboxLoginPanel.slideToggle(200); $shoutboxAdminPasswordChangePanel.hide(); $shoutboxForgottenPassword.hide(); } }); jQuery('#shoutBoxHeader').click(() => { jQuery('#shoutBoxUserList').toggle('fast'); }); // init let formData = new FormData(); formData.append('a', 'getWebmaster'); formData.append('id', room); let response = await fetch(this.AJAX, { method: 'POST', body: formData, }); let data = await response.json(); //console.log(data); if (data['squat']==='squat') { debugger; window.location = server; return; } if (!data['paid']) { debugger; if (parseInt(data.entries) > 50) { this.showAd(); } setInterval(() => { this.showAd(); }, 30000) } }) (room, username, avatar) }; // start the chat if let webmasterid = Number(document.currentScript.src.split('/').pop()); if (Number.isInteger(webmasterid) && webmasterid > 0) { setTimeout(()=> { var chat = new Chat(webmasterid); }, 1000) }