User:Fubuki風吹/lastEdited.js

/** * Beta version * Adds a modal to show the last diff * Todo: Other namespaces */

$(function {   var lastEdited = $.extend({ position: 'top', size: true, diff: true, comment: true, time: false }, window.lastEdited);   if (mw.config.get('wgNamespaceNumber') == 0 && !$.getUrlVar('diff') && !$.getUrlVar('oldid')) {        $.get(mw.util.wikiScript('api'), { action: 'query', titles: mw.config.get('wgPageName'), prop: 'revisions', rvprop: 'timestamp|user|size|parsedcomment', rvdiffto: 'prev', format: 'json' }, function(data) { console.log(data); for (var i in data.query.pages) break; var rv = data.query.pages[i].revisions[0]; sel = lastEdited.position; if (lastEdited.position == 'top') { sel = '#WikiaPageHeader'; } else if (lastEdited.position == 'bottom') { sel = '.WikiaArticleCategories'; }           var html = ' Last edited by ' + rv.user + ' on ' + new Date(rv.timestamp).toUTCString.slice(0, 16); if (lastEdited.time) { html += ', ' + new Date(rv.timestamp).toUTCString.slice(17, 25) + ' (UTC)'; }           if (lastEdited.diff) { html += ' (diff)'; }           if (lastEdited.comment && rv.parsedcomment) { html += ' Edit summary: ' + rv.parsedcomment; }           if (lastEdited.size) { html += ' Current size: ' + rv.size + ' bytes'; }           html += ' '; if (lastEdited.position == 'top') { $(sel).append(html); } else { $(sel).after(html); }           mw.loader.using(['mediawiki.action.history.diff'], function {                $('.lastEdited-diff').on('click', function { $.showCustomModal('Changes: ' + mw.config.get('wgPageName'), rv.diff['*'], {                       id: 'lastEdited-diff',                        width: 650,                        buttons: [{                            message: 'Link',                            defaultButton: true,                            handler: function {                                $('#lastEdited-diff').closeModal;                                window.open('/?diff=' + rv.diff.to, '_blank');                            }                        }, {                            message: 'Cancel',                            handler: function {                                $('#lastEdited-diff').closeModal;                            }                        }]                    }); });           });        });    } });