Last active
June 1, 2025 18:53
-
-
Save 8bc/604d5d01446a405fa2460e3beec98a1d to your computer and use it in GitHub Desktop.
Zabbix Shortcuts + Sidebar Mode Switcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Zabbix Shortcuts + Sidebar Mode Switcher | |
// @namespace http://tampermonkey.net/ | |
// @version 2025-06-01 | |
// @description Keyboard shortcuts for Zabbix and sidebar mode switching. Toggle Zabbix sidebar modes with Ctrl/Cmd + 1/2/3. Latest Data = Ctrl/Cmd+Shift+L | |
// @author Bob Cechacek | |
// @match *://*/zabbix.php* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=zabbix.com | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
document.addEventListener('keydown', function (event) { | |
let link = null; | |
const isCmdOrCtrl = event.ctrlKey || event.metaKey; | |
const key = event.key.toLowerCase(); | |
// --- Never override Backspace or its combos (browser/system default) --- | |
if (key === 'backspace') { | |
return; | |
} | |
// --- Ctrl/Cmd + Shift + [key] Shortcuts --- | |
if (isCmdOrCtrl && event.shiftKey) { | |
// Ctrl/Cmd + Shift + F => Focus search input | |
if (key === 'f') { | |
event.preventDefault(); | |
const searchInput = document.getElementById('search'); | |
if (searchInput) { | |
searchInput.focus(); | |
} | |
return; | |
} | |
// Ctrl/Cmd + Shift + L => "Latest data" | |
if (key === 'l') { | |
event.preventDefault(); | |
window.location.href = '/zabbix.php?action=latest.view'; | |
return; | |
} | |
// Ctrl/Cmd + Shift + H => "Host view" | |
if (key === 'h') { | |
event.preventDefault(); | |
window.location.href = '/zabbix.php?action=host.view'; | |
return; | |
} | |
// (Add more shift-key combos here if needed.) | |
} | |
// --- Navigation Shortcuts (Ctrl/Cmd + [key]) --- | |
if (isCmdOrCtrl) { | |
// Skip interfering with browser's default Ctrl/Cmd + F, R, Arrow keys, etc. | |
const exceptionKeys = [ | |
'f', 'r', 'a', 'c', 'v', 'x', 'z', 'l', 'backspace', | |
'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight' | |
]; | |
if (exceptionKeys.includes(event.key) || exceptionKeys.includes(key)) { | |
return; | |
} | |
event.preventDefault(); | |
switch (key) { | |
case 'p': | |
link = document.querySelector('a[href="zabbix.php?action=problem.view"]'); | |
break; | |
case 't': | |
link = document.querySelector('a[href="zabbix.php?action=template.list"]'); | |
break; | |
case 'm': | |
link = document.querySelector('a[href="zabbix.php?action=maintenance.list"]'); | |
break; | |
case 'h': | |
link = document.querySelector('a[href="zabbix.php?action=host.list"]'); | |
break; | |
case 'u': | |
link = document.querySelector('a[href="zabbix.php?action=user.list"]'); | |
break; | |
case 'g': | |
link = document.querySelector('a[href="zabbix.php?action=usergroup.list"]'); | |
break; | |
case 'i': | |
window.location.href = '/zabbix.php?action=item.list&context=host'; | |
return; | |
} | |
if (link) { | |
link.click(); | |
} | |
} | |
// --- Sidebar Mode Switcher (Ctrl/Cmd + 1/2/3) --- | |
if (isCmdOrCtrl && ['1', '2', '3'].includes(event.key)) { | |
if (!isSidebarAvailable()) return; | |
event.preventDefault(); | |
const sidebarEl = document.querySelector('.sidebar'); | |
const sidebarInstance = new CSidebar(sidebarEl); | |
switch (event.key) { | |
case '1': | |
sidebarInstance.setViewMode(SIDEBAR_VIEW_MODE_FULL); | |
break; | |
case '2': | |
sidebarInstance.setViewMode(SIDEBAR_VIEW_MODE_COMPACT); | |
break; | |
case '3': | |
sidebarInstance.setViewMode(SIDEBAR_VIEW_MODE_HIDDEN); | |
break; | |
} | |
} | |
}); | |
function isSidebarAvailable() { | |
return ( | |
typeof CSidebar !== 'undefined' && | |
typeof SIDEBAR_VIEW_MODE_HIDDEN !== 'undefined' && | |
document.querySelector('.sidebar') | |
); | |
} | |
console.log('✅ Zabbix Lab Shortcuts, Sidebar Mode Switcher, and Search Enhancer are active'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment