-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmss.html
149 lines (123 loc) · 4.31 KB
/
mss.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mastodon Stadium Seats</title>
<style>
#posts .post {
margin: 1px 0;
padding: 5px;
border: 1px solid #ccc;
font-family: sans-serif, "Helvetica Neue", "Lucida Grande", Arial;
font-stretch: condensed;
}
#posts .post .content {
font-size: 14px; /* Adjust to your preference */
line-height: 1.2; /* Adjust to your preference */
}
body{
font-family: sans-serif, "Helvetica Neue", "Lucida Grande", Arial;
font-stretch: condensed;
max-width: 90%
}
.column {
width: 50%;
float: left;
}
.shaded {
background-color: #f5f5f5; /* Light gray color */
}
</style>
</head>
<body>
<div id="main">
<div id="posts"></div>
<div id="side">
<div id="tags"></div>
<div id="accounts"></div>
</div>
</div>
<script>
const fetchDataAndDisplay = () => {
// Clear previous data
document.getElementById('posts').innerHTML = '';
// The querykeys array below holds the hashtags you'lll be monitoring. You can have an unlimited number but the more you have the longer the feed will take to generate and it might change too fast.
// Make sure to put single quotes around any new hashtags you add, and separate them with commas.
const querykeys = ['foss', 'opensource','mastodon'];
// The domains array holds the Mastodon instances you'll be monitoring. I find these work well but you can change them if you wish.
const domains = ['mastodon.social', 'mstdn.social','mastodon.world','techhub.social'];
const corsProxyUrl = 'https://corsproxy.io/?';
// Create an array to hold all the results
let allPosts = [];
// Create a Set to hold hashes of posts to track duplicates
let seen = new Set();
// Create an array to hold all the fetch promises
let fetchPromises = [];
// Iterate through each domain
domains.forEach((domain) => {
querykeys.forEach((querykey) => {
const url = 'https://' + domain + '/api/v1/timelines/tag/' + querykey + '?limit=40';
let fetchPromise = fetch(corsProxyUrl + url)
.then((response) => {
if (!response.ok) {
throw new Error('HTTP error ' + response.status);
}
return response.json();
})
.then((json) => {
json.forEach((post) => {
const hash = post.uri;
if (!seen.has(hash)) {
allPosts.push(post);
seen.add(hash);
}
});
})
.catch(function () {
console.log('An error occurred while fetching the data.');
});
fetchPromises.push(fetchPromise);
});
});
Promise.all(fetchPromises).then(() => {
allPosts.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
let top15Posts = allPosts.slice(0, 15);
// Inserting data into HTML
const postsContainer = document.getElementById('posts');
// Create two columns
const column1Div = document.createElement('div');
column1Div.className = 'column';
const column2Div = document.createElement('div');
column2Div.className = 'column';
// Iterate through the top 15 posts, and append them to the appropriate column
top15Posts.forEach((post, index) => {
const postDiv = document.createElement('div');
postDiv.className = 'post';
if (index % 2 === 0) {
postDiv.classList.add('shaded'); // or postDiv.style.backgroundColor = 'yourColor';
}
// Create a temporary container to hold the HTML content
let tempDiv = document.createElement('div');
tempDiv.innerHTML = post.content;
// Append the manipulated content
postDiv.innerHTML = tempDiv.innerHTML;
// Depending on the index, append the post to the appropriate column
if (index < 7) {
column1Div.appendChild(postDiv);
} else if (index < 14) {
column2Div.appendChild(postDiv);
}
});
// Append the two columns to the posts container
postsContainer.appendChild(column1Div);
postsContainer.appendChild(column2Div);
});
};
// Call the function immediately to fetch and display data
fetchDataAndDisplay();
// Schedule the function to run every 90 seconds (expressed in milliseconds.) You can change this if you wish.
setInterval(fetchDataAndDisplay, 90000);
</script>
</body>
</html>