-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
64 lines (55 loc) · 1.3 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const el = require('el');
const tweet2html = require('tweet-html');
const request = require('fetchagent');
module.exports = username => {
const self = {
count,
replies,
retweets,
render: renderTweets
};
const my = {
username,
exclude_replies: 0,
include_rts: 1,
count: 10
};
function count(c) {
my.count = c;
return self;
}
function replies(r) {
my.exclude_replies = r ? 0 : 1; // note the reverse logic
return self;
}
function retweets(r) {
my.include_retweets = r ? 1 : 0;
return self;
}
function renderTweets(container) {
let count = my.count;
const url = '/1.1/statuses/user_timeline.json';
if (my.include_rts !== 1 || my.exclude_replies !== 0) {
count *= 3; // ask for more so that we can still get valid count
}
request
.get(url)
.query({
screen_name: my.username,
count,
exclude_replies: my.exclude_replies,
include_rts: my.include_rts,
trim_user: 1,
include_entities: 1,
tweet_mode: 'extended'
})
.json()
.then(body => {
const tweets = body.slice(0, my.count).map(tweet => {
return el('li.tweet', tweet2html(tweet, my.username));
});
container.innerHTML = el('ul.timeline', tweets.join(''));
});
}
return self;
};