Bit of random stuff I find useful
Find a file
2025-06-02 15:56:24 +02:00
README.md Initial commit 2025-06-02 15:56:24 +02:00

GFGPT

Chat statistics script

Usage

On recent chats press F12 to open dev tools, switch to the Console tab, paste the script in and run it.

  • Will attempt to scroll to the bottom of the chat list automatically, but can get stuck if it fails to load when scrolling to the bottom.
  • If it fails to load the chats just scroll up a bit and then back down.
    • If the script is still running it will continue.
    • If it's already output the stats just run the script again.
(function autoScrollAndCountMessages() {
  const container = document.getElementById('main');
  if (!container) {
    console.error("Element with ID 'main' not found.");
    return;
  }

  let lastHeight = container.scrollHeight;
  let lastChangeTime = Date.now();

  const scrollInterval = setInterval(() => {
    const currentHeight = container.scrollHeight;
    const now = Date.now();
    const secondsIdle = Math.floor((now - lastChangeTime) / 1000);

    if (currentHeight !== lastHeight) {
      lastHeight = currentHeight;
      lastChangeTime = now;
      container.scrollTop = container.scrollHeight;
    } else if (secondsIdle >= 15) {
      clearInterval(scrollInterval);
      console.log("Scrolling complete. Starting count...");
      countMessages();
    } else if (secondsIdle % 5 === 0) {
      // Wiggle up
      container.scrollTop -= 250;
      container.dispatchEvent(new WheelEvent("wheel", { deltaY: -250, bubbles: true }));
      setTimeout(() => {
        container.scrollTop = container.scrollHeight;
        container.dispatchEvent(new WheelEvent("wheel", { deltaY: 250, bubbles: true }));
      }, 250);
    } else {
      container.scrollTop = container.scrollHeight;
    }
  }, 1000);

  function getBinLabel(count) {
    if (count === 1) return "1 message";
    if (count >= 2 && count <= 20) return "2-20 messages";
    if (count >= 21 && count <= 40) return "21-40 messages";
    if (count >= 41 && count <= 60) return "41-60 messages";
    if (count >= 61 && count <= 80) return "61-80 messages";
    if (count >= 81 && count <= 100) return "81-100 messages";
    if (count >= 101 && count <= 150) return "101-150 messages";
    if (count >= 151 && count <= 180) return "151-180 messages";
    if (count >= 181 && count <= 199) return "181-199 messages";
    return "200+ messages";
  }

  function countMessages() {
    const bins = {};
    const icons = container.querySelectorAll('svg.lucide-message-circle');

    icons.forEach(icon => {
      const span = icon.nextElementSibling;
      if (!span) return;

      const num = parseInt(span.textContent.trim(), 10);
      if (isNaN(num)) return;

      const label = getBinLabel(num);
      bins[label] = (bins[label] || 0) + 1;
    });

    Object.keys(bins)
      .sort((a, b) => {
        const extractMin = label => {
          if (label === "1 message") return 1;
          if (label === "200+ messages") return 2000;
          return parseInt(label.match(/\d+/)[0], 10);
        };
        return extractMin(a) - extractMin(b);
      })
      .forEach(label => {
        console.log(`${label}: ${bins[label]}`);
      });
  }
})();