MediaWiki:Gadget-recentChanges.js: mudanças entre as edições

Página de Interface do MediaWiki
Sem resumo de edição
Sem resumo de edição
Linha 61: Linha 61:
var diffDate = (currentDate - editDate);
var diffDate = (currentDate - editDate);
var diffDays = diffDate/(1000*60*60*24);
var diffDays = diffDate/(1000*60*60*24);
var diffHours = diffDate/(1000*60*60);
var diffMinutes = diffDate/(1000*60);
var diffSeconds = diffDate/(1000);
if (diffDays > 0) {
if (diffDays > 0) {
Time = Math.floor(diffDays);
Time = Math.floor(diffDays) + 'days ago – ';
} else if (diffHours > 0) {
Time = Math.floor(diffHours) + 'h ago – ';
} else if (diffMinutes > 0) {
Time = Math.floor(diffHours) + 'm ago – ';
} else if (diffSeconds > 0) {
Time = Math.floor(diffHours) + 's ago – ';
} else {
} else {
Time += Math.floor(Math.random() * 10);
Time += Math.floor(Math.random() * 10) + 'm ago – ';
}
}


Linha 75: Linha 84:
                             $('<p>')
                             $('<p>')
                             .addClass('rc-sidebar-user')
                             .addClass('rc-sidebar-user')
                             .text(Time + 'm ago – ')
                             .text(Time)
                             .append(
                             .append(
                                 $('<a>')
                                 $('<a>')

Edição das 01h27min de 3 de julho de 2022

//<nowiki>
/**
 * Adds a recent changes widget to the sidebar
 *
 * @author JaydenKieran
 */
'use strict';

;
(function($, mw) {
    var $prependTo
    var $rcContainer
    var recentChanges
    var $recentChangesDOM

    function init() {
        $prependTo = $('#p-Navigation')
        var api = new mw.Api()

        // Build our container
        $rcContainer = $('<nav>')
            .addClass('vector-menu vector-menu-portal portal')
            .attr('id', 'p-RecentChanges')
            .append(
                $('<h3>').text('Mudanças recentes')
            )

        // Add the container to the sidebar
        $prependTo.after($rcContainer)

        api.get({
                action: "query",
                list: "recentchanges",
                rcprop: "title|timestamp|sizes|user",
                rcnamespace: 0,
                rclimit: "4",
                rctype: "edit|new",
                rcshow: "!bot",
                rctoponly: 1,
                format: "json"
            })
            .done(function(data) {
                if (data.query && data.query.recentchanges) {
                    recentChanges = data.query.recentchanges
                }

                if (recentChanges.length > 0) {
                    var Time = 1;

                    $recentChangesDOM = recentChanges.map(function(rc) {
                    	const timeMatch = rc.timestamp.match(/([0-9]+)-([0-9]+)-([0-9]+)T([0-9]+):([0-9]+):([0-9]+)Z/);
                    	var editYear = timeMatch[1];
                    	var editMonth = timeMatch[2];
                    	var editDay = timeMatch[3];
                    	var editHour = timeMatch[4];
                    	var editMinute = timeMatch[5];
                    	var editSecond = timeMatch[6];
                    	
                    	var editDate = new Date(editYear, (editMonth-1), editDay, editHour, editMinute, editSecond);
						var currentDate = new Date();
						var diffDate = (currentDate - editDate);
						var diffDays = diffDate/(1000*60*60*24);
						var diffHours = diffDate/(1000*60*60);
						var diffMinutes = diffDate/(1000*60);
						var diffSeconds = diffDate/(1000);
						
						if (diffDays > 0) {
							Time = Math.floor(diffDays) + 'days ago – ';
						} else if (diffHours > 0) {
							Time = Math.floor(diffHours) + 'h ago – ';
						} else if (diffMinutes > 0) {
							Time = Math.floor(diffHours) + 'm ago – ';
						} else if (diffSeconds > 0) {
							Time = Math.floor(diffHours) + 's ago – ';
						} else {
							Time += Math.floor(Math.random() * 10) + 'm ago – ';
						}

                        return $('<div>').addClass('rc-sidebar-item').append(
                            $('<a>')
                            .addClass('rc-sidebar-page')
                            .text(' ' + rc.title)
                            .attr('href', new mw.Title(rc.title).getUrl()),
                            $('<p>')
                            .addClass('rc-sidebar-user')
                            .text(Time)
                            .append(
                                $('<a>')
                                .text(rc.user)
                                .attr('href', new mw.Title(rc.user, 2).getUrl())
                            )
                        )
                    })
                } else {
                    $recentChangesDOM = $('<p>').text('No recent changes.')
                }
                $rcContainer.append($recentChangesDOM)
                var $showMore
				$showMore = $('<div>')
                	.addClass('rc-sidebar-item rc-sidebar-more')
                	.append(
                		$('<a>')
                		.addClass('rc-sidebar-page')
                		.text('Ver mais...')
                		.attr('href', '/wiki/Especial:Mudanças recentes')
                )
                $rcContainer.append($showMore)
            })
            .fail(function(_, data) {
                alert(data.error.info)
            });
    }

    mw.loader.using(['mediawiki.util', 'mediawiki.api'], function() {
        $(init)
    })
}(jQuery, mediaWiki));
//</nowiki>