-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
187 lines (159 loc) · 7.17 KB
/
index.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!DOCTYPE htm>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
<link rel="stylesheet" href="css/style.css">
<style>
html {
background: url('bg.jpeg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="https://requirejs.org/docs/release/2.3.5/minified/require.js"></script>
</head>
<body onload="toggleSlideMenu()">
<div class="parent">
<nav class="navbar">
<a href="#" onclick="toggleSlideMenu()">
<i id="arrow" class="fas fa-chevron-down fa-lg"></i>
</a>
</nav>
<div id="input-menu" class="input-nav">
<input id="input-hashtag" type="text" placeholder="Enter a hashtag here!">
</input>
<br />
<br />
<a href='#' onclick="changeHashtag()" id="submit-button" class="button">Submit Hashtag</a>
<div><label class="control control-checkbox">
Pull GIFs
<input type="checkbox" id="checkGifs" onchange="isGifsEnabled()" checked="checked" />
<div class="control_indicator"></div>
</label></div>
<a href='#' onclick="clearAll()" id="submit-buttons" class="button_clear">Clear all</a>
<a href="#" class="btn-close" onclick="closeSlideMenu()">
</a>
</div>
</div>
<div id="container">
</div>
<script>
// Has navbar been opened?
$("#input-hashtag").keypress(function(event) {
if (event.keyCode == 13)
$("#submit-button").click();
});
var isToggled = false;
var gifs="yes";
function toggleSlideMenu() {
//If container is open, make height 50, else 0
var heightPX = isToggled ? 0 : 100;
//If container is open, set rotation angle for arrow to 180, else 0
var deg = isToggled ? 0 : 180;
//This is the arrow to be rotated
var arrow = document.getElementById('arrow');
//Actual changing of containr position
document.getElementById('input-menu').style.height = heightPX + 'px';
//rotate chevron
arrow.style.webkitTransform = 'rotate(' + deg + 'deg)';
arrow.style.mozTransform = 'rotate(' + deg + 'deg)';
arrow.style.msTransform = 'rotate(' + deg + 'deg)';
arrow.style.oTransform = 'rotate(' + deg + 'deg)';
arrow.style.transform = 'rotate(' + deg + 'deg)';
//Handle toggling
isToggled = !isToggled;
}
//Important stuff starts here
var tweetIdList = new Array();
var hashtag;
var delay = 0;
var isStarted;
function isGifsEnabled()
{
var checkBox=document.getElementById("checkGifs");
if(checkBox.checked)
{
gifs="yes";
}
else{
gifs="no";
}
}
function changeHashtag() {
hashtag = document.getElementById("input-hashtag").value;
hashtag = hashtag.replace("#", "");
if (!isStarted) {
init();
}
}
function init() {
fetch('http://127.0.0.1:5000/_return_tweets?hashtag=' + hashtag+"&gifs="+gifs)
.then(res => res.json())
.then(res => filterList(res.result)).catch(function(){isStarted=false});
}
//Merge the old and new list of tweets appropriately
function filterList(tweetList) {
if (!(isStarted))
isStarted = true;
var newList = new Array();
tweetList.forEach(function(element) {
found = false;
tweetIdList.forEach(function(oldTweetID) {
if (element.id == oldTweetID) {
found = true;
}
});
if (!found) {
tweetIdList.push(element.id);
newList.push(element);
}
});
loadNewTweetList(newList);
}
function loadNewTweetList(newList) {
for (i = newList.length - 1; i >= 0; i--) {
if (newList[i].imageLink != "") {
var indexOfUrl = newList[i].text.indexOf("pic.twitter.com");
newList[i].text = newList[i].text.slice(0, indexOfUrl);
}
visualizeTweet(newList[i].id.toString(), newList[i].username, newList[i].text, newList[i].imageLink, newList[i].profilephoto,newList[i].videoLink);
delay += 200;
}
delay = 0;
setTimeout(function() {
init()
}, 1000);
}
function visualizeTweet(id, username, content, imageLink, profilephoto,videoLink) {
setTimeout(function() {
if(videoLink!="" && videoLink.indexOf(".m3u8")==-1)
{
var type="type/mp4"
document.getElementById("container").insertAdjacentHTML('afterend', '<div class="tweet" id="#' + id + '"> <img src="' + profilephoto + '" alt="" class="profile-photo" onclick="hideTweet("#' + id + '")"></img> <div id="tests" class="speech-bubble"> <strong id="username" style="text-align: left">' + username + '</strong><br /> ' + content + '<br /><div id="image' + id + '" class="image-container"><video class="tweet-image" src="' + videoLink + '" loop autoplay type="'+type+'"></video></div></div></div>');
}
else{
document.getElementById("container").insertAdjacentHTML('afterend', '<div class="tweet" id="#' + id + '"> <img src="' + profilephoto + '" alt="" class="profile-photo" onclick="hideTweet("#' + id + '")"></img> <div id="tests" class="speech-bubble"> <strong id="username" style="text-align: left">' + username + '</strong><br /> ' + content + '<br /><div id="image' + id + '" class="image-container"><img class="tweet-image" src="' + imageLink + '"></img></div></div></div>');
}
setTimeout(function() {
if (imageLink == "" && videoLink=="")
document.getElementById("image" + id).style.display = "none";
document.getElementById("#" + id).style.opacity = "1";
}, 10);
}, delay);
}
function hideTweet(id) {
console.log(id + "");
document.getElementById(id).style.display = "none";
}
function clearAll() {
for (i = 0; i < tweetIdList.length; i++) {
document.getElementById("#" + tweetIdList[i]).style.display = "none";
}
}
</script>
</body>
</hml>