You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
3 years ago
|
const snippetsContainer = document.getElementById('snippets-container')
|
||
|
|
||
|
let pathname = window.location.pathname.replace('/soupboat/si16-app/','')
|
||
|
let page = pathname.substring(0, pathname.length - 1);
|
||
|
let endpoint = `https://hub.xpub.nl/soupboat/si16-app/api/is-event-mode/?page=${page}`;
|
||
|
|
||
|
fetch(endpoint)
|
||
|
.then((response) => response.json())
|
||
|
.then((data) => {
|
||
|
if (data.event && data.snippets) {
|
||
|
data.snippets.forEach(snippet=>{
|
||
|
console.log(snippet)
|
||
|
if(snippet.type == 'text') textSnippet(snippet.content)
|
||
|
if(snippet.type == 'image') imageSnippet(snippet)
|
||
|
|
||
|
})
|
||
|
}
|
||
|
});
|
||
|
|
||
|
function textSnippet(text){
|
||
|
let snippetBubble = document.createElement('div')
|
||
|
snippetBubble.classList.add('snippet')
|
||
|
snippetBubble.innerHTML = text
|
||
|
snippetsContainer.appendChild(snippetBubble)
|
||
|
}
|
||
|
|
||
|
function imageSnippet(snippet){
|
||
|
let snippetBubble = document.createElement('img')
|
||
|
snippetBubble.classList.add('snippet')
|
||
|
snippetBubble.src = "/soupboat/si16-app" + snippet.content
|
||
|
snippetsContainer.appendChild(snippetBubble)
|
||
|
}
|