更多语言
更多操作
(Added Recent Changes sidebar gadget JavaScript code for Chinese) |
小 (Imported from Russian wiki) |
||
第23行: | 第23行: | ||
.attr('id', 'p-RecentChanges') | .attr('id', 'p-RecentChanges') | ||
.append( | .append( | ||
$('<h3>').text(' | $('<h3>').text('Свежие правки') | ||
) | ) | ||
第36行: | 第36行: | ||
rclimit: "5", | rclimit: "5", | ||
rctype: "edit|new", | rctype: "edit|new", | ||
rcshow: "!bot | rcshow: "!bot", | ||
rctoponly: 1, | rctoponly: 1, | ||
format: "json" | format: "json" | ||
第48行: | 第48行: | ||
var Time = 1; | var Time = 1; | ||
$recentChangesDOM = recentChanges.map(function(rc) { | $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 editYear = timeMatch[1]; | ||
var editMonth = timeMatch[2]; | var editMonth = timeMatch[2]; | ||
第66行: | 第66行: | ||
if (diffDays > 0) { | if (diffDays > 0) { | ||
Time = diffDays + ' | Time = diffDays + 'd atrás – '; | ||
} else if (diffHours > 0) { | } else if (diffHours > 0) { | ||
Time = diffHours + ' | Time = diffHours + 'h atrás – '; | ||
} else if (diffMinutes > 0) { | } else if (diffMinutes > 0) { | ||
Time = diffMinutes + ' | Time = diffMinutes + 'm atrás – '; | ||
} else if (diffSeconds > 0) { | } else if (diffSeconds > 0) { | ||
Time = diffSeconds + ' | Time = diffSeconds + 's atrás – '; | ||
} else { | } else { | ||
Time = 1 + Math.floor(Math.random() * 10) + ' | Time = 1 + Math.floor(Math.random() * 10) + 'm atrás – '; | ||
} | } | ||
第93行: | 第93行: | ||
}) | }) | ||
} else { | } else { | ||
$recentChangesDOM = $('<p>').text(' | $recentChangesDOM = $('<p>').text('Нет свежих правок.') | ||
} | } | ||
$rcContainer.append($recentChangesDOM) | $rcContainer.append($recentChangesDOM) | ||
var $showMore | var $showMore | ||
第103行: | 第102行: | ||
$('<a>') | $('<a>') | ||
.addClass('rc-sidebar-page') | .addClass('rc-sidebar-page') | ||
.text(' | .text('Ver mais...') | ||
.attr('href', '/wiki/ | .attr('href', '/wiki/Служебная:Свежие правки') | ||
) | ) | ||
$rcContainer.append($showMore) | $rcContainer.append($showMore) |
2022年8月11日 (四) 00:08的版本
//<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('Свежие правки')
)
// Add the container to the sidebar
$prependTo.after($rcContainer)
api.get({
action: "query",
list: "recentchanges",
rcprop: "title|timestamp|sizes|user",
rcnamespace: 0,
rclimit: "5",
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();
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 = diffDays + 'd atrás – ';
} else if (diffHours > 0) {
Time = diffHours + 'h atrás – ';
} else if (diffMinutes > 0) {
Time = diffMinutes + 'm atrás – ';
} else if (diffSeconds > 0) {
Time = diffSeconds + 's atrás – ';
} else {
Time = 1 + Math.floor(Math.random() * 10) + 'm atrás – ';
}
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('Нет свежих правок.')
}
$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/Служебная:Свежие правки')
)
$rcContainer.append($showMore)
})
.fail(function(_, data) {
alert(data.error.info)
});
}
mw.loader.using(['mediawiki.util', 'mediawiki.api'], function() {
$(init)
})
}(jQuery, mediaWiki));
//</nowiki>