Skip to content

Instantly share code, notes, and snippets.

@macintacos
Last active May 2, 2020 17:00
Show Gist options
  • Save macintacos/067558fe734bbbb99a50dda88fad26c9 to your computer and use it in GitHub Desktop.
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.
// ==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