User:Tupka217/wikia.js

// Image size filtering by category // by Bobogoobo // http://community.wikia.com/wiki/Thread:541511 $(document).ready(function {   var cat, rsize, limit, pagelist;    $('.imagesizes').each(function { cat = 'Category:' + $(this).attr('data-category'); rsize = parseInt($(this).attr('data-rsize'), 10); limit = parseInt($(this).attr('data-limit'), 10); pagelist = []; function getList(qcontinue, callback, elem) { var pages, file, cont; $.getJSON('/api.php?action=query&generator=categorymembers&gcmtitle=' +              cat + '&gcmtype=file&prop=imageinfo&iiprop=size&gcmcontinue=' +               qcontinue + '&gcmlimit=max&format=json', function(data) {                pages = data.query.pages;                for (var id in pages) {                    file = pages[id];                    if (file.imageinfo === undefined) {                        continue; //File redirects or other weirdness                    }                    if (file.imageinfo[0].width < rsize) {                        pagelist.push([file.title, file.imageinfo[0].width]);                    }                }                cont = data['query-continue'];                if (cont !== undefined && pagelist.length < limit) {                    getList(cont.categorymembers.gcmcontinue, callback, elem);                } else {                    callback(elem); }           });        }        function printResults(elem) {            pagelist.sort(function(a, b) { return b[1] - a[1]; });           $(elem).html('');            var theList = $(elem).children('ul');            for (var i = 0; i < pagelist.length; i++) {                theList.append('' + pagelist[i][0] + ' - ' + pagelist[i][1] + 'px');           }        }        getList('', printResults, this);    }); });