Highlights Active ChatGPT Conversation Title

Underlines the currently active conversation title and scrolls it into view

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Highlights Active ChatGPT Conversation Title
// @namespace    violentmonkey.github.io
// @version      1.1
// @description  Underlines the currently active conversation title and scrolls it into view
// @author       Bui Quoc Dung
// @match        https://chatgpt.com/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function () {
  'use strict';

  let hasScrolledToActive = false;  

  function updateUnderline() {
    const currentPath = location.pathname;
    const links = document.querySelectorAll('a.group.__menu-item');

    links.forEach(link => {
      const href = link.getAttribute('href');
      const span = link.querySelector('span');

      if (span) {
        if (href === currentPath) {
          span.style.textDecoration = 'underline';
          span.style.fontWeight = 'bold';


          if (!hasScrolledToActive) {
            hasScrolledToActive = true;
            setTimeout(() => {
              link.scrollIntoView({ behavior: 'smooth', block: 'center' });
            }, 100);
          }
        } else {
          span.style.textDecoration = '';
          span.style.fontWeight = '';
        }
      }
    });
  }

  window.addEventListener('popstate', () => {
    hasScrolledToActive = false;
    updateUnderline();
  });

  window.addEventListener('pushState', () => {
    hasScrolledToActive = false;
    updateUnderline();
  });

  window.addEventListener('replaceState', () => {
    hasScrolledToActive = false;
    updateUnderline();
  });

  updateUnderline();

  const observer = new MutationObserver(updateUnderline);
  observer.observe(document.body, { childList: true, subtree: true });

  const origPushState = history.pushState;
  history.pushState = function () {
    origPushState.apply(this, arguments);
    hasScrolledToActive = false;
    updateUnderline();
  };

  const origReplaceState = history.replaceState;
  history.replaceState = function () {
    origReplaceState.apply(this, arguments);
    hasScrolledToActive = false;
    updateUnderline();
  };
})();