Commented + Tidying Up
This commit is contained in:
@@ -41,6 +41,7 @@ def words(message):
|
|||||||
@event('tweet')
|
@event('tweet')
|
||||||
def generate_tweet(ctx, e):
|
def generate_tweet(ctx, e):
|
||||||
tweet = dict(e.data)
|
tweet = dict(e.data)
|
||||||
|
# array of indexes that we want to pop from our tweets; this is to save memory
|
||||||
pops = [
|
pops = [
|
||||||
"display_text_range",
|
"display_text_range",
|
||||||
"in_reply_to_status_id",
|
"in_reply_to_status_id",
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
<link rel="icon" type="image/x-icon" href="./media/logo.png">
|
<link rel="icon" type="image/x-icon" href="./media/logo.png">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<!-- <div id="tweet" style="height: 200px;"></div> -->
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<div class="logo">
|
<div class="logo">
|
||||||
@@ -140,25 +139,10 @@
|
|||||||
memory: 100
|
memory: 100
|
||||||
});
|
});
|
||||||
block('#pie').piechart();
|
block('#pie').piechart();
|
||||||
events.connect('pie', '#pie');
|
|
||||||
events.connect("tweet", "#latest");
|
|
||||||
|
|
||||||
// // create a rolling chart block
|
events.connect("tweet", "#latest");
|
||||||
// block('#graph').rolling_chart({
|
events.connect('pie', '#pie');
|
||||||
// memory: 150,
|
|
||||||
// chart: {
|
|
||||||
// yaxis: {
|
|
||||||
// min: -100,
|
|
||||||
// max: 100
|
|
||||||
// },
|
|
||||||
// xaxis: {
|
|
||||||
// show: false
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// // connect sample event to graph
|
|
||||||
// events.connect('tweet', '#graph');
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -9,6 +9,8 @@ let filters = {
|
|||||||
sports: []
|
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() {
|
function showFeeds() {
|
||||||
if ($(window).width() < 1280) {
|
if ($(window).width() < 1280) {
|
||||||
if(filters.sports.length === 0 && filters.blockedWords.length === 0 && filters.searchedWords.length === 0 && (filters.sorted == "time" && filters.order == "desc")) {
|
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) {
|
function tweetCell(tweet) {
|
||||||
const date = new Date(tweet.created_at);
|
const date = new Date(tweet.created_at);
|
||||||
let minutes = date.getMinutes();
|
let minutes = date.getMinutes();
|
||||||
@@ -65,6 +68,7 @@ function tweetCell(tweet) {
|
|||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// applies all filters to a list of tweets
|
||||||
function filterTweets(tweets, bannedWords=[], searchWords=[], sorted, order) {
|
function filterTweets(tweets, bannedWords=[], searchWords=[], sorted, order) {
|
||||||
if(bannedWords.length == 1 && bannedWords[0] == ""){
|
if(bannedWords.length == 1 && bannedWords[0] == ""){
|
||||||
bannedWords = []
|
bannedWords = []
|
||||||
@@ -83,6 +87,7 @@ function filterTweets(tweets, bannedWords=[], searchWords=[], sorted, order) {
|
|||||||
return tweets
|
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){
|
function filterBannedWords(bannedWords, tweets){
|
||||||
for (let i = 0; i < tweets.length; i++) {
|
for (let i = 0; i < tweets.length; i++) {
|
||||||
var tweet = tweets[i]
|
var tweet = tweets[i]
|
||||||
@@ -96,6 +101,7 @@ function filterBannedWords(bannedWords, tweets){
|
|||||||
return 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){
|
function searchForWords(searchWords, tweets){
|
||||||
var filteredTweets = []
|
var filteredTweets = []
|
||||||
for (let i = 0; i < tweets.length; i++) {
|
for (let i = 0; i < tweets.length; i++) {
|
||||||
@@ -112,6 +118,7 @@ function searchForWords(searchWords, tweets){
|
|||||||
return filteredTweets.reverse()
|
return filteredTweets.reverse()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sorts through a list of tweets based on an array with options (sort)
|
||||||
function sortTweets(tweets, sort){
|
function sortTweets(tweets, sort){
|
||||||
if(typeof sort.sortby == 'undefined'){
|
if(typeof sort.sortby == 'undefined'){
|
||||||
return tweets
|
return tweets
|
||||||
|
|||||||
@@ -31,16 +31,19 @@ $(".sport").on("click", function() {
|
|||||||
$(this).trigger("selected", [selectedSports.includes(sportName), selectedSports]) // Trigger event
|
$(this).trigger("selected", [selectedSports.includes(sportName), selectedSports]) // Trigger event
|
||||||
})
|
})
|
||||||
|
|
||||||
|
//evaluate and alter our page layout when page gets resized
|
||||||
$(window).on("resize", function(){
|
$(window).on("resize", function(){
|
||||||
showFeeds()
|
showFeeds()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//evaluate and alter our page layout when page gets loaded
|
||||||
$(window).on("load", function() {
|
$(window).on("load", function() {
|
||||||
showFeeds()
|
showFeeds()
|
||||||
})
|
})
|
||||||
|
|
||||||
let root = document.querySelector(":root")
|
let root = document.querySelector(":root")
|
||||||
|
|
||||||
|
//switch between light and dark mode
|
||||||
$(".logo").on("click", function() {
|
$(".logo").on("click", function() {
|
||||||
if (root.style.getPropertyValue("--main-bg") === 'snow') {
|
if (root.style.getPropertyValue("--main-bg") === 'snow') {
|
||||||
var audio = new Audio("../media/Chicken.mp3");
|
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() {
|
$(window).on("filter", function() {
|
||||||
var parent = document.querySelector("#filtered")
|
var parent = document.querySelector("#filtered")
|
||||||
var lastTweet = parent.firstChild
|
var lastTweet = parent.firstChild
|
||||||
@@ -87,6 +91,7 @@ $(window).on("filter", function() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// toggle html for the sorting dropdown menu
|
||||||
$(".current-sort").on("click", function() {
|
$(".current-sort").on("click", function() {
|
||||||
$(".sort-dropdown-list li:not(:first-of-type)").toggle()
|
$(".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())
|
$(".current-sort").html($(this).html())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// toggle ordering between ascending or descending and changing arrow to match
|
||||||
$(".order-btn").on("click", function() {
|
$(".order-btn").on("click", function() {
|
||||||
if($(this).html() == "arrow_downward") { // Descending to ascending
|
if($(this).html() == "arrow_downward") { // Descending to ascending
|
||||||
$(this).html("arrow_upward")
|
$(this).html("arrow_upward")
|
||||||
@@ -113,6 +118,7 @@ $(".order-btn").on("click", function() {
|
|||||||
showFeeds()
|
showFeeds()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
//functions that get called in HTML onchange attributes to trigger filters
|
||||||
function updateSearched(searched){
|
function updateSearched(searched){
|
||||||
searched = searched.split(",");
|
searched = searched.split(",");
|
||||||
filters.searchedWords = searched;
|
filters.searchedWords = searched;
|
||||||
@@ -134,6 +140,7 @@ function updateSort(sort){
|
|||||||
showFeeds()
|
showFeeds()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// toggle between paused and unpaused
|
||||||
$(".pause-btn").on("click", function() {
|
$(".pause-btn").on("click", function() {
|
||||||
if($(".pause-btn").html() == "pause") { // Unpaused to paused
|
if($(".pause-btn").html() == "pause") { // Unpaused to paused
|
||||||
$(".pause-btn").html("play_arrow")
|
$(".pause-btn").html("play_arrow")
|
||||||
|
|||||||
@@ -87,11 +87,11 @@ block.fn.tweets = function(config) {
|
|||||||
}
|
}
|
||||||
window.sessionStorage.setItem('tweets', JSON.stringify(tweets));
|
window.sessionStorage.setItem('tweets', JSON.stringify(tweets));
|
||||||
if(!paused) {
|
if(!paused) {
|
||||||
// remove tweets
|
// remove tweets
|
||||||
$list.replaceChildren();
|
$list.replaceChildren();
|
||||||
var displayTweets = tweets.reverse().slice(0, options.memory).reverse();
|
var displayTweets = tweets.reverse().slice(0, options.memory).reverse();
|
||||||
for (i = 0; i < Math.min(options.memory-1, displayTweets.length); i++){
|
for (i = 0; i < Math.min(options.memory-1, displayTweets.length); i++){
|
||||||
$list.prepend(tweetCell(displayTweets[i]));
|
$list.prepend(tweetCell(displayTweets[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user