chatGPT nav menu filter

Filter anchors in nav elements by keyword inputted by user in real time.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         chatGPT nav menu filter
// @name:zh      chatGPT左方列表遮罩
// @namespace    openai
// @version      0.1
// @author       https://github.com/jctneko/
// @description  Filter anchors in nav elements by keyword inputted by user in real time.
// @match        https://chat.openai.com/*
// @run-at       document-idle
// @license      You can modify as long as you credit me
// ==/UserScript==

/*
  Note: The OpenAI interface frequent updates, which can sometimes cause issues with this userscript.
  Please report any issues you encounter, and I will make the necessary corrections.
*/

(() => {
  'use strict';

  const observers = {};

  const createInput = () => {
    const inputNode = document.createElement('input');
    inputNode.type = 'text';
    inputNode.id = 'filterKeyword';
    inputNode.style.cssText = 'position: fixed; top:5px; left: 270px; color: white; background-color:#444654; padding:0 5px;';
    inputNode.placeholder = 'filter_';
    document.body.appendChild(inputNode);
    return inputNode;
  }

  const observeFetch = (urlToObserve, onStart, onFinish) => {
    observers[urlToObserve] = { onStart, onFinish };
  }

  const moveLinks = (filterText) => {
    const navLinks = document.querySelectorAll('nav a');
    navLinks.forEach((link) => {
      link.style.cssText = link.innerText.includes(filterText) ? '' : 'position: absolute; left: -300px;';
    });
    console.log('[gptFilter] items hided.');
  }

  const updateNavLinks = () => {
    const inputNode = document.getElementById('filterKeyword');
    if (inputNode) {
      setTimeout(() => {
        moveLinks(inputNode.value)
      }, 500);
    }
  }

  const handleInputChange = (event) => {
    moveLinks(event.target.value);
  }

  const bindEvents = (inputNode) => {
    let interval = setInterval(() => {
      if (unsafeWindow.next) {
        inputNode.addEventListener('input', handleInputChange);
        unsafeWindow.next.router.events.on('routeChangeComplete', updateNavLinks);
        console.log('[gptFilter] event binded');
        clearInterval(interval);
      }
    }, 1000);

    unsafeWindow.fetch = new Proxy(unsafeWindow.fetch, {
      apply: function(target, thisArg, argumentsList) {
          const [url, options, ...args] = argumentsList;
          const observer = Object.keys(observers).find(key => url.includes(key));

          if (observer) {
              const { onStart, onFinish } = observers[observer];
              onStart && onStart(url, options, ...args);
              return target(url, options, ...args).then(response => {
                  onFinish && onFinish(response);
                  return response;
              });
          }

          return target.apply(thisArg, argumentsList);
      }
    });
  }

  const init = () => {
    const inputNode = createInput();
    bindEvents(inputNode);
  }

  observeFetch(
      "https://chat.openai.com/backend-api/conversations",
      (url, options, ...args) => {
          // console.log("Fetch started: ", url);
      },
      (response) => {
          console.log('[gptFilter] Nav element updated');
          // console.log("Fetch finished: ", response.url);
          updateNavLinks();
      }
  );

  init();
})();