ChatGPT Keep-Alive

每隔30秒自动发送一次请求到ChatGPT,防止出现错误提示: "Something went wrong. If this issue persists, please contact us through our helper center at help.openai.com."

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

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

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name                ChatGPT Keep-Alive
// @description         每隔30秒自动发送一次请求到ChatGPT,防止出现错误提示: "Something went wrong. If this issue persists, please contact us through our helper center at help.openai.com."
// @version             0.2
// @author              eiyen
// @namespace           https://github.com/eiyen/ChatGPT-Keep-Alive
// @description:zh-CN   每隔30秒自动发送一次请求到ChatGPT,防止出现错误提示: "Something went wrong. If this issue persists, please contact us through our helper center at help.openai.com."
// @description:en      Automatically ping ChatGPT every 30 seconds to prevent the error message: "Something went wrong. If this issue persists, please contact us through our helper center at help.openai.com."
// @match               https://chat.openai.com/*
// @license             MIT
// ==/UserScript==

(() => {
  "use strict";

  // Helper function to check if user is on the chat page
  const isUserOnChatPage = () => {
    const navSelector = "nav>a.flex";
    const buttonSelector = "button.justify-center";

    return (
      document.querySelector(navSelector) ||
      document.querySelector(buttonSelector)
    );
  };

  // Function to ping ChatGPT API every 30 seconds
  const pingChatGPT = () => {
    const apiEndpoint = `/api/auth/session`;

    // Request session data from the API
    fetch(apiEndpoint)
      .then((response) => {
        if (!response.ok) {
          const currentTime = new Date().toLocaleString();
          throw new Error(`Network response was not ok. Error occurred at: ${currentTime}`);
        }
      })
      .catch((error) => {
        console.log(`Error: ${error}`);
      });
  };

  // Main function to initialize the script
  const main = () => {
    setInterval(() => {
      if (isUserOnChatPage()) {
        pingChatGPT();
      }
    }, 1000 * 30);
  };

  main();
})();