Skip to content

Instantly share code, notes, and snippets.

@yanhaijing
Created November 8, 2013 10:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanhaijing/7369304 to your computer and use it in GitHub Desktop.
Save yanhaijing/7369304 to your computer and use it in GitHub Desktop.
自动follow github帐号
(function ($) {
var
followers = ["zedshaw"];
followeds = [];
function follow(id, callback) {
$.post('https://github.com/users/follow', {target: id}, function(data, textStatus, xhr) {
/*optional stuff to do after success */
callback(id, data);
//console.log("成功follow ", id, "此人共有", data.count, "位粉丝");
}, "json");
}
function unFollow(id, callback) {
$.post('https://github.com/users/unfollow', {target: id}, function(data, textStatus, xhr) {
/*optional stuff to do after success */
callback(id, data);
}, "json");
}
function getFollowers(id, callback) {
$.get("https://github.com/" + id + "/followers", {}, function (data) {
var a = $(data).find(".minibutton:not(.btn-unfollow)");
a.each(function () {
var
id = $(this).attr("data-user");
if (typeof followeds[id] === "undefined") {
followers.push(id);
}
});
console.log(followers);
callback();
}, "html");
}
function getFollower() {
var
id = followers.pop();
if (typeof id !== "undefined") {
followeds[id] = id;
return id;
}
return false;
}
// follow(getFollower(), function (id, data) {
// unFollow(id, function (id, data) {
// getFollowers(id);
// follow(getFollower());
// });
// });
function callback(id, data) {
getFollowers(id, function () {
window.setTimeout(function () {
var
id = getFollower();
if (id) {
follow(id, callback);
}
}, 1000);
});
}
follow(getFollower(), callback);
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment