User:Fubuki風吹/chatRC.js

/** * chatRC.js * * Creates an auto-updating recent changes box for chat * CSS at: User:Fubuki風吹/chatRC.css * * @author User:Fubuki風吹 */

$(function {   if (mw.config.get('wgCanonicalSpecialPageName') == 'Chat') {        $(' ', { class: 'chat-rc' }).append('  Recent changes  ').appendTo('body');       importStylesheetPage('User:Fubuki風吹/chatRC.css', 'c');        function updateRC {            $('.chat-rc .loading').show;            $.get(mw.util.wikiScript('api'), { action: 'query', list: 'recentchanges', rcprop: 'user|comment|ids|timestamp|title|sizes|tags', format: 'json' }, function(data) { $('.chat-rc .loading').hide; var html = ''; for (var i = 0; i < data.query.recentchanges.length; i++) { var rc = data.query.recentchanges[i]; html += ' ' + new Date(rc.timestamp).toUTCString.slice(17, 25) + ' ' + rc.title + ' (' + (rc.old_revid ? 'diff' : 'diff') + ' | ' + 'hist). . . . ' + calcBytes(rc.newlen, rc.oldlen) + '. . ' + rc.user + ' (talk | contribs</a>)' + (rc.comment ? ' . . ( ' + rc.comment + ' )' : ''); }               $('.chat-rc-container ul').html(html); $('.timeago').each(function {                   $(this).timeago;                }); $('.chat-rc a').each(function {                   $(this).attr('target', '_blank');                }) });           function calcBytes(newlen, oldlen) {                var bytes = newlen - oldlen,                    str = $(' ').text('(' + bytes + ')');                if (bytes > 0) {                    str.text('(+' + bytes + ')').css('color', 'green');                } else if (bytes < 0) {                    str.css('color', 'red');                } else if (bytes === 0 ) {                    str.css('color', '#ccc');                }            return str[0].outerHTML;            }            setTimeout(updateRC, 30000); //update in every 30 seconds        }        updateRC;    } });