// Kandidaturen auswerten
(function() {
var roles = {
A: { min: 50, diff: 0, quote: 2/1 }, // Administrator
B: { min: 50, diff: 0, quote: 7/3 }, // Bürokrat
C: { min: 25, diff: 0, quote: 7/3 }, // Checkuser
M: { min: 0, diff: 0, quote: 2/1 }, // Mentor
O: { min: 50, diff: 0, quote: 7/3 }, // Oversighter
S: { min: 0, diff: 1, quote: 0 }, // Schiedsrichter
},
wgPageName = mw.config.get('wgPageName');
if ($('.jw-votes').length==0 && wgPageName.match(
RegExp('^Wikipedia:('+[
'Kandidaturen$',
'Adminkandidaturen/',
'Bürokratenkandidaturen/',
'Checkuser/',
// 'Mentorenprogramm/Abstimmungen',
'Oversightkandidaturen/',
'Schiedsgericht/'
].join('|').replace(/\//, '\/')+')')
)) {
$('head').append(
'<link href="/w/index.php?title=Benutzer:Wiegels/css/indicator.css&action=raw&ctype=text/css" rel="stylesheet" type="text/css"/>'+
'<link href="/w/index.php?title=Benutzer:Wiegels/css/votes.css&action=raw&ctype=text/css" rel="stylesheet" type="text/css"/>');
if (wgPageName.match(/^Wikipedia:Mentorenprogramm\/Abstimmungen(|\/.*)$/)) {
$('#mw-content-text').html(
$('#mw-content-text').html().
replace(/>Aktuelle Kandidaturen</g, '>Mentorenkandidaturen<').
replace(/h3>/g, 'h4>').replace(/h2>/g, 'h3>').replace(/h1>/g, 'h2>'));
$('#mw-content-text h3').each(function() { $(this).parent().after($(this)).remove(); });
}
$('.mw-parser-output').
prepend('<h2 style="display:none;"><span class="mw-headline">'+wgPageName.replace(/^.*:(.*?)(\/.*|)$/, '$1')+'</span></h2>').
children('h2, .mw-heading2').
each(function() {
var key = $(this).find('h2, .mw-headline').text();
if (key in roles) {
$(this).nextUntil('h2, .mw-heading2', 'h3, .mw-heading3').each(function() {
var h3 = $(this);
var counts = ;
var votes = $('<div class="jw-votes jw-indicator"><span class="jw-name">'+$(this).find('h3, .mw-headline').text()+'</span></div>');
$(ontra/, /^Enthaltung(en|)/]).each(function(index, pattern) {
h3.nextUntil('h3, .mw-heading3', 'h4, .mw-heading4').each(function() {
if (matches = $(this).text().match(pattern)) {
var count = 0;
$(this).nextUntil('h4, .mw-heading4', 'ol').each(function() {
count = $(this).children(':visible:has(:parent)').length;
});
counts.push(count);
votes.append('<span class="jw-count jw-count-'+index+'" title="'+matches+'">'+count+'</span>');
}
});
});
var sum = (counts ?? 0)+(counts ?? 0);
if (sum>0) {
var lists = $(this).nextUntil('h3, .mw-heading3', 'ol');
var names = lists.children().filter(function() { return $(this).text()!='…'; }).
map(function() {
var name = $(this).html().
replace(/(^.*?\(CES?T\))*$/, '$1').
replace(/^*<a *?title="Benutzer(?:|in)(?:| Diskussion):(+?)(?:|: *| \(Seite nicht vorhanden\))"*?>.+?<\/a>(.*?\(CES?T\)|)*?$/i, '$1').
replace(/^.*?-- *(.*?) \d\d:\d\d, +? \(CES?T\)*?$/i, '$1');
$(this).attr('data-voter', name);
return name;
}).
toArray().sort();
var multi = names.join('|').replace(/^(.*)$/, '|$1|').match(/\|(+)(?=\|\1\|)/g);
var role = roles;
var index = (counts<Math.max(role.min, counts+role.diff, counts*role.quote) ? 0 : (key.match(//) ? 2 : 1));
var title = '= '+counts+'/'+sum+' ('++')';
votes.append(
(!multi ?
'<span class="jw-multi jw-multi-0" title="Keine mehrfachen Stimmabgaben">0</span>' :
'<span class="jw-multi jw-multi-1" title="Mehrfache Stimmabgaben:\n'+multi.join("\n").replace(/\|/g, '')+'">'+multi.length+'</span>')+
'<span class="jw-quote jw-quote-'+index+'" title="'+title+'">'+(''+Math.round(counts/sum*10000)).replace(/(\d\d)$/, ',$1 %')+'</span>');
if (multi) {
$(multi).each(function() {
lists.find('li').addClass('jw-multi-vote');
});
}
}
$('.mw-indicators').append(votes);
});
}
});
if ($('.jw-votes').length>1) {
$('.jw-votes').find('.jw-name, .jw-count, .jw-quote').addClass('jw-sortable').on('click', function() {
var index = $(this).index();
var value = function(element, index) {
var value = $(element).children().eq(index).text();
return (index==0 ? value : -('0000'+value.replace(//g, '')).substr(-5));
};
$($('.jw-votes').get().sort((a, b) => value(a, index)>value(b, index))).each(function() {
$('.mw-indicators').append($(this));
});
});
}
}
})();