Skip to content

Commit

Permalink
Improve team logo loading
Browse files Browse the repository at this point in the history
  • Loading branch information
UrbsKali committed Feb 27, 2024
1 parent 57461db commit 8dc1944
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions overlay/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ let is_connected = false;
let ref_timer = 0;
let current_timer = 0;

let teams_img_exist = [false, false];

async function setup() {
let rawData = await fetch("http://localhost/draft/full")
if (rawData.status != 200) {
Expand Down Expand Up @@ -168,19 +170,36 @@ async function getTeamInfo() {
async function setupTeamInfo() {
let teamName = document.getElementsByClassName("teamName");
let blob = document.getElementsByClassName("blob");
//let teamLogo = document.getElementsByClassName("teamLogo");
let score = document.getElementsByClassName("score");

selected = await getTeamInfo();
for (let i = 0; i < teamName.length; i++) {
teamName[i].getElementsByTagName("h1")[0].innerText = selected[i]["name"];

teamName[i].getElementsByTagName("img")[0].src = `./teams_img/${selected[i]["tag"]}.png`;
if (teams_img_exist[i] == true){
teamName[i].getElementsByTagName("img")[0].src = `./teams_img/${selected[i]["tag"]}.png`;
} else {
teamName[i].getElementsByTagName("img")[0].src = `./img/_notfound.png`;
}


//teamName[i].children[1].innerText = selected[i]["tag"];
score[i].innerText = selected[i]["score"];
//teamLogo[i].style.backgroundImage = `url('${selected[i]["logo"]}')`;
blob[i].style.backgroundColor = `${selected[i]["color"]}33`;

}
}
async function checkImg(){
let selected = await getTeamInfo();
for (let i = 0; i < 2; i++){
let img = new Image();

img.src = `./teams_img/${selected[i]["tag"]}.png`;
img.onload = function() {
teams_img_exist[i] = true;
}
img.onerror = function() {
teams_img_exist[i] = false;
}
}
}

Expand Down Expand Up @@ -248,5 +267,9 @@ setInterval(() => {
} else {
setup();
setupTeamInfo();
checkImg();
}
if (document.getElementsByClassName("teamName")[0].getElementsByTagName("h1")[0].innerText == "TEAM 1") {
setupTeamInfo();
}
}, 1000);
Binary file added overlay/teams_img/HEH.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8dc1944

Please sign in to comment.