diff --git a/esea-league-filter-bookmark.js b/esea-league-filter-bookmark.js index 995ecf1..8cb55de 100644 --- a/esea-league-filter-bookmark.js +++ b/esea-league-filter-bookmark.js @@ -1,25 +1,39 @@ javascript: (() => { - function doWork() { + var myInterval = setInterval(autoChecker, 500); + function autoChecker() { + console.log("Checking"); + teamList = document.getElementsByClassName('Tr'); + exists = document.getElementById('flag'); + if (teamList.length > 1 && !exists) { + doWork(); + clearInterval(myInterval); + document.getElementById("level").onchange = function () { + console.log("Switched division"); + myInterval = setInterval(autoChecker, 500); + }; + } + } + function doWork() { class dropDownFilter { teamList = document.getElementsByClassName('Tr'); totalFlags = []; flagImages = []; flagsCount = 0; flagBox = ""; - + constructor() { }; create() { - var regionBox = document.getElementById("region").parentElement.parentElement; - this.flagBox = regionBox.cloneNode(true); - this.flagBox.childNodes[0].childNodes[0].setAttribute("id", "flag"); - this.flagBox.childNodes[0].style.top = "10px"; - this.flagBox.childNodes[0].childNodes[0].innerHTML = ""; - - regionBox.parentElement.parentElement.parentElement.append(this.flagBox); - - this.flagBox = document.getElementById("flag"); + var regionBox = document.getElementById("region").parentElement.parentElement; + this.flagBox = regionBox.cloneNode(true); + this.flagBox.childNodes[0].childNodes[0].setAttribute("id", "flag"); + this.flagBox.childNodes[0].style.top = "10px"; + this.flagBox.childNodes[0].childNodes[0].innerHTML = ""; + + regionBox.parentElement.parentElement.parentElement.append(this.flagBox); + + this.flagBox = document.getElementById("flag"); } addDropDownFlag(flagName) { let newOption = document.createElement("option"); @@ -28,43 +42,43 @@ javascript: (() => { } addFlag(indexTeam) { this.flagOptions = this.flagBox.childNodes[0].childNodes[0]; - + let flagName = this.teamList[indexTeam].childNodes[1].childNodes[0].childNodes[0].title ?? this.teamList[indexTeam].childNodes[1].childNodes[0].childNodes[0].childNodes[0].textContent; for (let i = 0; i <= this.flagsCount; i++) { if (flagName == this.totalFlags[i]) return; } - + this.totalFlags[this.flagsCount] = flagName; this.flagsCount++; } - + fillDropDown() { for (let i = 0; i < this.totalFlags.length; i++) { this.addDropDownFlag(this.totalFlags[i]); } } - + indexFlags() { this.addDropDownFlag("Country"); - + for (let i = 1; i < this.teamList.length; i++) { this.addFlag(i); } - + this.totalFlags = this.totalFlags.sort(); this.fillDropDown(); } - + selectedCountry() { return document.getElementById("flag").value; } } countryBox = new dropDownFilter; - + class eseaHelper { teamList = document.getElementsByClassName('Tr'); qeuedTeams = []; removedTeams = 0; - + largeCutOff(teamsSize) { let newCuttOff = 0; switch (true) { @@ -113,7 +127,7 @@ javascript: (() => { } return newCuttOff; } - + smallCutOff(teamsSize) { let newCuttOff = 0; switch (true) { @@ -141,15 +155,15 @@ javascript: (() => { } return newCuttOff; } - + getDivision() { return document.getElementById("level").value; } - + getSeasonStage() { return seasonStage = document.getElementById("round").value; } - + getCutOff() { let cutOffValue = 0; let teamsSize = this.teamList.length - 1; @@ -169,18 +183,18 @@ javascript: (() => { } return cutOffValue; } - - printInfo(){ + + printInfo() { console.log("Division: " + this.getDivision()); let size = this.teamList.length - 1; console.log("Teams: " + size); console.log("Cutoff: " + this.getCutOff()); } - + filter() { let qeuedCount = 0; for (let i = 1; i < this.teamList.length; i++) { - + let currentFlag = this.teamList[i].childNodes[1].childNodes[0].childNodes[0].title ?? this.teamList[i].childNodes[1].childNodes[0].childNodes[0].childNodes[0].textContent; if (countryBox.selectedCountry() == "Country") { currentFlag = countryBox.selectedCountry(); @@ -197,9 +211,9 @@ javascript: (() => { let targetTeam = this.qeuedTeams[i]; targetTeam.style.backgroundColor = 'rgb(51, 52, 51)'; if (i % 2) targetTeam.style.backgroundColor = 'rgb(68, 68, 68)'; - + let teamRank = targetTeam.childNodes[0].textContent.slice(0, targetTeam.childNodes[0].textContent.length - 1); - + if (teamRank <= esea.getCutOff()) { targetTeam.childNodes[0].style.color = "green"; } else { @@ -208,15 +222,15 @@ javascript: (() => { } } } esea = new eseaHelper(); - + countryBox.create(); countryBox.indexFlags(); + document.getElementById("flag").onchange = function () { esea.filter(); }; + esea.printInfo(); esea.filter(); } - - doWork(); })(); \ No newline at end of file diff --git a/esea-league-filter.js b/esea-league-filter.js index 6648e70..4ca5e5a 100644 --- a/esea-league-filter.js +++ b/esea-league-filter.js @@ -1,6 +1,20 @@ -function doWork() { - +var myInterval = setInterval(autoChecker, 500); + +function autoChecker() { + console.log("Checking"); + teamList = document.getElementsByClassName('Tr'); + exists = document.getElementById('flag'); + if (teamList.length > 1 && !exists) { + doWork(); + clearInterval(myInterval); + document.getElementById("level").onchange = function () { + console.log("Switched division"); + myInterval = setInterval(autoChecker, 500); + }; + } +} +function doWork() { class dropDownFilter { teamList = document.getElementsByClassName('Tr'); totalFlags = []; @@ -10,15 +24,15 @@ function doWork() { constructor() { }; create() { - var regionBox = document.getElementById("region").parentElement.parentElement; - this.flagBox = regionBox.cloneNode(true); - this.flagBox.childNodes[0].childNodes[0].setAttribute("id", "flag"); - this.flagBox.childNodes[0].style.top = "10px"; - this.flagBox.childNodes[0].childNodes[0].innerHTML = ""; - - regionBox.parentElement.parentElement.parentElement.append(this.flagBox); - - this.flagBox = document.getElementById("flag"); + var regionBox = document.getElementById("region").parentElement.parentElement; + this.flagBox = regionBox.cloneNode(true); + this.flagBox.childNodes[0].childNodes[0].setAttribute("id", "flag"); + this.flagBox.childNodes[0].style.top = "10px"; + this.flagBox.childNodes[0].childNodes[0].innerHTML = ""; + + regionBox.parentElement.parentElement.parentElement.append(this.flagBox); + + this.flagBox = document.getElementById("flag"); } addDropDownFlag(flagName) { let newOption = document.createElement("option"); @@ -169,7 +183,7 @@ function doWork() { return cutOffValue; } - printInfo(){ + printInfo() { console.log("Division: " + this.getDivision()); let size = this.teamList.length - 1; console.log("Teams: " + size); @@ -179,7 +193,7 @@ function doWork() { filter() { let qeuedCount = 0; for (let i = 1; i < this.teamList.length; i++) { - + let currentFlag = this.teamList[i].childNodes[1].childNodes[0].childNodes[0].title ?? this.teamList[i].childNodes[1].childNodes[0].childNodes[0].childNodes[0].textContent; if (countryBox.selectedCountry() == "Country") { currentFlag = countryBox.selectedCountry(); @@ -198,7 +212,7 @@ function doWork() { if (i % 2) targetTeam.style.backgroundColor = 'rgb(68, 68, 68)'; let teamRank = targetTeam.childNodes[0].textContent.slice(0, targetTeam.childNodes[0].textContent.length - 1); - + if (teamRank <= esea.getCutOff()) { targetTeam.childNodes[0].style.color = "green"; } else { @@ -210,11 +224,11 @@ function doWork() { countryBox.create(); countryBox.indexFlags(); - /*document.getElementById("flag").onchange = function () { + + document.getElementById("flag").onchange = function () { esea.filter(); - };*/ + }; + esea.printInfo(); esea.filter(); -} - -doWork(); \ No newline at end of file +} \ No newline at end of file