Commented + Tidying Up

This commit is contained in:
jacktjong
2022-11-04 22:40:38 +01:00
parent f840a456af
commit e3e7ad4c7d
5 changed files with 23 additions and 24 deletions

View File

@@ -41,6 +41,7 @@ def words(message):
@event('tweet')
def generate_tweet(ctx, e):
tweet = dict(e.data)
# array of indexes that we want to pop from our tweets; this is to save memory
pops = [
"display_text_range",
"in_reply_to_status_id",

View File

@@ -16,7 +16,6 @@
<link rel="icon" type="image/x-icon" href="./media/logo.png">
</head>
<body>
<!-- <div id="tweet" style="height: 200px;"></div> -->
<div class="container">
<div class="header">
<div class="logo">
@@ -140,25 +139,10 @@
memory: 100
});
block('#pie').piechart();
events.connect('pie', '#pie');
events.connect("tweet", "#latest");
// // create a rolling chart block
// block('#graph').rolling_chart({
// memory: 150,
// chart: {
// yaxis: {
// min: -100,
// max: 100
// },
// xaxis: {
// show: false
// }
// }
// });
events.connect("tweet", "#latest");
events.connect('pie', '#pie');
// // connect sample event to graph
// events.connect('tweet', '#graph');
</script>
</body>
</html>

View File

@@ -9,6 +9,8 @@ let filters = {
sports: []
}
// smartly removes one of the feeds when the window is too narrow for both feeds to be shown properly
// it will swap between the "recent" and "filtered" feeds depending on if a filter is active
function showFeeds() {
if ($(window).width() < 1280) {
if(filters.sports.length === 0 && filters.blockedWords.length === 0 && filters.searchedWords.length === 0 && (filters.sorted == "time" && filters.order == "desc")) {
@@ -24,6 +26,7 @@ function showFeeds() {
}
}
// outputs HTML of a tweet based on the tweet that gets given as input
function tweetCell(tweet) {
const date = new Date(tweet.created_at);
let minutes = date.getMinutes();
@@ -65,6 +68,7 @@ function tweetCell(tweet) {
return cell
}
// applies all filters to a list of tweets
function filterTweets(tweets, bannedWords=[], searchWords=[], sorted, order) {
if(bannedWords.length == 1 && bannedWords[0] == ""){
bannedWords = []
@@ -83,6 +87,7 @@ function filterTweets(tweets, bannedWords=[], searchWords=[], sorted, order) {
return tweets
}
// iterates through each tweet in the list and removes any tweets that contain any of the given words in their text
function filterBannedWords(bannedWords, tweets){
for (let i = 0; i < tweets.length; i++) {
var tweet = tweets[i]
@@ -96,6 +101,7 @@ function filterBannedWords(bannedWords, tweets){
return tweets
}
// iterates through each tweet in the list and removes any tweets that do not contain any of the given words in their text
function searchForWords(searchWords, tweets){
var filteredTweets = []
for (let i = 0; i < tweets.length; i++) {
@@ -112,6 +118,7 @@ function searchForWords(searchWords, tweets){
return filteredTweets.reverse()
}
// sorts through a list of tweets based on an array with options (sort)
function sortTweets(tweets, sort){
if(typeof sort.sortby == 'undefined'){
return tweets

View File

@@ -31,16 +31,19 @@ $(".sport").on("click", function() {
$(this).trigger("selected", [selectedSports.includes(sportName), selectedSports]) // Trigger event
})
//evaluate and alter our page layout when page gets resized
$(window).on("resize", function(){
showFeeds()
});
//evaluate and alter our page layout when page gets loaded
$(window).on("load", function() {
showFeeds()
})
let root = document.querySelector(":root")
//switch between light and dark mode
$(".logo").on("click", function() {
if (root.style.getPropertyValue("--main-bg") === 'snow') {
var audio = new Audio("../media/Chicken.mp3");
@@ -63,6 +66,7 @@ $(".logo").on("click", function() {
}
})
//when a filter event happens, filter and sort tweets, then remove all old HTML and fill with new HTML
$(window).on("filter", function() {
var parent = document.querySelector("#filtered")
var lastTweet = parent.firstChild
@@ -87,6 +91,7 @@ $(window).on("filter", function() {
}
})
// toggle html for the sorting dropdown menu
$(".current-sort").on("click", function() {
$(".sort-dropdown-list li:not(:first-of-type)").toggle()
})
@@ -100,7 +105,7 @@ $(".sort-dropdown-list li:not(:first-of-type)").on("click", function() {
$(".current-sort").html($(this).html())
})
// toggle ordering between ascending or descending and changing arrow to match
$(".order-btn").on("click", function() {
if($(this).html() == "arrow_downward") { // Descending to ascending
$(this).html("arrow_upward")
@@ -113,6 +118,7 @@ $(".order-btn").on("click", function() {
showFeeds()
})
//functions that get called in HTML onchange attributes to trigger filters
function updateSearched(searched){
searched = searched.split(",");
filters.searchedWords = searched;
@@ -134,6 +140,7 @@ function updateSort(sort){
showFeeds()
}
// toggle between paused and unpaused
$(".pause-btn").on("click", function() {
if($(".pause-btn").html() == "pause") { // Unpaused to paused
$(".pause-btn").html("play_arrow")

View File

@@ -87,11 +87,11 @@ block.fn.tweets = function(config) {
}
window.sessionStorage.setItem('tweets', JSON.stringify(tweets));
if(!paused) {
// remove tweets
$list.replaceChildren();
var displayTweets = tweets.reverse().slice(0, options.memory).reverse();
for (i = 0; i < Math.min(options.memory-1, displayTweets.length); i++){
$list.prepend(tweetCell(displayTweets[i]));
// remove tweets
$list.replaceChildren();
var displayTweets = tweets.reverse().slice(0, options.memory).reverse();
for (i = 0; i < Math.min(options.memory-1, displayTweets.length); i++){
$list.prepend(tweetCell(displayTweets[i]));
}
}