Added filter function for filtering tweets
This commit is contained in:
@@ -104,4 +104,82 @@ var atweet = {
|
|||||||
|
|
||||||
for (let i = 0; i < 2; i++) {
|
for (let i = 0; i < 2; i++) {
|
||||||
tweetCell(atweet, $(".leftcol"));
|
tweetCell(atweet, $(".leftcol"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filter(tweets, bannedWords=[], searchWords=[], likesTop=null, likesBottom=null, retweetsTop=null, retweetsBottom=null, repliesTop=null, repliesBottom=null) {
|
||||||
|
if(bannedWords.length > 0){
|
||||||
|
tweets = filterBannedWords(bannedWords, tweets)
|
||||||
|
}
|
||||||
|
if(searchWords.length > 0){
|
||||||
|
tweets = searchForWords(searchWords, tweets)
|
||||||
|
}
|
||||||
|
if(likesTop != null || likesBottom != null){
|
||||||
|
tweets = filterLikes(likesTop, likesBottom, tweets)
|
||||||
|
}
|
||||||
|
if(retweetsTop != null || retweetsBottom != null){
|
||||||
|
tweets = filterRetweets(retweetsTop, retweetsBottom, tweets)
|
||||||
|
}
|
||||||
|
if(repliesTop != null || repliesBottom != null){
|
||||||
|
tweets = filterReplies(repliesTop, repliesBottom, tweets)
|
||||||
|
}
|
||||||
|
return tweets
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterBannedWords(bannedWords, tweets){
|
||||||
|
for (let i = 0; i < tweets.length; i++) {
|
||||||
|
var tweet = tweets[i]
|
||||||
|
for(let j=0; j < bannedWords.length; j++){
|
||||||
|
if (tweet.text.toLowerCase().includes(bannedWords[j].toLowerCase())){
|
||||||
|
tweets.splice(i, 1)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tweets
|
||||||
|
}
|
||||||
|
|
||||||
|
function searchForWords(searchWords, tweets){
|
||||||
|
for (let i = 0; i < tweets.length; i++) {
|
||||||
|
var tweet = tweets[i]
|
||||||
|
for(let i=0; i < searchWords.length; i++){
|
||||||
|
if (!tweet.text.toLowerCase().includes(searchWords[i].toLowerCase())) {
|
||||||
|
tweets.splice(i, 1)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tweets
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterLikes(likesTop, likesBottom, tweets){
|
||||||
|
for (let i = 0; i < tweets.length; i++) {
|
||||||
|
var tweet = tweets[i]
|
||||||
|
if(tweet.favorite_count >= likesTop || tweet.favorite_count <= likesBottom){
|
||||||
|
tweets.splice(i, 1)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tweets
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterRetweets(retweetsTop, retweetsBottom, tweets){
|
||||||
|
for (let i = 0; i < tweets.length; i++) {
|
||||||
|
var tweet = tweets[i]
|
||||||
|
if(tweet.retweet_count >= retweetsTop || tweet.retweet_count <= retweetsBottom){
|
||||||
|
tweets.splice(i, 1)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tweets
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterReplies(repliesTop, repliesBottom, tweets){
|
||||||
|
for (let i = 0; i < tweets.length; i++) {
|
||||||
|
var tweet = tweets[i]
|
||||||
|
if(tweet.reply_count >= repliesTop || tweet.reply_count <= repliesBottom){
|
||||||
|
tweets.splice(i, 1)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tweets
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user