ChatGPT Keep-Alive

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

  1. // ==UserScript==
  2. // @name ChatGPT Keep-Alive
  3. // @description 每隔30秒自动发送一次请求到ChatGPT,防止出现错误提示: "Something went wrong. If this issue persists, please contact us through our helper center at help.openai.com."
  4. // @version 0.2
  5. // @author eiyen
  6. // @namespace https://github.com/eiyen/ChatGPT-Keep-Alive
  7. // @description:zh-CN 每隔30秒自动发送一次请求到ChatGPT,防止出现错误提示: "Something went wrong. If this issue persists, please contact us through our helper center at help.openai.com."
  8. // @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."
  9. // @match https://chat.openai.com/*
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (() => {
  14. "use strict";
  15.  
  16. // Helper function to check if user is on the chat page
  17. const isUserOnChatPage = () => {
  18. const navSelector = "nav>a.flex";
  19. const buttonSelector = "button.justify-center";
  20.  
  21. return (
  22. document.querySelector(navSelector) ||
  23. document.querySelector(buttonSelector)
  24. );
  25. };
  26.  
  27. // Function to ping ChatGPT API every 30 seconds
  28. const pingChatGPT = () => {
  29. const apiEndpoint = `/api/auth/session`;
  30.  
  31. // Request session data from the API
  32. fetch(apiEndpoint)
  33. .then((response) => {
  34. if (!response.ok) {
  35. const currentTime = new Date().toLocaleString();
  36. throw new Error(`Network response was not ok. Error occurred at: ${currentTime}`);
  37. }
  38. })
  39. .catch((error) => {
  40. console.log(`Error: ${error}`);
  41. });
  42. };
  43.  
  44. // Main function to initialize the script
  45. const main = () => {
  46. setInterval(() => {
  47. if (isUserOnChatPage()) {
  48. pingChatGPT();
  49. }
  50. }, 1000 * 30);
  51. };
  52.  
  53. main();
  54. })();