User:Rillke/TicketVerificationList.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
/*global jQuery:false*/
// run this on
// https://commons.wikimedia.org/w/index.php?title=Special:Contributions&dir=prev&offset=20190227092925&limit=500&target=Olaf+Kosinsky&namespace=6&tagfilter=PermissionOTRS&start=&end=
(function($) {
    const l = [];
    $('.mw-contributions-title').each(function(i, elem) {
        const t = $(elem).text().replace(/^File:/, '');
        l.push(t);
    });

    const output = [];
    let listOf10 = [];
    let max = 0;
    l.forEach(function(e, i) {
        listOf10.push(e);
        max = Math.max(e.length, max);
        if ((i + 1) % 10 == 0) {
            output.push(formatGallery(listOf10, max));
            listOf10 = [];
            max = 0;
        }
    });
    if (listOf10.length > 0) {
        output.push(formatGallery(listOf10, max));
    }

    function formatGallery(listOf10, max) {
        return '<gallery>\n' + listOf10.map(function(e, i) {
            return e + '| ' + ' '.repeat(max - e.length) + '????';
        }).join('\n') + '\n</gallery>';
    }

    $('<pre>').appendTo(document.body).text(output.join('\n'));
}(jQuery));