User:Bobogoobo/sandbox/SimilarNames.js

// Test script for "ponies with similar names" by Bobogoobo // import on a regular Special:BlankPage $(function {   var $body = $('#mw-content-text').children('p');    var qstr = '/api.php?action=query&list=categorymembers&cmprop=title&cmlimit=max&format=json&cmtitle=';    var names = [];    var threes = ['Big', 'Mr.', 'Ms.', 'Pie', 'Pin', 'Ray', 'Sea', 'Sky', 'Sun', 'Top'];    $.getJSON(qstr + 'Category:Male characters', function(data) { data = data.query.categorymembers; $.each(data, addToList); $.getJSON(qstr + 'Category:Female characters', function(data) {           data = data.query.categorymembers;            $.each(data, addToList);            names.sort;            crunch;        }); });   function addToList(index, value) {        var name = value.title;        if (!/^List of ponies\//.test(name) && names.indexOf(name) === -1) {            names.push(name);        }    }    function crunch {        $body.replaceWith('  ');        var $ul = $('#mw-content-text').find('#similar-names');        $.each(names, function(index, value) { var name = value.replace(/-/g, ' ');// treat hyphen as word separator var subs = [], matches = []; $.each(name.split(' '), function(i, v) {               for (var offset = 3; offset < v.length; offset++) {                    subs.push(v.substring(offset - 3, offset + 1));                }                if (v.length < 4 && threes.indexOf(v) !== -1) {                    subs.push(v);                }            }); $.each(names, function(idx, val) {               if (idx === index) {                    return true;// continue                }                $.each(subs, function(pos, sub) { if (val.indexOf(sub) !== -1) { matches.push(val); return false;// break }               });            });            if (matches.length) { $ul.append(' ' + link(value) + ': ' + matches.join(', ') + ''); }       });    }    function link(name) {        return '' + name + '';    } });