From 20f1e598ae13eeea6280ae8ac9bfd841667bd62b Mon Sep 17 00:00:00 2001 From: Luigi D'Acunto Date: Thu, 4 Jun 2026 12:43:24 +0200 Subject: [PATCH] Initial commit --- checkmk_swissknife.user.js | 462 +++++++++++++++++++++++++++++++++++++ 1 file changed, 462 insertions(+) create mode 100644 checkmk_swissknife.user.js diff --git a/checkmk_swissknife.user.js b/checkmk_swissknife.user.js new file mode 100644 index 0000000..19011ce --- /dev/null +++ b/checkmk_swissknife.user.js @@ -0,0 +1,462 @@ +// ==UserScript== +// @name Checkmk SwissKnife +// @namespace https://checkmk.example.com/ +// @version 2.0 +// @description Raccolta di miglioramenti all'interfaccia di Checkmk WATO. Ogni fix o enhancement viene aggiunto qui come feature indipendente. +// @author Luigi D'Acunto +// @match *://checkmk.example.com/*/index.py* +// @match *://checkmk.example.com/*/wato.py* +// @grant none +// ==/UserScript== + +(function () { + 'use strict'; + + // ========================================================================= + // INFRASTRUTTURA COMUNE + // ========================================================================= + + const LOG_PREFIX = '[CMK-SK]'; + const POLL_INTERVAL_MS = 500; + const MAX_ATTEMPTS = 60; + + // Ricava il documento su cui operare: + // - Se c'è un iframe (index.py con sidebar) → usa il contentDocument dell'iframe + // - Se wato.py è aperto direttamente → usa document solo se contiene la select target + function getWatoDoc(selectId) { + const iframe = document.querySelector('iframe[name="main"], iframe#main'); + if (iframe) { + try { return iframe.contentDocument; } catch (e) { return null; } + } + if (document.getElementById(selectId) || + document.querySelector('select[name*="folder_path"]')) { + return document; + } + return null; + } + + // Inietta CSS nel documento target (una sola volta, deduplica per id) + function injectStyles(iDoc, id, css) { + if (iDoc.getElementById(id)) return; + const style = iDoc.createElement('style'); + style.id = id; + style.textContent = css; + iDoc.head.appendChild(style); + } + + + // ========================================================================= + // FEATURE: Folder Path Select Enhancement + // + // Migliora la