Skip to content

Instantly share code, notes, and snippets.

@gmcabrita
Created December 3, 2024 14:50
Show Gist options
  • Save gmcabrita/55568fcc1c4bd11f20b4f33980696555 to your computer and use it in GitHub Desktop.
Save gmcabrita/55568fcc1c4bd11f20b4f33980696555 to your computer and use it in GitHub Desktop.
karafka web ui, hide topic lags at 0 from tooltip
// ==UserScript==
// @name Karafka Web UI Fixes
// @description Fixes some Karakfa Web UI annoyances
// @namespace http://tampermonkey.net/
// @version 2024-12-03
// @author Gonçalo Cabrita
// @match *://*/karafka/dashboard*
// @updateURL https://gist.github.com/gmcabrita/55568fcc1c4bd11f20b4f33980696555/raw/karafka_web_ui.user.js
// @downloadURL https://gist.github.com/gmcabrita/55568fcc1c4bd11f20b4f33980696555/raw/karafka_web_ui.user.js
// @supportURL https://gist.github.com/gmcabrita/55568fcc1c4bd11f20b4f33980696555#new_comment_field
// @grant none
// ==/UserScript==
(function() {
'use strict';
function modifyChart(chart) {
const originalFilter = chart.config.options.plugins.tooltip.filter;
chart.config.options.plugins.tooltip.filter = function(tooltipItem, currentIndex, tooltipItems) {
if (tooltipItem.raw[1] === 0) return false;
return originalFilter ? originalFilter(tooltipItem, currentIndex, tooltipItems) : true;
};
chart.update('none');
}
// Monitor for new charts
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
mutation.addedNodes.forEach((node) => {
if (node.classList?.contains('chartjs-line')) {
const chart = Chart.getChart(node);
if (chart) {
modifyChart(chart);
}
}
});
});
});
// Start observing
observer.observe(document.body, {
childList: true,
subtree: true
});
// Modify existing charts
document.querySelectorAll('.chartjs-line').forEach((node) => {
const chart = Chart.getChart(node);
if (chart) {
modifyChart(chart);
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment