-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
61 lines (52 loc) · 1.89 KB
/
script.js
File metadata and controls
61 lines (52 loc) · 1.89 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// ==UserScript==
// @name Azure Nav Highlighter
// @namespace https://github.com/BenDutton/AzureNavHighlighter
// @version 1.2.0
// @description Highlight the Azure nav bar based off the current environment
// @author Benjamin Dutton
// @match https://*.portal.azure.com/*
// @updateURL https://raw.githubusercontent.com/BenDutton/AzureNavHighlighter/master/script.js
// @downloadURL https://raw.githubusercontent.com/BenDutton/AzureNavHighlighter/master/script.js
// @grant none
// @run-at document-end
// ==/UserScript==
(function () {
"use strict";
const SELECTORS = {
topBar: ".fxs-topbar",
tenant: ".fxs-avatarmenu-tenant",
username: ".fxs-avatarmenu-username",
};
const POLL_INTERVAL_MS = 100;
function intToColorHex(num) {
const hex = (num & 0x00ffffff).toString(16).toUpperCase();
return hex.padStart(6, "0");
}
function stringToRGB(str) {
let hash = 0;
for (const char of str) {
hash = char.charCodeAt(0) + ((hash << 5) - hash);
}
return `#${intToColorHex(hash)}`;
}
function getElementText(selector) {
const element = document.querySelector(selector);
return element?.textContent ?? "";
}
function updateTopBar(tenant, username) {
const topBar = document.querySelector(SELECTORS.topBar);
if (topBar) {
topBar.style.background = `linear-gradient(90deg, ${stringToRGB(username)}, ${stringToRGB(tenant)})`;
}
}
function waitForElements() {
const tenant = getElementText(SELECTORS.tenant);
const username = getElementText(SELECTORS.username);
if (tenant.length > 0 && username.length > 0) {
updateTopBar(tenant, username);
} else {
setTimeout(waitForElements, POLL_INTERVAL_MS);
}
}
waitForElements();
})();