Más idiomas
Más acciones
Nota: Después de publicar, quizás necesite actualizar la caché de su navegador para ver los cambios.
- Firefox/Safari: Mantenga presionada la tecla Shift mientras pulsa el botón Actualizar, o presiona Ctrl+F5 o Ctrl+R (⌘+R en Mac)
- Google Chrome: presione Ctrl+Shift+R (⌘+Shift+R en Mac)
- Internet Explorer/Edge: mantenga presionada Ctrl mientras pulsa Actualizar, o presione Ctrl+F5
- Opera: Presiona Ctrl+F5.
/**
* Recent changes sidebar gadget for Citizen skin
* Originally created by @author JaydenKieran (RunescapeWiki), adapted to the Citizen skin by Forte (ProleWiki)
**/
"use strict";
(function($, mw) {
var $prependTo;
var $rcContainer;
var recentChanges;
var $recentChangesDOM;
var $final;
function init() {
$prependTo = $('#p-navigation');
var api = new mw.Api();
$final = $('<ul>').after($rcContainer);
var $div = $('<div>').text('Cambios recientes')
.addClass('citizen-menu__heading');
$rcContainer = $('<nav>')
.addClass('citizen-menu mw-portlet mw-portlet-RecentChanges')
.attr('id', 'p-RecentChanges')
.append($div)
.append($final);
// Add the container to the sidebar
$prependTo.after($rcContainer)
api.get({
action: "query",
list: "recentchanges",
rcprop: "title|timestamp|sizes|user",
rcnamespace: "0|3000",
rclimit: "5",
rctype: "edit|new",
rcshow: "!bot|!redirect",
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();
currentDate = currentDate.getTime() + (currentDate.getTimezoneOffset() * 60000)
var diffDate = currentDate - editDate;
var diffDays = Math.floor(diffDate/(1000*60*60*24));
var diffHours = Math.floor(diffDate/(1000*60*60));
var diffMinutes = Math.floor(diffDate/(1000*60));
var diffSeconds = Math.floor(diffDate/(1000));
if (diffDays > 0) {
Time = 'hace' + diffDays + 'd – ';
} else if (diffHours > 0) {
Time = 'hace' + diffHours + 'h – ';
} else if (diffMinutes > 0) {
Time = 'hace' + diffMinutes + 'm – ';
} else if (diffSeconds > 0) {
Time = 'hace' + diffSeconds + 's – ';
} else {
Time = 1 + Math.floor(Math.random() * 10) + 'm ago – ';
}
var $a = $('<a>')
.css('white-space', 'normal')
.addClass('rc-sidebar-page')
.css({
'padding-top': '0.25em',
'padding-bottom': '0.25em'
})
.text(' ' + rc.title)
.attr('href', new mw.Title(rc.title).getUrl());
var $p = $('<p>')
.css({
'text-align': 'right',
'margin-right': '2.5em'
})
.addClass('rc-sidebar-user')
.text(Time)
.append(
$('<a>')
.css({
'display' : 'contents',
'padding' : '0px'
})
.text(rc.user)
.attr('href', new mw.Title(rc.user, 2).getUrl())
);
return $('<li>').addClass('mw-list-item').append($a,$p);
})
} else {
$recentChangesDOM = $('<p>').text('Sin cambios recientes.')
}
$final.append($recentChangesDOM)
var $showMore
$showMore = $('<div>')
.addClass('rc-sidebar-item rc-sidebar-more')
.append(
$('<a>')
.addClass('rc-sidebar-page')
.text('Ver más...')
.attr('href', '/wiki/Especial:CambiosRecientes')
)
$final.append($showMore)
})
.fail(function(_, data) {
alert(data.error.info)
});
}
mw.loader.using(['mediawiki.util', 'mediawiki.api'], function() {
$(init)
})
}(jQuery, mediaWiki));