// RedirectID by Ahecht v0.1.0
$(document).ready(function() {
var titles=[], redirects={};
$( "div.mw-parser-output a.mw-redirect" ).each(function() {titles.push($(this).prop('title'));});
mw.loader.using( [ 'mediawiki.api' ], function () {
function getRedirects() {
var fiftyTitles = titles.splice(0,50);
new mw.Api().get( {
action: 'query',
prop: '',
redirects: 1,
titles: fiftyTitles.join('|')
}).fail(function (e, f) {console.warn(f.error.info);}).done( function (data) {
if (typeof data !== 'undefined' &&
typeof data.query !== 'undefined' &&
typeof data.query.redirects !== 'undefined'
) {
data.query.redirects.forEach(i =>
redirects[i.from] = i.to + ((i.tofragment !== 'undefined') ? (" § " + i.tofragment) : '')
);
if (titles.length > 0) {
getRedirects();
} else {
$( "div.mw-parser-output a.mw-redirect" ).each(function() {
if (typeof redirects[$(this).prop('title')] !== 'undefined') {
$(this).prop('title', $(this).prop('title')+" → "+redirects[$(this).prop('title')]);
}
});
}
}
});
}
getRedirects();
} );
} );