2024-12-29 13:08:59 +01:00
|
|
|
import { checkConsent, showConsentPopup, setUserConsent } from '../components/consentManager.js';
|
|
|
|
|
2024-12-28 15:17:57 +01:00
|
|
|
export async function loadPostwall() {
|
|
|
|
const container = document.getElementById('postswall-container');
|
|
|
|
|
|
|
|
// Mastodon API-URL für Hashtag-Suche
|
2025-01-12 00:11:54 +01:00
|
|
|
const apiUrl = 'https://kirche.social/api/v1/timelines/tag/fedikirche?limit=20';
|
2024-12-28 15:17:57 +01:00
|
|
|
|
|
|
|
// Posts laden
|
|
|
|
async function fetchPosts() {
|
|
|
|
try {
|
|
|
|
const response = await fetch(apiUrl);
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error('Fehler beim Laden der Posts');
|
|
|
|
}
|
|
|
|
|
|
|
|
const posts = await response.json();
|
|
|
|
renderPosts(posts);
|
|
|
|
|
|
|
|
// Button hinzufügen
|
|
|
|
addReadMoreButton();
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Fehler:', error);
|
|
|
|
container.innerHTML = '<p>Fehler beim Laden der Posts.</p>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Posts rendern
|
|
|
|
function renderPosts(posts) {
|
|
|
|
container.innerHTML = ''; // Vorherige Inhalte leeren
|
|
|
|
posts.forEach(post => {
|
|
|
|
const postElement = document.createElement('a');
|
|
|
|
postElement.classList.add('post');
|
|
|
|
postElement.href = post.url; // Link zum Originalpost
|
2024-12-29 13:08:59 +01:00
|
|
|
postElement.target = '_blank';
|
|
|
|
postElement.rel = 'noopener noreferrer';
|
|
|
|
postElement.setAttribute('aria-label', 'Zum Originalpost auf Mastodon');
|
2024-12-28 15:17:57 +01:00
|
|
|
|
|
|
|
// Zeitstempel berechnen
|
2024-12-29 13:08:59 +01:00
|
|
|
const postDate = new Date(post.created_at);
|
|
|
|
const timeAgo = getTimeAgo(postDate);
|
2024-12-28 15:17:57 +01:00
|
|
|
|
|
|
|
let content = post.content || 'Kein Inhalt verfügbar.';
|
|
|
|
const author = post.account.display_name || post.account.username;
|
2024-12-29 13:08:59 +01:00
|
|
|
const username = `@${post.account.acct}`;
|
|
|
|
const avatar = post.account.avatar || 'src/assets/default-avatar.png';
|
2024-12-28 15:17:57 +01:00
|
|
|
|
2024-12-29 13:08:59 +01:00
|
|
|
// Links deaktivieren
|
2024-12-28 15:17:57 +01:00
|
|
|
const tempContainer = document.createElement('div');
|
|
|
|
tempContainer.innerHTML = content;
|
|
|
|
|
|
|
|
const links = tempContainer.querySelectorAll('a');
|
|
|
|
links.forEach(link => {
|
2024-12-29 13:08:59 +01:00
|
|
|
link.removeAttribute('href');
|
|
|
|
link.style.pointerEvents = 'none';
|
|
|
|
link.style.color = 'blue';
|
|
|
|
link.style.textDecoration = 'underline';
|
2024-12-28 15:17:57 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Bilder bearbeiten
|
|
|
|
const images = tempContainer.querySelectorAll('img');
|
|
|
|
images.forEach(img => {
|
2024-12-29 13:08:59 +01:00
|
|
|
img.style.maxHeight = '200px';
|
|
|
|
img.style.width = 'auto';
|
|
|
|
img.style.display = 'block';
|
|
|
|
img.style.margin = '10px 0';
|
2024-12-28 15:17:57 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
content = tempContainer.innerHTML;
|
|
|
|
|
|
|
|
const mediaAttachments = post.media_attachments || [];
|
|
|
|
let mediaHTML = '';
|
|
|
|
mediaAttachments.forEach(media => {
|
|
|
|
if (media.type === 'image') {
|
|
|
|
mediaHTML += `
|
|
|
|
<img src="${media.url}" alt="Medienanhang" style="max-height: 200px; width: auto; display: block; margin: 10px 0;">
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
postElement.innerHTML = `
|
|
|
|
<div class="post-header">
|
|
|
|
<img src="${avatar}" alt="${author}" class="avatar">
|
|
|
|
<div class="post-author">
|
2025-01-01 21:43:05 +01:00
|
|
|
<span class="post-authorname">${author}</span>
|
2024-12-28 15:17:57 +01:00
|
|
|
<span class="post-username">${username}</span>
|
|
|
|
</div>
|
|
|
|
<span class="post-timestamp">${timeAgo}</span>
|
|
|
|
</div>
|
|
|
|
<div class="post-content">${content}</div>
|
|
|
|
<div class="post-media">${mediaHTML}</div>
|
|
|
|
<div class="post-footer">…</div>
|
|
|
|
`;
|
|
|
|
container.appendChild(postElement);
|
|
|
|
});
|
|
|
|
}
|
2024-12-29 13:08:59 +01:00
|
|
|
|
2024-12-28 15:17:57 +01:00
|
|
|
// Lade die Posts
|
|
|
|
fetchPosts();
|
|
|
|
}
|
|
|
|
|
2024-12-29 13:08:59 +01:00
|
|
|
// Zeitberechnung für Posts
|
2024-12-28 15:17:57 +01:00
|
|
|
function getTimeAgo(date) {
|
|
|
|
const now = new Date();
|
|
|
|
const secondsAgo = Math.floor((now - date) / 1000);
|
|
|
|
|
|
|
|
if (secondsAgo < 60) {
|
|
|
|
return `${secondsAgo} Sek.`;
|
|
|
|
} else if (secondsAgo < 3600) {
|
|
|
|
const minutes = Math.floor(secondsAgo / 60);
|
|
|
|
return `${minutes} Min.`;
|
|
|
|
} else if (secondsAgo < 86400) {
|
|
|
|
const hours = Math.floor(secondsAgo / 3600);
|
|
|
|
return `${hours} Std.`;
|
|
|
|
} else {
|
|
|
|
const days = Math.floor(secondsAgo / 86400);
|
|
|
|
return `${days} T.`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-29 13:08:59 +01:00
|
|
|
// "Lese weiter"-Button hinzufügen
|
2024-12-28 15:17:57 +01:00
|
|
|
function addReadMoreButton() {
|
|
|
|
const container = document.getElementById('postswall-container');
|
|
|
|
const readMoreButton = document.createElement('a');
|
2025-01-12 00:11:54 +01:00
|
|
|
readMoreButton.href = 'https://kirche.social/tags/fedikirche';
|
2024-12-29 13:08:59 +01:00
|
|
|
readMoreButton.target = '_blank';
|
2024-12-28 15:17:57 +01:00
|
|
|
readMoreButton.rel = 'noopener noreferrer';
|
2024-12-29 13:08:59 +01:00
|
|
|
readMoreButton.classList.add('read-more-button');
|
2024-12-28 15:17:57 +01:00
|
|
|
readMoreButton.innerText = 'weiterlesen';
|
|
|
|
container.appendChild(readMoreButton);
|
|
|
|
}
|