2024-12-10 22:53:16 +01:00
|
|
|
import { fetchProfile } from './profile-utils.js';
|
|
|
|
import { createRecommendationPopup } from './popup-utils.js';
|
2024-12-14 15:34:09 +01:00
|
|
|
import { getServerClass, extractHostname } from './instances.js';
|
2024-12-10 22:53:16 +01:00
|
|
|
|
|
|
|
export function createStarterKitElement(kit) {
|
|
|
|
const template = document.getElementById('starterkit-template').content.cloneNode(true);
|
|
|
|
|
2024-12-12 22:30:51 +01:00
|
|
|
// Titel und Beschreibung
|
2024-12-10 22:53:16 +01:00
|
|
|
const kitElement = template.querySelector('.starterkit');
|
|
|
|
kitElement.querySelector('h3').textContent = kit.name;
|
|
|
|
kitElement.querySelector('p').textContent = kit.description;
|
|
|
|
|
|
|
|
// Aufteilen der Profilanzahl in zwei Zeilen
|
|
|
|
const profileCount = kitElement.querySelector('.profile-count');
|
|
|
|
profileCount.querySelector('.profile-line2').textContent = `${kit.accounts.length}`;
|
|
|
|
|
|
|
|
// Hinzufügen des Autors mit 'created by'
|
|
|
|
const authorLink = kitElement.querySelector('.account');
|
|
|
|
authorLink.href = kit.author;
|
|
|
|
|
|
|
|
fetchProfile(kit.author, { updateElement: authorLink }).then(() => {
|
|
|
|
const avatarImage = authorLink.querySelector('.account-avatar');
|
|
|
|
if (avatarImage) {
|
2024-12-12 22:30:51 +01:00
|
|
|
authorLink.textContent = '';
|
2024-12-10 22:53:16 +01:00
|
|
|
authorLink.appendChild(avatarImage);
|
2024-12-14 15:34:09 +01:00
|
|
|
|
|
|
|
// Hinzufügen der server-class für den Avatar-Rahmen
|
|
|
|
const hostname = extractHostname(kit.author);
|
|
|
|
const serverClass = getServerClass(hostname);
|
|
|
|
if (serverClass) {
|
|
|
|
avatarImage.classList.add(serverClass);
|
|
|
|
}
|
2024-12-10 22:53:16 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
kitElement.dataset.accounts = JSON.stringify(kit.accounts);
|
|
|
|
|
|
|
|
return kitElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function enhanceStarterKits() {
|
|
|
|
const starterkits = document.querySelectorAll('.starterkit');
|
|
|
|
|
|
|
|
starterkits.forEach(kit => {
|
|
|
|
kit.addEventListener('click', function () {
|
|
|
|
const title = kit.querySelector('h3').textContent;
|
|
|
|
const accounts = JSON.parse(kit.dataset.accounts || '[]');
|
|
|
|
const popup = createRecommendationPopup(accounts, title);
|
|
|
|
document.body.appendChild(popup);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|