-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_old.js
More file actions
64 lines (47 loc) · 1.53 KB
/
script_old.js
File metadata and controls
64 lines (47 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function parseCsv(cityName) {
const promise = fetch(`/csv/${cityName}.csv`)
.then((response) => response.text())
.then((data) => {
const list = data.split("\n")
return list
})
.then((list) => {
const users = []
for (let i = 1; i < list.length; i++) {
const s = list[i].trim()
const userList = s.split(",")
const userObject = {
name: userList[0],
username: userList[1]
}
users.push(userObject)
}
return users
})
.catch((error) => console.log(error))
return promise
}
function tohtml(userObject) {
const url = `https://community.infiniteflight.com/u/${userObject.username}/summary`
const a = document.createElement('a')
a.setAttribute('href', url)
a.setAttribute('target', "_self")
a.innerHTML += userObject.name
const p = document.createElement('p')
p.appendChild(a)
return p.outerHTML
}
function usersToHtmls(users) {
const htmls = []
for (let i = 0; i < users.length; i++) {
const userObject = users[i]
const html = tohtml(userObject)
htmls.push(html)
}
return htmls
}
function injectCityHtml(cityId, htmls) {
const cityDiv = document.getElementById(cityId)
const users = htmls.join(" <br> ")
cityDiv.innerHTML += users
}