forked from Knowit-Objectnet/browseit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getEmployees.js
40 lines (38 loc) · 1.3 KB
/
getEmployees.js
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
var getEmployees = async function() {
let data = await fetch(
"https://projects.knowit.no/pages/viewpage.action?pageId=55805057",
{ credentials: "include", sameSite: false }
)
.then(result => {
if (result.redirected) {
throw "Error loading employees";
} else {
return result.text();
}
})
.then(html => {
// Parse HTML table to an array of tuples {name, imageURL}
let result = [];
var parser = new DOMParser();
var doc = parser.parseFromString(html, "text/html");
var employees = Array.from(doc.querySelectorAll("tr")).slice(1);
employees.forEach(function(person) {
const name = person.querySelector(".confluence-userlink");
const img = person.querySelector(".confluence-embedded-image");
if (name && img) {
var imgUrl = img.getAttribute("src");
// Images are hosted on multiple domains
// If domain is not specified it defaults to projects.knowit.no
if (!imgUrl.includes("https://")) {
imgUrl = "https://projects.knowit.no" + imgUrl;
}
result.push({ name: name.innerText, img: imgUrl });
}
});
return result;
})
.catch(e => {
throw e;
});
return data;
};