-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpretty-aws-navbar.user.js
133 lines (107 loc) · 3.71 KB
/
pretty-aws-navbar.user.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// ==UserScript==
// @name pretty-aws-navbar
// @description Prettify the AWS Console's Navigation Bar.
// @include https://console.aws.amazon.com/console/home?region=us-east-1#
// @include https://console.aws.amazon.com/*/home*
// @include https://*.console.aws.amazon.com/*/home*
// @include https://*.console.aws.amazon.com/GetResource/Console.html*
// @exclude https://console.aws.amazon.com/s3/home*
// @version 2.0
// ==/UserScript==
//
/* ------------------- */
/* YOUR ACCOUNTS HERE! */
/* ------------------- */
const accountColors = new Map([
['foo', 'CornflowerBlue'],
['bar', 'FireBrick'],
['baz', 'OliveDrab'],
]);
function prettify() {
prettifyNavBar();
prettifyRegion();
}
function prettifyNavBar() {
let accountElement = document.querySelector('[data-testid="awsc-nav-account-menu-button"]');
let account = accountElement.innerText.split('@')[1].trim();
if(!isEmpty(account) && accountColors.has(account)) {
let color = accountColors.get(account);
let styleSheet = document.createElement('style');
styleSheet.setAttribute('type', 'text/css');
styleSheet.textContent = buildNavBar(color);
document.head.appendChild(styleSheet);
} else {
console.error('could not determine the account or the account styling.');
}
}
function buildNavBar(color) {
let headerFooterSelectors = `
#console-nav-footer-inner,
[data-testid="awsc-nav-header-viewport-shelf-inner"] {
background : linear-gradient(to bottom, ${color} 0px, #000 100%);
}`;
let dropDownSelectors = `
[data-testid="awsc-nav-service-menu"],
[data-testid="awsc-footer-language-selector-content"],
[data-testid="awsc-nav-regions-menu-content"],
[data-testid="awsc-nav-account-menu-content"],
[data-testid="awsc-nav-support-menu-content"],
[data-testid="awsc-phd__bell-icon"] ~ div,
#awsc-navigation__more-menu--list > [role="menuitem"] > div > div,
#search-widget-dropdown {
background: linear-gradient(to top, ${color} 0px, #000 100%);
}`;
let search = `
#search-widget-input {
background : none !important;
}
#search-widget-input:focus {
border : 2px solid white !important;
box-shadow: 0 0 0 1px ${color} inset !important;
}
[id^="search-widget-result-"]:hover {
background: none; !important;
border : 2px solid white !important;
}
[id^="search-widget-result-"] > span > mark {
color: white !important;
}
`;
let favorites = `
[data-testid^="favorites-list-item"] {
border: 2px solid transparent;
}
[data-testid^="favorites-list-item"]:hover {
background: none;
border: 2px solid white;
}`;
return `${headerFooterSelectors} ${dropDownSelectors} ${search} ${favorites}`;
}
function extractRegionName(str) {
var regionNameRegex = /.*\((.*)\).*/g;
var match = regionNameRegex.exec(str);
return match[1];
}
function extractRegionCode(str) {
var regionCodeRegex = /.*\)(.*)/g;
var match = regionCodeRegex.exec(str);
return match[1];
}
function prettifyRegion() {
// Scrape the page for the region map rather than hardcode it.
let regions = new Map();
document.querySelectorAll('#menu--regions > [role="menuitem"]').forEach(x => {
regions.set(extractRegionName(x.textContent), extractRegionCode(x.textContent));
});
let regionElement = document.querySelector('[data-testid="awsc-nav-regions-menu-button"]');
let region = regionElement.innerText;
if(!isEmpty(region) && regions.has(region)) {
regionElement.innerText = `${region}: ${regions.get(region)}`;
} else {
console.error('could not determine the region code or the region name.');
}
}
function isEmpty(str) {
return (!str || 0 === str.length);
}
setTimeout(prettify, 1000);