Last active
December 2, 2018 12:09
-
-
Save t-kuni/eea17aa5a6d9565bfb468244a1985071 to your computer and use it in GitHub Desktop.
ツイッターの検索結果(ツイート一覧)のユーザをまとめてフォローする
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 focusTweet() { | |
$tweet = this; | |
return new Promise(function(resolve, reject) { | |
$avatar = $tweet.find("img.avatar"); | |
$avatar.mouseover(); | |
resolve($tweet); | |
}); | |
} | |
// プロフィールがフェードインするまで待機 | |
function getProfile($tweet) { | |
return new Promise(function(resolve, reject) { | |
setTimeout(function() { | |
$profile = $("div#profile-hover-container"); | |
//alert($profile.find("a.fullname").text()); | |
resolve({ | |
profile: $profile, | |
tweet: $tweet, | |
}); | |
}, 1000); | |
}); | |
} | |
// フォローボタンを押下 | |
function follow(params) { | |
$profile = params.profile; | |
$tweet = params.tweet; | |
return new Promise(function(resolve, reject) { | |
$btn = $profile.find("span.user-actions-follow-button"); | |
if (!$btn.parent().hasClass("following")) { | |
$btn.click(); | |
//ついでにいいねする | |
$tweet.find("button.ProfileTweet-actionButton.js-actionFavorite").click(); | |
} | |
resolve(); | |
}); | |
} | |
var $tweets = $('li[data-item-type="tweet"]'); | |
var p = Promise.resolve(); | |
$tweets.each(function(i) { | |
$tweet = $(this); | |
p = p.then(focusTweet.bind($tweet)).then(getProfile).then(follow); | |
}); | |
p.then(function() { | |
return new Promise(function(resolve, reject) { | |
setTimeout(function() { | |
alert('終了しました') | |
resolve(); | |
}, 1000); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment