Patrick Engel
5 years ago
1 changed files with 61 additions and 0 deletions
@ -0,0 +1,61 @@ |
|||
const fflog = "https://www.fflogs.com:443/v1/report/fights/"; |
|||
const api = "?api_key="; |
|||
|
|||
var indexViewModel; |
|||
|
|||
// 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(""); |
|||
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()); |
|||
}; |
|||
|
|||
self.fightChanged = function() { |
|||
console.log("Fight has changed to ",self.selectedFight()); |
|||
}; |
|||
}; |
|||
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; |
|||
} |
Loading…
Reference in new issue