function addVideo(data, position) { var item = $('
'); item.data('id', data.id); item.data('temp', data.temp); var btnstrip = $('').addClass('btn-group video-buttons') .appendTo(item); var title = $('', { href: videoLink(data.id), target: '_blank', class: 'video-title' }).text(data.title).appendTo(item); var duration = $('').addClass('video-time') .text(formatTime(data.duration)) .appendTo(item); if (position === 'first') { item.prependTo($('#playlist')); } else if (position === 'last') { item.appendTo($('#playlist')); } else { var prev = findVideo(position); if (prev.length > 0) { item.insertAfter(prev); } } addVideoButtons(item); return item; } function addVideoButtons(li) { var btns = li.find('.video-buttons'); if (btns.length === 0) { return; } if (can('playlistjump')) { $('').addClass('btn btn-xs btn-default') .html('') .click(function () { SOCKET.emit('playVideo', { id: li.data('id') }); }) .appendTo(btns); } if (can('playlistmove')) { $('').addClass('btn btn-xs btn-default') .html('') .click(function () { SOCKET.emit('moveVideo', { id: li.data('id'), after: CURRENT.id }); }) .appendTo(btns); } if (can('playlistsettemp')) { $('').addClass('btn btn-xs btn-default') .html('') .click(function () { SOCKET.emit('setTemp', { id: li.data('id'), temp: !li.data('temp') }); }) .appendTo(btns); } if (can('playlistsettemp')) { $('').addClass('btn btn-xs btn-default') .html('') .click(function () { SOCKET.emit('deleteVideo', { id: li.data('id'), temp: !li.data('temp') }); }) .appendTo(btns); } } function videoLink(data) { data = data.split(':'); var type = data[0]; var id = data[1]; if (type === void 0 || id === void 0) { return '#'; } switch(type) { case 'yt': return 'http://youtu.be/' + id; default: return '#'; } } function formatTime(seconds) { var h = parseInt(seconds / 3600); var m = parseInt((seconds % 3600) / 60); var s = seconds % 60; var time = ''; if (h !== 0) { h = '' + h; if (h.length < 2) { h = '0' + h; } time += h + ':'; } m = '' + m; if (m.length < 2) { m = '0' + m; } time += m + ':'; s = '' + s; if (s.lengts < 2) { s = '0' + s; } time += s; return time; } function addChatMessage(data, buffer) { var last = buffer.data('lastmessagename'); var div = $('').addClass('chatmsg') .addClass('chatmsg-' + data.name); var timestamp = $('').addClass('chat-timestamp').appendTo(div) .text('[' + new Date(data.time).toTimeString().split(' ')[0] + '] '); var username = $('').addClass('chat-name').appendTo(div); var message = $('').appendTo(div).text(data.message); if (data.msgclass === 'action') { username.text(data.name + ' '); } else { username.text(data.name + ': '); } switch(data.msgclass) { case 'action': timestamp.addClass('action'); username.addClass('action'); message.addClass('action'); break; case 'spoiler': message.addClass('spoiler'); break; case 'greentext': message.addClass('greentext'); break; case 'shout': timestamp.addClass('shout'); username.addClass('shout'); message.addClass('shout'); break; case 'drink': div.addClass('drink'); break; default: break; } if (!data.msgclass.match(/action|shout|drink/) && data.name === last) { if (!data.message.match(/^\s*.+?\s*:/)) { username.remove(); } } buffer.data('lastmessagename', data.name); if (data.flair) { username.addClass(data.flair); } div.appendTo(buffer); } function can(what) { return true; }