46 lines
1.4 KiB
JavaScript
46 lines
1.4 KiB
JavaScript
|
|
const response = await fetch('https://api.instantworkstation.com/workstations');
|
||
|
|
const workstations = await response.json();
|
||
|
|
|
||
|
|
const now = new Date();
|
||
|
|
const recent = new Date(now);
|
||
|
|
|
||
|
|
recent.setUTCDate(now.getUTCDate() - 30);
|
||
|
|
recent.setUTCHours(0, 0, 0, 0);
|
||
|
|
|
||
|
|
const recentWorkstations = workstations.filter(isRecent);
|
||
|
|
const news = recentWorkstations.flatMap(generateNews);
|
||
|
|
const ticker = document.getElementById('news-ticker-content');
|
||
|
|
|
||
|
|
let index = 0;
|
||
|
|
if (news.length > 0) {
|
||
|
|
ticker.textContent = news[index];
|
||
|
|
ticker.addEventListener('animationiteration', showNextAnnouncement);
|
||
|
|
ticker.style.animationPlayState = 'running';
|
||
|
|
}
|
||
|
|
|
||
|
|
function generateNews(workstation) {
|
||
|
|
return workstation.architectures.map(architecture => {
|
||
|
|
const workstationDetails = `${workstation.os} ${workstation.version}`;
|
||
|
|
const architectureDetails = `${architecture.cpu} ${architecture.bitness} ${architecture.endianness}`;
|
||
|
|
|
||
|
|
return `${workstationDetails} ${architectureDetails} is now available`;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function isRecent(workstation) {
|
||
|
|
const added = new Date(workstation.added);
|
||
|
|
|
||
|
|
return added >= recent;
|
||
|
|
}
|
||
|
|
|
||
|
|
function showNextAnnouncement() {
|
||
|
|
index++;
|
||
|
|
|
||
|
|
if (index < news.length) {
|
||
|
|
ticker.textContent = news[index];
|
||
|
|
} else {
|
||
|
|
ticker.removeEventListener('animationiteration', showNextAnnouncement);
|
||
|
|
ticker.style.animationPlayState = 'paused';
|
||
|
|
ticker.textContent = '';
|
||
|
|
}
|
||
|
|
}
|