const fflog = "https://www.fflogs.com:443/v1/report/fights/"; const api = "?api_key="; var indexViewModel; var classColors = { "Scholar": "#4c49b2", "WhiteMage": "#c7bf8e", "Astrologian": "#8c501e", "Paladin": "#8aa8a8", "Gunbreaker": "#6c6433", "Warrior": "#610e0a", "DarkKnight": "#241011", "Ninja": "#b30000", "Dragoon": "#3b4ba0", "Monk": "#c58d1c", "Samurai": "#9e6d35", "RedMage": "#47132a", "BlackMage": "#261947", "Summoner": "#59922b", "Dancer": "#ceb8ab", "Machinist": "#6c6433", "Barde": "#6d8432" }; // Do stuff when HTML parsing is ready $(() => { // Document is ready function IndexViewModel() { var self = this; self.apiKey = ko.observable(localStorage.getItem("apikey")); self.logID = ko.observable(localStorage.getItem("fflogid")); self.fights = ko.observableArray(); self.friendlies = ko.observableArray(); self.displayFightPicker = ko.observable(false); self.selectedFight = ko.observable(); self.getLog = async function() { var log = await fetchLog(self.logID()); self.fights(log["fights"]); self.friendlies(log["friendlies"]); self.displayFightPicker(true); }; self.formatTime = function(fight) { let secs = (fight.end_time - fight.start_time)/1000; let mins = Math.floor(secs / 60); let rest = Math.floor(secs % 60); return mins+"m"+rest+"s"; }; self.apiKeyChanged = function() { console.log("Setting apiKey to ",self.apiKey()); localStorage.setItem("apikey",self.apiKey()); localStorage.setItem("fflogid", self.logID()); }; self.fightChanged = function() { console.log("Fight has changed to ",self.selectedFight()); }; self.textColor = function(job) { console.log(job.type) return classColors[job.type]; } }; indexViewModel = new IndexViewModel(); ko.applyBindings(indexViewModel); }); // API request um JSON zu erhalten async function fetchLog(fightId) { let url = fflog + fightId + api + indexViewModel.apiKey(); console.log("Fetching log "+fightId); var res = await fetch(url); if (!res.ok) { console.log(res); throw Error(res.text); } var log = await res.json(); //get specific fight data console.log(log); return log; }