-
Notifications
You must be signed in to change notification settings - Fork 0
/
content-script.js
73 lines (66 loc) · 3.23 KB
/
content-script.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
67
68
69
70
71
72
document.onreadystatechange = function () {
if (document.readyState == "complete") {
arnToLinks = function() {
document.querySelectorAll(".awsui-table-row").forEach(row => {
var search = row.querySelector('span>span[title^="arn:aws:elasticloadbalancing"]')
// console.log(search)
if(search != null) {
var arnSplit = search.innerHTML.split(":")
// console.log(arnSplit)
// console.log(arnSplit[5].split("/"))
if(arnSplit[5].split("/")[0] == "loadbalancer" || arnSplit[5].split("/")[0] == "listener"){
var lbName = arnSplit[5].split("/")[2]
var lbLink = window.location.origin+"/ec2/home#LoadBalancers:search="+lbName+";sort=loadBalancerName";
var a = document.createElement('a');
a.setAttribute('href',lbLink);
a.setAttribute('target',"_blank");
a.innerHTML = search.innerHTML;
search.innerHTML = ""
search.appendChild(a)
}
else if(arnSplit[5].split("/")[0] == "targetgroup") {
var tgLink = window.location.origin+"/ec2/home#TargetGroup:targetGroupArn="+search.innerHTML;
var a = document.createElement('a');
a.setAttribute('href',tgLink);
a.setAttribute('target',"_blank");
a.innerHTML = search.innerHTML;
search.innerHTML = ""
search.appendChild(a)
}
}
})
}
observe = function() {
// Select the node that will be observed for mutations
const targetNodes = document.querySelectorAll('.cfn-details-table');
// Options for the observer (which mutations to observe)
const config = { attributes: true, childList: true, subtree: true };
// Callback function to execute when mutations are observed
const callback = (mutationList, observer) => {
for (const mutation of mutationList) {
// console.log(mutation.type)
if (mutation.type === 'childList') {
// console.log(document.querySelectorAll(".awsui-table-row"))
arnToLinks()
}
}
};
// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
targetNodes.forEach( (targetNode) => {
observer.observe(targetNode, config);
})
// Later, you can stop observing
// observer.disconnect();
}
//wait 2 seconds so that data can load
setTimeout(function () {
arnToLinks()
}, 2000);
tabs = document.querySelectorAll('ul[role="tablist"]')
tabs.forEach(tab => {
tab.addEventListener("click", observe);
});
}
}