From 4fa54fe1f1ff382e500bd671e996bf4c7024a290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Hn=C3=A1t?= Date: Wed, 2 Nov 2022 11:42:11 +0100 Subject: [PATCH 1/2] Added filter function for filtering tweets --- dashboard_static/js/code.js | 80 ++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/dashboard_static/js/code.js b/dashboard_static/js/code.js index 2fea0fc..abddcb1 100644 --- a/dashboard_static/js/code.js +++ b/dashboard_static/js/code.js @@ -104,4 +104,82 @@ var atweet = { for (let i = 0; i < 2; i++) { tweetCell(atweet, $(".leftcol")); -} \ No newline at end of file +} + +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 +} From abb8c77e3fd49f161ac0775e71eea9273d970263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Hn=C3=A1t?= Date: Wed, 2 Nov 2022 11:42:29 +0100 Subject: [PATCH 2/2] Changed the number of tweets stored in local memory --- dashboard_static/lib/tweets.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dashboard_static/lib/tweets.js b/dashboard_static/lib/tweets.js index 6cc4642..c8f89a1 100644 --- a/dashboard_static/lib/tweets.js +++ b/dashboard_static/lib/tweets.js @@ -83,7 +83,8 @@ block.fn.tweets = function(config) { tweets = window.sessionStorage.getItem('tweets'); tweets = JSON.parse(tweets); tweets.push(tweet); - if(tweets.length >= options.memory) { + var localMemory = 100; + if(tweets.length >= localMemory) { tweets.shift(); } window.sessionStorage.setItem('tweets', JSON.stringify(tweets));