var subs = []; var mods = []; var s = ''; Array.from(document.querySelectorAll('.community-list [data-prefixed-name]')) .slice(0, 250) .map(el => ({ 'sub': '/' + el.getAttribute('data-prefixed-name'), 'subscriberCount': el.getAttribute('data-subscribers-count'), })) .map(({sub, subscriberCount}) => () => new Promise((resolve, reject) => { subs[sub] = {sub, subscriberCount, modNames: []}; fetch(window.location.origin + sub + '/about/moderators.json') .then(res => res.json()) .then(modsList => { console.log('Fetching mod list for ' + sub); subs[sub].modNames = modsList.data.children.map(u => '/u/' + u.name); setTimeout(resolve, 1000); }) })) .reduce((chain, step) => chain.then(step), Promise.resolve()) .then(() => { mods = []; Object.values(subs).forEach(sub => sub.modNames.forEach(modName => mods[modName] = {modName, subsModded: [], totalSubscriberCount: 0})) Object.values(subs).forEach(sub => sub.modNames.forEach(modName => { mods[modName].subsModded.push(sub.sub); mods[modName].totalSubscriberCount += parseInt(sub.subscriberCount); })); s = ( Object.values(mods) .filter(mod => !mod.modName.match(/(auto|bot|helper)/i)) .sort((a,b) => b.subsModded.length - a.subsModded.length) .slice(0, 20) .map(mod => ( ' - **[' + mod.modName + '](' + 'https://old.reddit.com/' + mod.modName + '/?sort=controversial)** ' + 'mods ' + mod.subsModded.length + '/' + Object.values(subs).length + ' subs ' + 'with ' + mod.totalSubscriberCount + ' total subscribers ' + '(e.g. ' + mod.subsModded.slice(0, 5).map(subName => '[' + subName + '](' + 'https://old.reddit.com' + subName + ')').join(', ') + ')' )) .join('\n') ); console.log(s); console.log('done'); }); // and then you can copy(s) after it's done