SDWU - Custom hotkeys for Lobe Theme

Press 'x' or 'e' to toggle visibility of the "Extra Networks" panel and 'q' to toggle the "Quick Settings" panel in Stable Diffusion WebUI with Lobe Theme

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name SDWU - Custom hotkeys for Lobe Theme
// @namespace http://monnef.eu/
// @version 0.1
// @description Press 'x' or 'e' to toggle visibility of the "Extra Networks" panel and 'q' to toggle the "Quick Settings" panel in Stable Diffusion WebUI with Lobe Theme
// @match http://127.0.0.1:7860/*
// @author monnef
// @grant none
// @license GPLv3
// ==/UserScript==

const EXTRA_NETWORKS_SELECTOR = '.lucide.lucide-chevron-left';
const QUICK_SETTINGS_SELECTOR = '.lucide.lucide-chevron-right';

const clickOnElement = selector => {
  const element = document.querySelector(selector);
  if (element) {
    element.dispatchEvent(new MouseEvent('click', {
      bubbles: true,
      cancelable: true,
      view: window
    }));
  } else {
    console.log(`Element not found for selector: ${selector}`);
  }
};

const handleExtraNetworks = () => clickOnElement(EXTRA_NETWORKS_SELECTOR);
const handleQuickSettings = () => clickOnElement(QUICK_SETTINGS_SELECTOR);

const keyHandlers = {
  'x': handleExtraNetworks,
  'e': handleExtraNetworks,
  'q': handleQuickSettings
};

document.addEventListener('keydown', event => {
  const activeElement = document.activeElement;
  const isFocusedElementInputOrTextarea = activeElement && ['INPUT', 'TEXTAREA'].includes(activeElement.tagName);

  if (isFocusedElementInputOrTextarea) return;

  keyHandlers[event.key]?.();
});