GraphQL Playground Timed Autocomplete Hide

Hides GraphQL Playground autocomplete suggestions after a short delay

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         GraphQL Playground Timed Autocomplete Hide
// @description  Hides GraphQL Playground autocomplete suggestions after a short delay
// @namespace    @lfernandezcall
// @version      2025-05-31
// @author       Alberto Fernandez
// @match        */graphql
// @icon         https://graphql.org/favicon.png
// @license      MIT
// @grant        none
// ==/UserScript==

let hintTimeout; // Global variable to store the timeout ID

const observer = new MutationObserver((mutations) => {
  mutations.forEach((mutation) => {
    if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
      mutation.addedNodes.forEach(node => {
        if (node.nodeType === Node.ELEMENT_NODE) {
          if (node.classList.contains("CodeMirror-hints") || node.classList.contains("CodeMirror-hint-information")) {
            handleHintBoxVisibility();
          }
        }
      });
    } else if (mutation.type === 'attributes' && mutation.attributeName === 'style') {
      if (mutation.target.classList.contains("CodeMirror-hints") || mutation.target.classList.contains("CodeMirror-hint-information")) {
        if (window.getComputedStyle(mutation.target).display !== 'none') {
          handleHintBoxVisibility();
        }
      }
    }
  });
});

// Function to manage the hint box visibility
function handleHintBoxVisibility() {
  if (hintTimeout) {
    clearTimeout(hintTimeout);
  }

  // Set a new timeout to hide/remove the hints after a delay
  // You can adjust the delay (in milliseconds) here
  const delay = 1500; // 1.5 seconds

  hintTimeout = setTimeout(() => {
    const hintWrappers = document.querySelectorAll(".CodeMirror-hints-wrapper, .CodeMirror-hints, .CodeMirror-hint-information");
    hintWrappers.forEach(element => {
      if (element.style.display !== 'none') {
        element.style.display = 'none';
      }
    });
    hintTimeout = null; // Reset timeout ID after execution
  }, delay);
}

// Start observing the body for child list changes and attribute changes on subtree elements
observer.observe(document.body, {
  subtree: true,
  childList: true,
  attributes: true,
  attributeFilter: ['style'] // Only observe 'style' attribute changes for performance
});

console.log("MutationObserver for GraphQL Playground initialized (timed hide).");