Last active
May 2, 2020 17:00
-
-
Save macintacos/067558fe734bbbb99a50dda88fad26c9 to your computer and use it in GitHub Desktop.
Bringing icons (in an emoji form) back to the MongoDB Atlas UI. Add this as your own UserScript in something like Tampermonkey and it'll give you emojis for the icons in the left-hand bar.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Gimme My Icons Plz | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Adding emojis in place of icons for the Atlas Project UI. This now handles the new redesign properly. | |
// @author macintacos | |
// @match https://cloud.mongodb.com/v2/* | |
// @exclude https://cloud.mongodb.com/v2/admin* | |
// @require http://code.jquery.com/jquery-3.4.1.min.js | |
// @grant none | |
// ==/UserScript== | |
/* eslint-disable no-undef */ | |
(function () { | |
"use strict"; | |
let menuItems = [ | |
{ | |
menuTitle: "Clusters", | |
newText: "π Clusters", | |
}, | |
{ | |
menuTitle: "Data Lake", | |
newText: `π Data Lake <span class="css-npw7us">BETA</span>`, | |
}, | |
{ | |
menuTitle: "Deployment", | |
newText: "π Deployment", | |
}, | |
{ | |
menuTitle: "Database Access", | |
newText: "π Database Access", | |
}, | |
{ | |
menuTitle: "Network Access", | |
newText: "π‘ Network Access", | |
}, | |
{ | |
menuTitle: "Advanced", | |
newText: "π Advanced", | |
}, | |
{ | |
menuTitle: "Access Manager", | |
newText: "π Access Manager", | |
}, | |
{ | |
menuTitle: "Continuous", | |
newText: "πΎ Cont. Backup", | |
}, | |
{ | |
menuTitle: "Activity Feed", | |
newText: "π§Ύ Activity Feed", | |
}, | |
{ | |
menuTitle: "Alerts", | |
newText: "π Alerts", | |
}, | |
{ | |
menuTitle: "Integrations", | |
newText: "𧩠Integrations", | |
}, | |
{ | |
menuTitle: "Settings", | |
newText: "βοΈ Settings", | |
}, | |
{ | |
menuTitle: "Charts", | |
newText: "π Charts", | |
}, | |
{ | |
menuTitle: "Stitch", | |
newText: "𧡠Stitch", | |
}, | |
{ | |
menuTitle: "Triggers", | |
newText: "π« Triggers", | |
}, | |
{ | |
menuTitle: "Docs", | |
newText: "π Docs", | |
}, | |
{ | |
menuTitle: "Support", | |
newText: "π ββοΈ Support", | |
}, | |
]; | |
function detectElement(label) { | |
let activeElement = `19zsrcl`; | |
let otherElement = `1aen1ds`; | |
let element = $(`.leafygreen-ui-${otherElement}:contains(${label})`).text() | |
? $(`.leafygreen-ui-${otherElement}:contains(${label})`) | |
: $(`.leafygreen-ui-${activeElement}:contains(${label})`); | |
if (!element.text()) { | |
// These are for elements that are considered "inactive", and thus have a different leafygreen value | |
let inactiveElement = `16rhx3s`; | |
element = $(`.leafygreen-ui-${inactiveElement}:contains(${label})`); | |
} | |
return element; | |
} | |
function convertElement(element, textToReplaceWith) { | |
element.html(`${textToReplaceWith}`); | |
} | |
function addIconsToSidebar() { | |
let checkExist = setInterval(function () { | |
// Using this to check if we've been loaded | |
let buttons = [ | |
$('[data-testid="project-nav-invite"]'), | |
$('[data-testid="project-nav-atlas"]'), | |
$('[data-testid="project-nav-activity-feed"]'), | |
$('[data-testid="project-nav-alerts"]') | |
] | |
let leftNavLinks = $(".leafygreen-ui-bdnco"); | |
// Only do this next part if we have some navigation links to mess with | |
if (buttons) { | |
// First we do the buttons to make sure they have the event handlers | |
for (let button of buttons) { | |
button.click(addIconsToSidebar); | |
} | |
if (leftNavLinks.length) { | |
// Now we do the sidebar | |
let alertsSpanWidgetText = $(".alerts-widget").text(); | |
for (let item of menuItems) { | |
let currentElement = detectElement(item.menuTitle); | |
if (item.menuTitle === "Alerts") { | |
// Special handling of alerts because it has a badge we need to keep track of | |
convertElement( | |
currentElement, | |
`${item.newText} <span class="alerts-widget">${alertsSpanWidgetText}</span>` | |
); | |
} else { | |
convertElement(currentElement, `${item.newText}`); | |
} | |
} | |
// No need to check if the elements exist anymore at this point | |
clearInterval(checkExist); | |
} | |
} | |
}, 100); // check every 100ms | |
} | |
window.onload = addIconsToSidebar; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment