Moves client side javascript to a new file

- creates new file, resources/script.js
- removes javascript from index.html
This commit is contained in:
Ariana Giroux 2022-07-22 17:17:50 -06:00
parent 823abb4395
commit f9a78d9d10
2 changed files with 28 additions and 31 deletions

View File

@ -28,36 +28,6 @@
</footer>
</body>
<script>
async function getEndpoint(url = '') {
const response = await fetch(url, {method:'GET'});
const data = await response.json();
return data;
}
async function uiUpdate() {
window.setInterval(async () => {
data = await getEndpoint('http://127.0.0.1:5000/api/serverstatus');
document.getElementById("streamTitle").innerHTML = data.streamTitle
document.getElementById("currentViewers").innerHTML = data.viewerCount
document.getElementById("sessionMaxViewerCount").innerHTML = data.sessionMaxViewerCount
document.getElementById("overallMaxViewerCount").innerHTML = data.overallMaxViewerCount
document.getElementById("tags").innerHTML = data.tags
}, 1000)
}
async function updateStreamTitle() {
response = await fetch('http://127.0.0.1:5000/api/update/streamtitle',
{
method:'POST',
data:JSON.stringify('a big test')
}
);
const data = await response.json()
return data
}
// uiUpdate()
updateStreamTitle()
</script>
<script src="resources/script.js"></script>
</html>

27
resources/script.js Normal file
View File

@ -0,0 +1,27 @@
async function getEndpoint(url = '') {
const response = await fetch(url, {method:'GET'});
const data = await response.json();
return data;
}
async function uiUpdate() {
window.setInterval(async () => {
data = await getEndpoint('http://127.0.0.1:5000/api/serverstatus');
document.getElementById("streamTitle").innerHTML = data.streamTitle
document.getElementById("currentViewers").innerHTML = data.viewerCount
document.getElementById("sessionMaxViewerCount").innerHTML = data.sessionMaxViewerCount
document.getElementById("overallMaxViewerCount").innerHTML = data.overallMaxViewerCount
document.getElementById("tags").innerHTML = data.tags
}, 1000)
}
async function updateStreamTitle() {
response = await fetch('http://127.0.0.1:5000/api/update/streamtitle',
{
method:'POST',
data:JSON.stringify('a big test')
}
);
const data = await response.json()
return data
}