-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentScript.js
56 lines (52 loc) · 1.62 KB
/
contentScript.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
const injectedScript ="(" +
function() {
const getVaccineType = (boosterDays) => {
switch (boosterDays) {
case 21:
return "<b>PFIZER</b>";
case 28:
return "<b>MODERNA</b>";
case 56:
return "<b>ASTRAZENECA</b>";
default:
return "<b>N/A</b>";
}
}
const updateType = (centres) => {
let spans = [...document.getElementsByClassName("cdk-column-name")];
centres.forEach(elem => {
spans.forEach(span => {
if (span.innerText.includes(elem.name.trim().replace(/\s\s/g, " "))) {
span.innerHTML = "(" + getVaccineType(elem.boosterDays) + ") " + span.innerText;
}
})
})
}
const monkeyPatch = () => {
let oldXHROpen = window.XMLHttpRequest.prototype.open;
window.XMLHttpRequest.prototype.open = function() {
this.addEventListener("load", function() {
if (this.__zone_symbol__xhrURL.includes("/scheduling/api/centres")) {
const responseBody = JSON.parse(this.responseText);
setTimeout(function () {updateType(responseBody.content);}, 500);
}
});
return oldXHROpen.apply(this, arguments);
};
};
monkeyPatch();
} + ")();";
const injectScript = () => {
var script = document.createElement("script");
script.textContent = injectedScript;
(document.head || document.documentElement).appendChild(script);
script.remove();
};
function checkForDOM() {
if (document.body && document.head) {
injectScript();
} else {
requestIdleCallback(checkForDOM);
}
}
requestIdleCallback(checkForDOM);