cmagnuson

Taller Zendesk Macro Menu

Jul 15th, 2025 (edited)
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 5.17 KB | Software | 0 0
  1. // ==UserScript==
  2. // @name         Zendesk Taller Macro Menu (75% Height with Scrolling)
  3. // @namespace    http://tampermonkey.net/
  4. // @version      1.3
  5. // @description  Makes the Zendesk macro dropdown menu 75% of window height with working scroll and navigation
  6. // @author       You
  7. // @match        https://*.zendesk.com/agent/*
  8. // @grant        GM_addStyle
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.     'use strict';
  13.  
  14.     // Add custom CSS for the macro menu
  15.     GM_addStyle(`
  16.         /* Main macro dropdown - set height but keep overflow auto for scrolling */
  17.         .macro-suggestions,
  18.         .macros_dropdown,
  19.         [data-test-id="macro-suggestions"],
  20.         [data-garden-id="dropdowns.menu"],
  21.         [aria-label*="macro" i] {
  22.             max-height: 75vh !important;
  23.             height: auto !important;
  24.             overflow-y: auto !important;
  25.             overflow-x: hidden !important;
  26.         }
  27.  
  28.         /* Inner scrollable container - if it exists separately */
  29.         .macro-list,
  30.         .macros-list,
  31.         [data-test-id="macro-list"],
  32.         [data-garden-id="dropdowns.menu"] > ul,
  33.         .macros_dropdown > ul,
  34.         .macro-suggestions > ul {
  35.             max-height: calc(75vh - 40px) !important;
  36.             overflow-y: auto !important;
  37.             overflow-x: hidden !important;
  38.         }
  39.  
  40.         /* Keep navigation header visible */
  41.         .macro-suggestions-header,
  42.         .macros_dropdown-header,
  43.         .macro-navigation,
  44.         .macro-folder-navigation,
  45.         [data-test-id="macro-suggestions"] > div:first-child:has(button),
  46.         [data-garden-id="dropdowns.menu"] > header {
  47.             position: sticky !important;
  48.             top: 0 !important;
  49.             z-index: 100 !important;
  50.             background: white !important;
  51.             border-bottom: 1px solid #e9ebed !important;
  52.         }
  53.  
  54.         /* Back button and breadcrumbs */
  55.         [aria-label="Back"],
  56.         [data-test-id="back-button"],
  57.         button[aria-label*="folder"],
  58.         .macro-folder-back {
  59.             display: flex !important;
  60.             visibility: visible !important;
  61.         }
  62.  
  63.         /* Search box if present */
  64.         .macro-search,
  65.         input[placeholder*="Search macros"],
  66.         input[placeholder*="Filter macros"] {
  67.             position: sticky !important;
  68.             top: 0 !important;
  69.             z-index: 99 !important;
  70.             background: white !important;
  71.         }
  72.  
  73.         /* Ensure proper scrollbar styling */
  74.         .macro-suggestions::-webkit-scrollbar,
  75.         .macro-list::-webkit-scrollbar,
  76.         [data-garden-id="dropdowns.menu"]::-webkit-scrollbar {
  77.             width: 8px !important;
  78.         }
  79.  
  80.         .macro-suggestions::-webkit-scrollbar-track,
  81.         .macro-list::-webkit-scrollbar-track,
  82.         [data-garden-id="dropdowns.menu"]::-webkit-scrollbar-track {
  83.             background: #f1f1f1 !important;
  84.         }
  85.  
  86.         .macro-suggestions::-webkit-scrollbar-thumb,
  87.         .macro-list::-webkit-scrollbar-thumb,
  88.         [data-garden-id="dropdowns.menu"]::-webkit-scrollbar-thumb {
  89.             background: #888 !important;
  90.             border-radius: 4px !important;
  91.         }
  92.  
  93.         /* Individual macro items */
  94.         .macro-item,
  95.         .macro-suggestion-item {
  96.             padding: 8px 12px !important;
  97.         }
  98.     `);
  99.  
  100.     // Simpler JavaScript approach focusing on height only
  101.     function expandMacroMenu() {
  102.         const windowHeight = window.innerHeight;
  103.         const menuHeight = Math.floor(windowHeight * 0.75);
  104.  
  105.         // Target all possible macro menu containers
  106.         const selectors = [
  107.             '.macro-suggestions',
  108.             '.macros_dropdown',
  109.             '[data-test-id="macro-suggestions"]',
  110.             '[data-garden-id="dropdowns.menu"]',
  111.             '[aria-label*="macro" i]'
  112.         ];
  113.  
  114.         selectors.forEach(selector => {
  115.             const elements = document.querySelectorAll(selector);
  116.             elements.forEach(element => {
  117.                 if (element && element.textContent.includes('macro')) {
  118.                     // Set max height and ensure scrolling works
  119.                     element.style.maxHeight = `${menuHeight}px`;
  120.                     element.style.overflowY = 'auto';
  121.                     element.style.overflowX = 'hidden';
  122.  
  123.                     // Find any inner list containers and ensure they can scroll too
  124.                     const innerLists = element.querySelectorAll('ul, .macro-list, .macros-list');
  125.                     innerLists.forEach(list => {
  126.                         list.style.maxHeight = `${menuHeight - 40}px`;
  127.                         list.style.overflowY = 'auto';
  128.                         list.style.overflowX = 'hidden';
  129.                     });
  130.                 }
  131.             });
  132.         });
  133.     }
  134.  
  135.     // Run after a short delay to ensure DOM is ready
  136.     setTimeout(expandMacroMenu, 500);
  137.  
  138.     // Re-run on window resize
  139.     window.addEventListener('resize', expandMacroMenu);
  140.  
  141.     // Observer for dynamic content
  142.     const observer = new MutationObserver(() => {
  143.         expandMacroMenu();
  144.     });
  145.  
  146.     observer.observe(document.body, {
  147.         childList: true,
  148.         subtree: true
  149.     });
  150. })();
Advertisement
Add Comment
Please, Sign In to add comment