Last active
August 29, 2015 14:06
-
-
Save SleepWalker/e6f54de8dfa625b37974 to your computer and use it in GitHub Desktop.
Simple script to search developers by the Location (city, country) in the "stargazers" list of repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
/** | |
* Simple script to search developers by the Location (city, country) in the "stargazers" list of repository. | |
* To use it, simple go to the `/[your-repo]/stargazers` url, open console and execute this script. You will | |
* see profile links in the console (console.info()) output | |
* | |
* https://gist.github.com/SleepWalker/e6f54de8dfa625b37974 | |
*/ | |
var usersParsed = 0, | |
found = 0; | |
function scanPage(page, searchedLocation) { | |
$(page).find('.gravatar').closest('a').each(function() { | |
checkIfUserHasLocation(this.href, searchedLocation); | |
}); | |
scanNextPage(page); | |
} | |
function checkIfUserHasLocation(url, loc) { | |
getPage(url, function(data) { | |
var country = getUserCountry(data); | |
usersParsed++; | |
if(country.toLowerCase().indexOf(loc.toLowerCase()) > -1) { | |
console.info(url); | |
found++; | |
} | |
}); | |
} | |
function checkIfUserHasEmail(url) { | |
getPage(url, function(data) { | |
var email = getUserEmail(data); | |
usersParsed++; | |
if(email) { | |
console.info(url + ":" + email); | |
found++; | |
} | |
}); | |
} | |
function getPage(url, callback) { | |
$.ajax(url, { | |
success: callback, | |
beforeSend: function(xhr) { | |
xhr.setRequestHeader('X-Requested-With', {toString: function(){ return ''; }}); | |
} | |
}); | |
} | |
function getUserCountry(page) { | |
return $(page).find(".vcard [itemprop=homeLocation]").text(); | |
} | |
function getUserEmail(page) { | |
return $(page).find(".vcard .email").text(); | |
} | |
function scanNextPage(page) { | |
var nextPage = $(page).find('.pagination').children().eq(1)[0]; | |
if(nextPage.tagName != 'A') { | |
finishMessage(); | |
return; | |
} | |
getPage(nextPage.href, scanPage); | |
} | |
function finishMessage() { | |
alert('Finished.\nUsers Parsed: ' + usersParsed + '\nFound matches: ' + found); | |
usersParsed = found = 0; | |
} | |
window.ghCrawler = { | |
searchByCountry: function(country) { | |
scanPage(document.body.innerHTML, country); | |
}, | |
// profileUrls — array of urls | |
getEmailsFromProfiles: function(profileUrls) { | |
profileUrls = profileUrls instanceof Array ? profileUrls : [profileUrls]; | |
for(var i = 0; i < profileUrls.length; i++) { | |
var curUrl = profileUrls[i]; | |
checkIfUserHasEmail(curUrl); | |
} | |
// TODO: finishMessage(); | |
}, | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment