-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
43 lines (37 loc) · 1.17 KB
/
content.js
File metadata and controls
43 lines (37 loc) · 1.17 KB
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
/******************************************************
* content.js
* Reads the user's account→color config from storage,
* detects the current AWS account in the URL,
* and applies the user's chosen color to the top nav.
******************************************************/
(function() {
const host = window.location.hostname;
const match = host.match(/^(\d+)-/);
const accountId = match ? match[1] : null;
if (!accountId) return;
chrome.storage.sync.get({ accountColors: {} }, (result) => {
const color = result.accountColors[accountId];
if (!color) return;
const possibleNavSelectors = [
'#awsc-top-level-nav',
'header[class*="awsc-header"]',
'header[class*="globalNav"]',
'[class*="awsc-nav"]'
];
function applyColor() {
for (const selector of possibleNavSelectors) {
const element = document.querySelector(selector);
if (element) {
element.style.backgroundColor = color;
return true;
}
}
return false;
}
// Try immediately
if (!applyColor()) {
// If not found, try again after a short delay
setTimeout(applyColor, 1000);
}
});
})();