www.franconian.net/static/bauchbinde/assets/script.js

185 lines
5.7 KiB
JavaScript
Raw Normal View History

2020-12-23 19:37:15 +01:00
(() => {
2021-12-27 13:09:30 +01:00
const scheduleUrl = 'https://static.rc3.world/schedule/everything.json';
2020-12-25 15:44:57 +01:00
2020-12-28 16:24:17 +01:00
let isFirstRun = true;
let autoIntro = false;
2020-12-27 13:32:40 +01:00
let data = null;
2020-12-23 19:37:15 +01:00
let textEl;
2020-12-27 13:32:40 +01:00
let headline = null;
let speaker = null;
2020-12-23 19:37:15 +01:00
let isIntro = false;
2020-12-27 21:17:37 +01:00
let holdDuration = 10;
2020-12-25 15:44:57 +01:00
let room = null;
let time = null;
2020-12-27 21:17:37 +01:00
let startDelay = 1;
let gracePeriod = 360;
2020-12-27 20:36:52 +01:00
let interval = null;
2020-12-25 15:44:57 +01:00
2020-12-27 13:32:40 +01:00
async function getCurrentTalkByRoomName(roomName, offset) {
if (!offset) {
offset = 0;
}
let now = Date.now() + offset;
2020-12-25 15:44:57 +01:00
if (time) {
2020-12-27 13:32:40 +01:00
now = Date.parse(time) + offset;
}
2020-12-27 21:17:37 +01:00
if (!offset || !data) {
2020-12-27 13:32:40 +01:00
const response = await fetch(scheduleUrl);
data = await response.json();
2020-12-25 15:44:57 +01:00
}
const days = data.schedule.conference.days;
const today = days.find(day => {
const start = Date.parse(day.day_start);
const end = Date.parse(day.day_end);
return now >= start && now <= end;
});
if (!today) return false;
2020-12-23 19:37:15 +01:00
2020-12-25 15:44:57 +01:00
const room = today.rooms[roomName];
if (!room) return false;
const talk = room.find(talk => {
const start = Date.parse(talk.date);
2020-12-28 18:11:30 +01:00
const [hours, minutes] = talk.duration.split(':').map(s => parseInt(s.trim(), 10));
2020-12-25 15:44:57 +01:00
const duration = (hours * 60 + minutes) * 60 * 1000;
const end = start + duration;
return now >= start && now <= end;
})
if (!talk) return false;
return talk;
}
async function init() {
2020-12-25 23:17:55 +01:00
const root = document.querySelector('html');
2020-12-23 19:37:15 +01:00
if (window.location.search) {
2020-12-25 15:44:57 +01:00
const pairs = window.location.search.slice(1).split('&').map(x => x.split('='));
for (let pair of pairs) {
const key = pair.shift();
const value = decodeURIComponent(pair.join('='));
2020-12-23 19:37:15 +01:00
if (key === 'headline') {
2020-12-25 20:47:40 +01:00
headline = value;
2020-12-23 19:37:15 +01:00
}
if (key === 'speaker') {
2020-12-25 15:44:57 +01:00
speaker = value;
2020-12-23 19:37:15 +01:00
}
if (key === 'intro') {
2020-12-24 00:39:14 +01:00
isIntro = !!parseInt(value, 10)
2020-12-23 19:37:15 +01:00
}
2020-12-28 16:24:17 +01:00
if (key === 'autoIntro') {
autoIntro = !!parseInt(value, 10)
}
2020-12-23 19:37:15 +01:00
if (key === 'hold') {
2020-12-24 00:39:14 +01:00
holdDuration = parseInt(value, 10);
2020-12-23 19:37:15 +01:00
}
2020-12-24 17:53:14 +01:00
if (key === 'theme') {
2020-12-25 15:44:57 +01:00
root.className = '';
root.classList.add(`theme-${value}`)
}
if (key === 'room') {
room = value;
}
if (key === 'time') {
time = value;
}
2020-12-25 23:17:55 +01:00
if (key === 'startdelay') {
startDelay = parseInt(value, 10);
}
if (key === 'left') {
root.style.setProperty('--left', value);
}
if (key === 'bottom') {
root.style.setProperty('--bottom', value);
}
2020-12-27 23:50:47 +01:00
if (key === 'top') {
root.style.setProperty('--top', value);
}
2020-12-25 23:17:55 +01:00
if (key === 'width') {
root.style.setProperty('--width', value);
}
2020-12-27 13:32:40 +01:00
if (key === 'gracePeriod') {
2020-12-27 20:36:52 +01:00
gracePeriod = parseInt(value, 10);
}
if (key === 'interval') {
interval = parseInt(value, 10);
2020-12-27 13:32:40 +01:00
}
2020-12-25 15:44:57 +01:00
}
}
if (room) {
2020-12-27 21:17:37 +01:00
let offset = gracePeriod * 1000;
2020-12-27 13:32:40 +01:00
let talk = await getCurrentTalkByRoomName(room);
2020-12-25 15:44:57 +01:00
if (!talk) {
2020-12-27 13:32:40 +01:00
talk = await getCurrentTalkByRoomName(room, -offset);
}
if (!talk) {
talk = await getCurrentTalkByRoomName(room, offset);
}
if (!talk) {
headline = null;
speaker = null;
2020-12-25 15:44:57 +01:00
} else {
headline = talk.title;
if (talk.persons) {
2021-12-24 23:21:32 +01:00
speaker = talk.persons.map(person => person.public_name).join(', ');
2020-12-24 17:53:14 +01:00
}
2020-12-25 15:44:57 +01:00
}
2020-12-23 19:37:15 +01:00
}
2020-12-25 23:17:55 +01:00
2020-12-27 13:32:40 +01:00
if (!headline) {
return false;
}
2021-12-24 23:21:32 +01:00
const headlineEl = document.querySelector('.headline');
headlineEl.innerHTML = '';
const speakerEl = document.querySelector('.speaker');
speakerEl.innerHTML = '';
2020-12-23 19:37:15 +01:00
2021-12-24 23:21:32 +01:00
console.log('headline', headline);
console.log('speaker', speaker);
2020-12-23 19:37:15 +01:00
2020-12-27 13:32:40 +01:00
if (headline) {
2021-12-24 23:21:32 +01:00
headlineEl .innerText = headline;
2020-12-27 13:32:40 +01:00
}
if (speaker) {
2021-12-24 23:21:32 +01:00
speakerEl.innerText = speaker;
2020-12-23 19:37:15 +01:00
}
2020-12-27 13:32:40 +01:00
return true;
2020-12-23 19:37:15 +01:00
}
async function animate() {
2021-12-26 00:23:30 +01:00
const glitchEl = document.querySelector('.glitch');
const infoEl = document.querySelector('.info');
const glitchDuration = 1500;
glitchEl.classList.add('visible');
await new Promise(r => setTimeout(r, glitchDuration));
glitchEl.classList.remove('visible');
infoEl.classList.add('visible');
2020-12-27 21:17:37 +01:00
await new Promise(r => setTimeout(r, holdDuration * 1000));
2021-12-26 00:23:30 +01:00
infoEl.classList.remove('visible');
glitchEl.classList.add('visible');
await new Promise(r => setTimeout(r, glitchDuration));
glitchEl.classList.remove('visible');
2020-12-23 19:37:15 +01:00
}
2020-12-27 20:36:52 +01:00
async function cycle() {
2020-12-27 13:32:40 +01:00
if (await init()) {
2020-12-27 21:17:37 +01:00
await new Promise(r => setTimeout(r, startDelay * 1000));
2020-12-27 13:32:40 +01:00
await animate();
}
2020-12-27 20:36:52 +01:00
if (interval) {
setTimeout(cycle, interval * 1000);
2020-12-28 16:24:17 +01:00
isFirstRun = false;
2020-12-27 20:36:52 +01:00
}
}
window.addEventListener('load', () => {
cycle();
2020-12-23 19:37:15 +01:00
});
})();