„Benutzer:Wiegels/js/votes.js“ – Versionsunterschied

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen
Inhalt gelöscht Inhalt hinzugefügt
Überschriftenerkennung an beide MediaWiki-Varianten angepasst
Auswertung auch bei Einzelkandidaturen des Mentorenprogramms ermöglicht
(Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt)
Zeile 5: Zeile 5:
B: { min: 50, diff: 0, quote: 7/3 }, // Bürokrat
B: { min: 50, diff: 0, quote: 7/3 }, // Bürokrat
C: { min: 25, diff: 0, quote: 7/3 }, // Checkuser
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
O: { min: 50, diff: 0, quote: 7/3 }, // Oversighter
S: { min: 0, diff: 1, quote: 0 } // Schiedsrichter
S: { min: 0, diff: 1, quote: 0 }, // Schiedsrichter
},
},
wgTitle = mw.config.get('wgTitle');
wgTitle = mw.config.get('wgTitle');
if ($('.jw-votes').length==0 && wgTitle.match(
if ($('.jw-votes').length==0 && wgTitle.match(
RegExp('^('+[
/^(Kandidaturen$|Adminkandidaturen\/|Bürokratenkandidaturen\/|Checkuser\/|Oversightkandidaturen\/|Schiedsgericht\/)/
'Kandidaturen$',
'Adminkandidaturen/',
'Bürokratenkandidaturen/',
'Checkuser/',
'Mentorenprogramm/Abstimmungen',
'Oversightkandidaturen/',
'Schiedsgericht/'
].join('|').replace(/\//, '\/')+')')
)) {
)) {
$('head').append(
$('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/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"/>');
'<link href="/w/index.php?title=Benutzer:Wiegels/css/votes.css&action=raw&ctype=text/css" rel="stylesheet" type="text/css"/>');
if (wgTitle.match(/^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').
$('.mw-parser-output').
prepend('<h2 style="display:none;"><h2><span class="mw-headline">'+wgTitle.replace(/\/.*$/, '')+'</span></h2>').
prepend('<h2 style="display:none;"><h2><span class="mw-headline">'+wgTitle.replace(/\/.*$/, '')+'</span></h2>').
Zeile 26: Zeile 42:
$(this).nextUntil('h3', 'ol').each(function() {
$(this).nextUntil('h3', 'ol').each(function() {
var title = $(this).prevAll('h3, h4').first().find('.mw-headline').text().replace(/ .*$/, '');
var title = $(this).prevAll('h3, h4').first().find('.mw-headline').text().replace(/ .*$/, '');
if (title.match(/^Pro|Contra|Kontra|Enthaltung|Enthaltungen$/)) {
if (title.match(/^Pro|[CK]ontra|Enthaltung(|en)$/)) {
$(this).attr('data-vote', title);
$(this).attr('data-vote', title);
}
}
Zeile 36: Zeile 52:
votes.append('<span class="jw-count jw-count-'+index+'" title="'+$(this).attr('data-vote')+'">'+count+'</span>');
votes.append('<span class="jw-count jw-count-'+index+'" title="'+$(this).attr('data-vote')+'">'+count+'</span>');
});
});
var sum = counts[0]+counts[1];
var sum = (counts[0] ?? 0)+(counts[1] ?? 0);
if (sum>0) {
if (sum>0) {
var names = lists.children().filter(function() { return $(this).text()!='…'; }).
var names = lists.children().filter(function() { return $(this).text()!='…'; }).
Zeile 58: Zeile 74:
'<span class="jw-quote jw-quote-'+index+'" title="'+title+'">'+(''+Math.round(counts[0]/sum*10000)).replace(/(\d\d)$/, ',$1 %')+'</span>');
'<span class="jw-quote jw-quote-'+index+'" title="'+title+'">'+(''+Math.round(counts[0]/sum*10000)).replace(/(\d\d)$/, ',$1 %')+'</span>');
if (multi) {
if (multi) {
$(multi).each(function() { lists.find('li[data-voter="'+this.substr(1)+'"]').addClass('jw-multi-vote'); });
$(multi).each(function() {
lists.find('li[data-voter="'+this.substr(1)+'"]').addClass('jw-multi-vote');
});
}
}
}
}
Zeile 72: Zeile 90:
return (classes=='jw-name' ? value : -('0000'+value.replace(/[ %,]/g, '')).substr(-5));
return (classes=='jw-name' ? value : -('0000'+value.replace(/[ %,]/g, '')).substr(-5));
};
};
$($('.jw-votes').get().sort((a, b) => key(a, classes)>key(b, classes))).each(function() { $('.mw-indicators').append($(this)); });
$($('.jw-votes').get().sort((a, b) => key(a, classes)>key(b, classes))).each(function() {
$('.mw-indicators').append($(this));
});
});
});
}
}

Version vom 24. November 2023, 01:06 Uhr

// 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
        },
        wgTitle = mw.config.get('wgTitle');
    if ($('.jw-votes').length==0 && wgTitle.match(
        RegExp('^('+[
            '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 (wgTitle.match(/^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;"><h2><span class="mw-headline">'+wgTitle.replace(/\/.*$/, '')+'</span></h2>').
            children('h2, .mw-heading2').
            each(function() {
                var key = $(this).find('.mw-headline').text()[0];
                if (key in roles) {
                    $(this).nextUntil('h2, .mw-heading2', 'h3').each(function() {
                        var counts = [],
                            votes = $('<div class="jw-votes jw-indicator"><span class="jw-name">'+$(this).find('.mw-headline').text()+'</span></div>');
                        $(this).nextUntil('h3', 'ol').each(function() {
                            var title = $(this).prevAll('h3, h4').first().find('.mw-headline').text().replace(/ .*$/, '');
                            if (title.match(/^Pro|[CK]ontra|Enthaltung(|en)$/)) {
                                $(this).attr('data-vote', title);
                            }
                        });
                        var lists = $(this).nextUntil('h3', 'ol[data-vote]');
                        lists.each(function(index) {
                            var count = $(this).children(':visible:has(:parent)').length;
                            counts.push(count);
                            votes.append('<span class="jw-count jw-count-'+index+'" title="'+$(this).attr('data-vote')+'">'+count+'</span>');
                        });
                        var sum = (counts[0] ?? 0)+(counts[1] ?? 0);
                        if (sum>0) {
                            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(),
                                multi = names.join('|').replace(/^(.*)$/, '|$1|').match(/\|([^|]+)(?=\|\1\|)/g),
                                role = roles[key],
                                index = (counts[0]<Math.max(role.min, counts[1]+role.diff, counts[1]*role.quote) ? 0 : (key.match(/[AB]/) ? 2 : 1)),
                                title = '= '+counts[0]+'/'+sum+' ('+['nicht gewählt', 'bestanden', 'gewählt'][index]+')';
                            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[0]/sum*10000)).replace(/(\d\d)$/, ',$1 %')+'</span>');
                            if (multi) {
                                $(multi).each(function() {
                                    lists.find('li[data-voter="'+this.substr(1)+'"]').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 classes = $(this).attr('class').replace(/ ?jw-sortable ?/, ''),
                    key = function(element, classes) {
                        var value = $(element).find('.'+classes.replace(/^.* /, '')).text();
                        return (classes=='jw-name' ? value : -('0000'+value.replace(/[ %,]/g, '')).substr(-5));
                    };
                $($('.jw-votes').get().sort((a, b) => key(a, classes)>key(b, classes))).each(function() {
                    $('.mw-indicators').append($(this));
                });
            });
        }
    }
})();