function MessagePanel(el) { this.el = el; this.render(); } MessagePanel.prototype.render = function() { }; MessagePanel.prototype.pushMessage = function(message) { }; // automatic clearing is not enabled by default. call this method from the constructor to enable MessagePanel.prototype.initClearTimer = function() { var me = this; if (me.removalInterval) clearInterval(me.removalInterval); me.removalInterval = setInterval(function () { var $elements = $(me.el).find('tbody tr'); // limit to 1000 entries in the list since browsers get laggy at some point var toRemove = $elements.length - 1000; if (toRemove <= 0) return; $elements.slice(0, toRemove).remove(); }, 15000); } function WsjtMessagePanel(el) { MessagePanel.call(this, el); this.initClearTimer(); } WsjtMessagePanel.prototype = new MessagePanel(); WsjtMessagePanel.prototype.render = function() { $(this.el).append($( '' + '' + '' + '' + '' + '' + '' + '' + '' + '
UTCdBDTFreqMessage
' )); }; WsjtMessagePanel.prototype.pushMessage = function(msg) { var $b = $(this.el).find('tbody'); var t = new Date(msg['timestamp']); var pad = function (i) { return ('' + i).padStart(2, "0"); }; var linkedmsg = msg['msg']; var matches; var html_escape = function(input) { return $('
').text(input).html() }; if (['FT8', 'JT65', 'JT9', 'FT4', 'FST4', 'FST4W'].indexOf(msg['mode']) >= 0) { matches = linkedmsg.match(/(.*\s[A-Z0-9]+\s)([A-R]{2}[0-9]{2})$/); if (matches && matches[2] !== 'RR73') { linkedmsg = html_escape(matches[1]) + '' + matches[2] + ''; } else { linkedmsg = html_escape(linkedmsg); } } else if (msg['mode'] === 'WSPR') { matches = linkedmsg.match(/([A-Z0-9]*\s)([A-R]{2}[0-9]{2})(\s[0-9]+)/); if (matches) { linkedmsg = html_escape(matches[1]) + '' + matches[2] + '' + html_escape(matches[3]); } else { linkedmsg = html_escape(linkedmsg); } } $b.append($( '' + '' + pad(t.getUTCHours()) + pad(t.getUTCMinutes()) + pad(t.getUTCSeconds()) + '' + '' + msg['db'] + '' + '' + msg['dt'] + '' + '' + msg['freq'] + '' + '' + linkedmsg + '' + '' )); $b.scrollTop($b[0].scrollHeight); } $.fn.wsjtMessagePanel = function(){ if (!this.data('panel')) { this.data('panel', new WsjtMessagePanel(this)); }; return this.data('panel'); };