-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreverseNames.js
66 lines (60 loc) · 2.83 KB
/
reverseNames.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const checkForNames = () => {
// get the Meeting details > Participants container node
const participantsContainer = document.querySelector('[aria-label="Participants"]');
// Ends if the participantsContainer doesn't exist
if (!participantsContainer) return;
// convert the HTMLCollection to an iterable
const participantsElements = Array.from(participantsContainer.children ?? []);
participantsElements.forEach((participantElement, i) => {
// find the img element as it should be the previousSibling to the name container
const [imageElement] = participantElement.getElementsByTagName('img');
const nameContainer = imageElement?.nextSibling;
if (nameContainer) {
// get the actual element that contains the participant's name
const [nameElement] = nameContainer.getElementsByTagName('span');
if (nameElement) {
// cater for participants with more than 1 last name
if (!nameElement.textContent.includes(',')) {
const [fName, lName, ...names] = nameElement.textContent.split(' ');
nameElement.textContent = `${lName}${names.length ? ' ' + names.join(' ') : ''}, ${fName}`;
// Sorts the array of students by last name on the final iteration
if (i == (participantsElements.length - 1)) {
try {
participantsElements.sort(function(a, b) {
var nameA = a.children[0].children[1].children[0].innerText.split(",")[0].toUpperCase(); // grabs last name from child div
var nameB = b.children[0].children[1].children[0].innerText.split(",")[0].toUpperCase(); // grabs last name from child div
if (nameA < nameB) {
return -1;
}
if (nameA > nameB) {
return 1;
}
return 0;
});
// Removes elements to replace them in sorted order
// This is really janky but it works
console.log("Participants Container:");
console.log(participantsContainer);
console.log("Participants Elements (To Array):");
console.log(participantsElements);
participantsElements.forEach(function(element) {
element.remove();
participantsContainer.append(element);
});
console.log("Sorted!");
console.log("Participants Container:");
console.log(participantsContainer);
console.log("Participants Elements (To Array):");
console.log(participantsElements);
}
catch(e) {
console.log("Participants Sorting Failed! Exiting...")
console.log(e)
}
}
}
}
}
});
};
setInterval(checkForNames, 1500);