Skip to content

Instantly share code, notes, and snippets.

@Gabrielcarvfer
Last active April 7, 2025 22:29
Show Gist options
  • Save Gabrielcarvfer/9a89545231138797596d76a86fe85af4 to your computer and use it in GitHub Desktop.
Save Gabrielcarvfer/9a89545231138797596d76a86fe85af4 to your computer and use it in GitHub Desktop.
Make Gitlab navigation less bad, like it was in the past
// ==UserScript==
// @name Make Gitlab navigation great again
// @namespace http://tampermonkey.net/
// @version 0.5
// @description Trying to make the new Gitlab navigation feel less crappy
// @author Gabriel Ferreira
// @match https://gitlab.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=gitlab.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
var top_bar_container = document.getElementsByClassName("top-bar-container");
// Create subdivision to hold buttons on the far-right of the screen,
// where they were before Gitlab had a brain fart
var right_buttons_div = document.createElement('div');
right_buttons_div.id = "good_old_menu";
right_buttons_div.class = "gl-display-flex gl-p-3 gl-gap-1 gl-flex-direction-column";
// Copy search bar
right_buttons_div.appendChild(document.getElementById('super-sidebar-search'));
// Copy issues button
right_buttons_div.appendChild(document.querySelectorAll('[data-testid="issues-shortcut-button"]')[0]);
// Copy merge requests button
right_buttons_div.appendChild(document.querySelectorAll('[data-testid="merge-requests-shortcut-button"]')[0]);
// Copy todo button
right_buttons_div.appendChild(document.querySelectorAll('[data-testid="todos-shortcut-button"]')[0]);
// Copy + button
right_buttons_div.appendChild(document.getElementById('create-menu-toggle'));
// Copy user button
right_buttons_div.appendChild(document.querySelectorAll('[data-testid="user-dropdown"]')[0]);
// Adjust display to inline-block to get them in a row
for (var i = 0; i < right_buttons_div.children.length; i++) {
// Prevent merge requests button from being retarded
right_buttons_div.children[i].classList.remove("gl-w-full");
right_buttons_div.children[i].style.display = "inline-block";
// Add some spacing
right_buttons_div.children[i].style.padding = "8px";
}
// Put the top bar back to where it belong
top_bar_container[0].appendChild(right_buttons_div);
// Reduce size of stupid side bar
document.getElementById('super-sidebar').style.width = "210px";
// Increase size of actually useful search bar
document.getElementById('super-sidebar-search').style.width = "400px";
// Reduce gap after gitlab logo
document.getElementsByClassName("user-bar")[0].classList.remove("gl-gap-3")
var top_level_entries_section = document.querySelectorAll('[data-testid="static-items-section"]')[0];
if (top_level_entries_section)
{
top_level_entries_section = top_level_entries_section.parentElement;
// Move useful sections to the outer list
var pinned_entries = ["activity",
"files",
"project_issue_list",
"milestones",
"project_merge_request_list",
"pipelines"
]
for (i = 0; i < pinned_entries.length; i++)
{
var entry_to_move = document.querySelectorAll('[data-track-label="'+pinned_entries[i]+'"]')[0];
if (entry_to_move)
{
top_level_entries_section.appendChild(entry_to_move);
}
}
}
// Remove dumb sections
var elements_to_remove = ["menu-section-button-pinned",
"menu-section-button-plan",
"menu-section-button-manage",
"menu-section-button-code",
"menu-section-button-build",
"menu-section-button-deploy",
"menu-section-button-operate",
"menu-section-button-monitor",
"menu-section-button-analyze"
]
for (i = 0; i < elements_to_remove.length; i++)
{
var left_menu_section_to_remove = document.getElementById(elements_to_remove[i]);
if (left_menu_section_to_remove)
{
left_menu_section_to_remove.parentElement.innerHTML = "";
}
}
const sheet = new CSSStyleSheet();
// Reduce main column left padding
sheet.replaceSync(`
@media (min-width: 1200px) {
.page-with-super-sidebar {
padding-left: 14rem;
}
}
@media (min-width: 1200px) {
.page-with-super-sidebar {
--application-bar-left: 14rem;
}
}
.content-wrapper .container-fluid, .content-wrapper .container-sm, .content-wrapper .container-md, .content-wrapper .container-lg, .content-wrapper .container-xl {
padding: 0 0px;
}
`);
document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
// Nuke every event listener that hijacks links in the new issues board...
const observer = new MutationObserver((mutations, obs) => {
const links = document.getElementsByClassName('gl-link');
if (links.length > 0) {
obs.disconnect();
document.body.addEventListener('click', (e) => {
const classes = [...e.srcElement.classList, ...e.srcElement.parentElement.classList, ...e.srcElement.parentElement.parentElement.classList];
if(classes.some(test_class => test_class.includes("issue-title")))
{
e.stopPropagation(); // prevents bubbling up
e.stopImmediatePropagation(); // blocks other handlers on same element
}
}, true);
obs.observe(document.body, {
childList: true,
subtree: true,
});
}
});
const url = window.location.pathname;
if (/\/issues(?:\/|-\/|\/?$)(?!\d)/.test(url)) {
observer.observe(document.body, {
childList: true,
subtree: true,
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment