Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Twitterの複数の企業IDでフォロワーがどのくらい重複しているか.. - 人力検索はてな http://q.hatena.ne.jp/1321238733
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
var list = [];
$('#btn').click(function() {
list = [];
$('#counter, #result').text('');
var p1 = $('#p1').val();
var p2 = $('#p2').val();
getFollowers(p1, -1, []);
getFollowers(p2, -1, []);
});
$('body').bind('create_list', function(event, id, followers){
list.push(followers);
if (list.length >= 2) {
$('body').trigger('comp_list');
}
});
$('body').bind('comp_list', function(){
if (list[0].length > list[1].length)
var t1 = list[1], t2 = list[0];
else
var t1 = list[0], t2 = list[1];
var result = t1.filter(function(e) {
return t2.contains(e);
});
$('#counter').text(result.length);
$('#result').text(result.join());
});
function getFollowers(id, cursor, followers) {
$.ajax({
url: 'http://api.twitter.com/1/followers/ids.json',
dataType: 'jsonp',
data: {
screen_name: id,
cursor: (cursor == -1) ? -1 : cursor,
},
success: function(data, textStatus, jqXHR){
console.log(data)
console.log(jqXHR)
followers = followers.concat(data.ids);
if (data.next_cursor != 0)
getFollowers(id, data.next_cursor, followers);
else
$('body').trigger('create_list', [id, followers]);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
}
});
}
});
Array.prototype.contains = function (element) {
for (var i = 0, n = this.length; i < n; i++) {
if (this[i] == element) {
return true;
}
}
return false;
}
</script>
</head>
<body>
<input id="p1" type="text" value="Starbucks_J" />
&
<input id="p2" type="text" value="Tullys_jp" />
<input id="btn" type="button" value="重複したフォロワーを数える"/>
<div>
<p id="counter"></p>
<textarea id="result"></textarea>
<div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.