// ==UserScript== // @name Checkmk SwissKnife // @namespace https://luigidacunto.com/ // @version 2.8.0 // @description Raccolta di miglioramenti all'interfaccia di Checkmk WATO. Ogni fix o enhancement viene aggiunto qui come feature indipendente. // @author Luigi D'Acunto // @homepageURL https://git.luigidacunto.com/tools/checkmk-swissknife // @updateURL https://luigidacunto.com/scripts/checkmk-swissknife/user_script/checkmk_swissknife.user.js // @downloadURL https://luigidacunto.com/scripts/checkmk-swissknife/user_script/checkmk_swissknife.user.js // @include /^https?:\/\/.+\/check_mk\/(index|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; } // Legge il parametro "mode" dall'URL del documento target senza accedere al DOM function getPageMode(iDoc) { try { return new URLSearchParams(iDoc.location.search).get('mode') || ''; } catch (e) { return ''; } } // Restituisce il documento su cui operare, gestendo sia il caso iframe (index.py con // sidebar) che il caso direct (wato.py aperto senza sidebar, nessun iframe presente). function getTargetDoc() { const iframe = document.querySelector('iframe[name="main"], iframe#main'); if (iframe) { try { return iframe.contentDocument; } catch (e) { return null; } } return document; } // Pagine che supportano gli accordion badge (stessa struttura form_edit_host + table.nform) const ACCORDION_MODES = new Set(['edit_host', 'bulkedit']); // 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