LuminaWebsite/assets/js/activity.js
Maaxxs 392994e1cd Activity check (website + bot), videos in the wiki, contributor search list
- Activity check: created on the website (activity.php, activity.manage) or with /aktivitaetscheck; the bot posts "I'm in" / "I'm out" buttons; title, text, color, image and button labels are configurable with a live preview; deadline; consequences for non-responders (DM, remove/add role, optionally also for "I'm out"); close early or cancel; overview of in / out / pending
- Wiki: a video link alone on a line (YouTube incl. Shorts/start time, Twitch, Vimeo, .mp4/.webm) becomes an embedded player, plus a "Video" button in the editor
- Wiki: "Add contributor" as a search list with avatar, group and class instead of a dropdown

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 01:11:49 +02:00

93 lines
4.1 KiB
JavaScript

/**
* Aktivitaetscheck anlegen: Formular ein-/ausblenden und Live-Vorschau, wie die Nachricht im
* Discord aussehen wird (Farbe, Titel, Text, Bild, Knoepfe, Frist).
*/
(function () {
'use strict';
var panel = document.getElementById('activity-create');
var form = document.getElementById('activity-form');
if (!panel || !form) return;
document.querySelectorAll('[data-toggle-activity-form]').forEach(function (button) {
button.addEventListener('click', function () {
panel.hidden = !panel.hidden;
if (!panel.hidden) {
panel.scrollIntoView({ behavior: 'smooth', block: 'start' });
f.title.focus();
}
});
});
var f = form.elements; // form.title waere das title-Attribut des Formulars, nicht das Feld
var dmToggle = form.querySelector('[data-toggle-dm]');
var dmField = form.querySelector('.activity-dm');
dmToggle.addEventListener('change', function () { dmField.hidden = !dmToggle.checked; });
function out(name) { return form.querySelector('[data-out="' + name + '"]'); }
// Discord-Formatierung grob nachbilden: **fett**, *kursiv*, Zeilenumbrueche (Text sicher als Text)
function discordText(text) {
var div = document.createElement('div');
div.textContent = text;
return div.innerHTML
.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
.replace(/(^|[^*])\*([^*\n]+)\*/g, '$1<em>$2</em>')
.replace(/\n/g, '<br>');
}
function color() {
var custom = f.color_custom.value;
var picked = form.querySelector('input[name="color"]:checked');
return custom && custom.toLowerCase() !== '#c9a227' ? custom : (picked ? picked.value : '#c9a227');
}
function update() {
out('title').textContent = f.title.value || 'Aktivitätscheck';
out('message').innerHTML = discordText(f.message.value);
out('embed').style.borderLeftColor = color();
var role = f.target_role_id.options[f.target_role_id.selectedIndex];
out('role').textContent = role && role.value ? role.textContent.replace(/^@/, '') : 'Rolle';
out('ping').hidden = !f.ping_role.checked;
out('yes').textContent = f.yes_label.value.trim() || 'Ich bin da';
out('no').textContent = f.no_label.value.trim() || 'Ich bin nicht da';
var value = Math.max(1, parseInt(f.duration_value.value, 10) || 1);
var ms = value * (f.duration_unit.value === 'hours' ? 3600e3 : 86400e3);
var end = new Date(Date.now() + ms);
out('deadline').textContent = end.toLocaleString('de-DE', { weekday: 'long', day: '2-digit', month: 'long', hour: '2-digit', minute: '2-digit' })
+ ' (in ' + value + (f.duration_unit.value === 'hours' ? (value === 1 ? ' Stunde' : ' Stunden') : (value === 1 ? ' Tag' : ' Tagen')) + ')';
var image = f.image_url.value.trim();
var img = out('image');
if (/^https:\/\/\S+$/.test(image)) {
img.src = image;
img.hidden = false;
} else {
img.hidden = true;
}
}
form.addEventListener('input', update);
form.addEventListener('change', update);
// Eigene Farbe gewaehlt -> Auswahlkreise abwaehlen, Kreis gewaehlt -> eigene Farbe zuruecksetzen
f.color_custom.addEventListener('input', function () {
form.querySelectorAll('input[name="color"]').forEach(function (r) { r.checked = false; });
});
form.querySelectorAll('input[name="color"]').forEach(function (radio) {
radio.addEventListener('change', function () { f.color_custom.value = '#c9a227'; });
});
form.addEventListener('submit', function (event) {
var consequences = [];
if (dmToggle.checked) consequences.push('PN');
if (f.remove_role_id.value) consequences.push('Rolle entfernen');
if (f.add_role_id.value) consequences.push('Rolle geben');
var text = 'Check jetzt im Discord posten?\n\nFolgen ohne Rückmeldung: ' + (consequences.length ? consequences.join(', ') : 'keine (nur Liste im Log-Kanal)');
if (!window.confirm(text)) event.preventDefault();
});
update();
})();