-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter-archive.html
63 lines (56 loc) · 2.06 KB
/
twitter-archive.html
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
---
layout: page
title: Twitter archive
---
<div id="twitter-archive"></div>
<div id="loading" style="display: none;">Loading...</div>
<button id="load-tweets-button" onclick="javascript:loadTweets()">Load tweets</button>
<script>
function loadTweets() {
const loadingDiv = document.getElementById('loading');
const loadTweets = new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = '/public/js/twitter/data/tweets.js';
document.body.appendChild(script);
resolve();
});
const waitForTweets = new Promise((resolve, reject) => {
const interval = setInterval(() => {
if (window.tweets) {
clearInterval(interval);
resolve();
}
}, 500);
});
loadTweets
.then(() => {
loadingDiv.style.display = 'block'
}).then(() => {
const button = document.getElementById('load-tweets-button');
button.style.display = 'none';
})
.then(() => waitForTweets)
.then(() => {
const tweetsDiv = document.getElementById('twitter-archive');
const tweets = window.tweets;
tweets.forEach(tweet => {
const {
tweet: {
created_at: createdAt,
full_text: fullText
}
} = tweet;
const tweetDiv = document.createElement('div');
const tweetText = `
created at: ${createdAt}: <br>
${fullText}
`
tweetDiv.innerHTML = tweetText;
tweetsDiv.appendChild(tweetDiv);
tweetDiv.appendChild(document.createElement('hr'));
});
}).then(() => {
loadingDiv.style.display = 'none';
})
}
</script>