-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent.js
53 lines (43 loc) · 1.32 KB
/
content.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
//Max Attempts
var maxAttempts = 10;
var totalAttempts = 0;
//Attempt to get Elements
var elements = document.getElementsByClassName('ghx-field-icon');
//Wait for load
waitForReady(onwardFunction, fallbackFunction);
//Recursive loop to check if elements are returned. Otherwise continue to wait.
function waitForReady(callback, fallback) {
if(totalAttempts >= maxAttempts) {
fallback();
} else {
totalAttempts++;
setTimeout(function(){
if(elements.length > 0) {
callback();
}
else {
waitForReady(callback);
}
}, 100);
}
}
//Continue with your code execution within this function
function onwardFunction() {
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
var node = element.attributes['data-tooltip']
var attribute = node.nodeValue
//TODO: Add more issue types and priorities.
if (attribute == "Bug") {
element.replaceWith(document.createTextNode("🐛"));
} else if (attribute == "Story") {
element.replaceWith(document.createTextNode("✨"))
} else if (attribute == "Improvement") {
element.replaceWith(document.createTextNode("⚒"))
}
}
}
//fallback function if elements were not found within max attempts
function fallbackFunction() {
console.log("Could not find all the needed elements");
}