User:Dorumin/seconds.​js

//  // @requires seconds.css importArticle({   type: 'script',    article: 'u:dev:MediaWiki:Chat-js.js' });

mw.hook('dev.chat.render').add(function {   function bind_messages(fn) {        mainRoom.model.chats.bind('afteradd', fn);        mainRoom.model.privateUsers.bind('add', function(u) { var id = u.attributes.roomId, room = mainRoom.chats.privates[id], key = room.model.privateRoom.attributes.users.filter(function(n) { return n != wgUserName }).sort.join('|'); room.model.chats.bind('afteradd', fn); room.socket.bind('initial', $.debounce(0, function { if (window.PrivateHistory && PrivateHistory.rooms[key]) { PrivateHistory.rooms[key].model.chats.bind('afteradd', fn); }           }));        });    }

bind_messages(function(model) {       if (model.attributes.isInlineAlert) return;        var seconds = document.createElement('span'),        day = document.createElement('span'),        entry = document.getElementById('entry-' + model.cid) || PrivateHistory.frag.getElementById('entry-' + model.cid),        time = entry.querySelector('.time'),        d = new Date(model.attributes.timeStamp),        now = new Date,        today = false,        yesterday = false;        seconds.className = 'seconds';        seconds.textContent = ':' + d.getSeconds.toString.padStart(2, '0');        day.className = 'day';        if (d.toDateString == now.toDateString || Math.abs(now - day) < 60000) {            today = true;        } else {            now.setDate(now.getDate - 1);            if (d.toDateString == now.toDateString) {                yesterday = true;            }        }        if (today) { day.textContent = 'Today at '; day.className += ' today'; } else if (yesterday) { day.textContent = 'Yesterday at '; day.className += ' yesterday'; } else { day.textContent = d.getFullYear + '/' + d.getMonth + '/' + d.getDate + ' at '; day.className += ' date'; }       time.appendChild(seconds); time.insertBefore(day, time.firstChild); }); });