More languages
More actions
(Collectivized code from Runescape Wiki) |
m (Changed text) |
||
Line 23: | Line 23: | ||
.attr('id', 'p-RecentChanges') | .attr('id', 'p-RecentChanges') | ||
.append( | .append( | ||
$('<h3>').text(' | $('<h3>').text('Recent changes') | ||
) | ) | ||
Revision as of 17:29, 1 July 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('Recent changes')
)
// 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 placeholderTime = 1;
$recentChangesDOM = recentChanges.map(function(rc) {
placeholderTime += Math.floor(Math.random() * 10);
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(placeholderTime + 'm ago – ')
.append(
$('<a>')
.text(rc.user)
.attr('href', new mw.Title(rc.user, 2).getUrl())
)
)
})
} else {
$recentChangesDOM = $('<p>').text('No recent changes.')
}
$rcContainer.append($recentChangesDOM)
})
.fail(function(_, data) {
alert(data.error.info)
});
}
mw.loader.using(['mediawiki.util', 'mediawiki.api'], function() {
$(init)
})
}(jQuery, mediaWiki));
//</nowiki>