-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimeline-meft.html
260 lines (222 loc) · 9.96 KB
/
timeline-meft.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Mastodon Timeline Embed (MEFT Example)</title>
<meta name="author" content="@[email protected]" />
<meta name="keywords" content="mastodon, embed timeline, fediverse, example, javascript" />
<meta name="description"
content="Example showing how to embed a Mastodon timeline using the mastodon-embed-timeline JavaScript library." />
<meta property="og:title" content="Mastodon Timeline Embed Example (MEFT)" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://mastodon-embeds.glitch.me/timeline-meft.html" />
<meta property="og:image" content="https://mastodon-embeds.glitch.me/mastodon-logo.svg" />
<meta property="og:description"
content="Example showing how to embed a Mastodon timeline using the mastodon-embed-timeline JavaScript library." />
<meta property="og:site_name" content="Mastodon Embed Examples" />
<link rel="icon" type="image/png" sizes="96x96" href="images/favicon-96x96.png">
<link rel="icon" type="image/x-icon" href="images/favicon.ico">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css" />
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@idotj/[email protected]/dist/mastodon-timeline.min.css"
integrity="sha256-Qi3H+bdH6RuMuyR1trAlG5bMWJGl9y3jPiTc1PWQFpI=" crossorigin="anonymous">
<style>
.section.has-top-controls {
position: relative;
padding-top: 4rem;
}
.theme-toggle-button {
position: absolute;
top: 1.5rem;
right: 1.5rem;
width: 2.5rem;
height: 2.5rem;
padding: 0;
border-radius: 50%;
display: inline-flex;
align-items: center;
justify-content: center;
}
.theme-toggle-button .icon svg {
width: 1.1em;
height: 1.1em;
}
/* Ensure the container has some height while loading */
/* You might need to adjust styles in mastodon-timeline.css for theme compatibility */
#mt-timeline {
min-height: 200px;
/* Basic theme adjustments - consider moving to mastodon-timeline.css */
background-color: hsl(0, 0%, 96%);
/* Default light background */
color: hsl(0, 0%, 21%);
/* Default light text */
}
[data-theme="dark"] #mt-timeline {
background-color: hsl(0, 0%, 21%);
/* Dark background */
color: hsl(0, 0%, 96%);
/* Dark text */
/* Add more specific dark theme overrides for links, borders etc. if needed */
}
[data-theme="dark"] #mt-timeline a {
color: hsl(204, 71%, 53%);
/* Example dark theme link color */
}
[data-theme="dark"] .mt-toot {
border-bottom-color: hsl(0, 0%, 29%);
/* Darker border */
}
</style>
</head>
<body>
<section class="section has-top-controls">
<button class="button theme-toggle-button" aria-label="Toggle theme">
<span class="icon theme-icon">
</span>
</button>
<div class="container">
<h1 class="title">Mastodon Timeline Embed: MEFT</h1>
<div class="box">
<div class="content">
<h2 class="title is-4">About This Method</h2>
<p>
This method uses the <a href="https://gitlab.com/idotj/mastodon-embed-timeline" target="_blank"
rel="noopener noreferrer">mastodon-embed-timeline</a> (MEFT) JavaScript library.
It fetches timeline data from the Mastodon API and renders it client-side into a designated HTML
element.
</p>
<p>
Configuration requires setting JavaScript variables before loading the main library script.
See the <strong>Configuration Script</strong> section below the rendered timeline.
</p>
<p>
<strong>Important:</strong> You need the Mastodon <strong>User ID</strong> (a number, not the username)
for the account you want to embed. You can often find this using API tools (like searching the account via
<code>/.well-known/webfinger</code> on the instance and looking for the ID in the <code>self</code> link)
or sometimes by viewing the source code of the user's profile page.
</p>
</div>
</div>
<div class="box">
<div class="content">
<h2 class="title is-4">Configuration Script</h2>
<p>The following script block sets the configuration options for the library, and is set towards the end of
the code in this example page. Modify these values as
needed. Here, we're asking to fetch 40 posts, and show a maximum of 20; but we're hiding unlisted posts,
replies, reblogs, and pinned posts, all of which get filtered from the number of posts fetched, so it may
show fewer than 20.</p>
</p>
<pre><code><script>
const myTimeline = new MastodonTimeline.Init({
instanceUrl: "https://macaw.social",
timelineType: "profile",
userId: "109332977621728450",
profileName: "@andypiper",
defaultTheme: "auto",
maxNbPostFetch: "40",
maxNbPostShow: "20",
hideUnlisted: true,
hideReplies: true,
hideReblog: true,
hidePinnedPosts: true,
// Add any other options you want to configure
// See the documentation for more details
});
</script></code></pre>
</div>
</div>
<div class="box">
<div class="content">
<h2 class="title is-4">Rendered Timeline</h2>
<p>This is what the embedded timeline looks like using this method:</p>
<div id="mt-container" class="mt-container">
<div class="mt-body" role="feed">
<div class="mt-loading-spinner"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<footer class="footer">
<div class="content has-text-centered">
<p>
<strong><a href="https://mastodon-embeds.glitch.me">Mastodon Embed Examples</a></strong>.
Styled using <a href="https://bulma.io/" target="_blank" rel="noopener noreferrer">Bulma</a>.
Find me on Mastodon: <a href="https://macaw.social/@andypiper" target="_blank"
rel="noopener noreferrer">@[email protected]</a>.
</p>
</div>
</footer>
<script>
(function () {
// Simple inline SVGs for icons
const sunIcon = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/></svg>`;
const moonIcon = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/></svg>`;
// Select ALL buttons with this class
const toggleButtons = document.querySelectorAll('.theme-toggle-button');
// Select ALL icon spans within those buttons
const iconSpans = document.querySelectorAll('.theme-toggle-button .theme-icon');
const htmlElement = document.documentElement;
const storageKey = 'theme-preference';
// Function to apply theme and update ALL icons
const applyTheme = (theme) => {
htmlElement.dataset.theme = theme;
const iconHTML = theme === 'dark' ? moonIcon : sunIcon;
iconSpans.forEach(span => {
// Check if span exists before setting innerHTML
if (span) span.innerHTML = iconHTML;
});
};
// Function to get the preferred theme
const getPreferredTheme = () => {
const savedTheme = localStorage.getItem(storageKey);
if (savedTheme) return savedTheme;
// Default to light if no system preference detected or needed
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
};
// Function to handle the button click
const handleToggleClick = () => {
// Read the current theme directly from the html element
let currentTheme = htmlElement.dataset.theme || getPreferredTheme();
let newTheme = currentTheme === 'dark' ? 'light' : 'dark';
applyTheme(newTheme);
localStorage.setItem(storageKey, newTheme);
}
// --- Initialization ---
// Apply the initial theme when the script runs
let currentTheme = getPreferredTheme();
applyTheme(currentTheme);
// Add listeners to all toggle buttons found
if (toggleButtons.length > 0) {
toggleButtons.forEach(button => {
button.addEventListener('click', handleToggleClick);
});
} else {
// It's okay if not found on pages without the button
// console.warn("Theme toggle button(s) not found on this page.");
}
})();
</script>
<script src="https://cdn.jsdelivr.net/npm/@idotj/[email protected]/dist/mastodon-timeline.umd.js"
integrity="sha256-atEPYqs4j5Ogqb9yl3++jbRmTIItqwZUhpnTWdNsF2c=" crossorigin="anonymous"></script>
<script>
// --- Configuration for mastodon-embed-timeline ---
const myTimeline = new MastodonTimeline.Init({
instanceUrl: "https://macaw.social",
timelineType: "profile",
userId: "109332977621728450",
profileName: "@andypiper",
defaultTheme: "auto",
maxNbPostFetch: "40",
maxNbPostShow: "10",
hideUnlisted: true,
hideReplies: true,
hideReblog: true,
hidePinnedPosts: true,
});
</script>
</body>
</html>