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');       mw.util.addCSS('.chat-rc {' + 'position: fixed;' + 'top: -235px;' + 'left: 460px;' + 'width: 400px;' + 'height: 250px;' + 'background: #fff;' + 'border-radius: 5px;' + 'transition: .4s all linear;' + 'padding: 10px;' + 'z-index: 9999;' + 'border: 1px solid #ccc;' + '}' +       '.chat-rc:hover {' + 'top: 5px;' + '}' +       '.chat-rc-container {' + 'height: 223px;' + 'border-bottom: 1px solid #ccc;' + 'margin-bottom: 5px;' + 'overflow-y: auto;' + 'color: rgb(58,58,58);' + '}' +       '.chat-rc-container ul {' + 'list-style: square;' + 'margin: 0 10px 0 20px;' + '}' +       '.chat-rc-header {' + 'color: #000;' + 'font-size: 20px;' + 'text-align: center;' + 'line-height: 28px;' + '}');       function updateRC {            $('.chat-rc .loading').show;            $.get(mw.util.wikiScript('api'), { action: 'query', list: 'recentchanges', rcprop: 'user|parsedcomment|ids|timestamp|title|sizes|tags', format: 'json' }, function(data) { $('.chat-rc .loading').hide; var html = ' '; $('.chat-rc-container').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;    } });