BetterChatGPT

detects if chatgpt needs refresh, access to chatgpt while down, favicon based on status

目前为 2023-02-07 提交的版本。查看 最新版本

// ==UserScript==
// @name           BetterChatGPT
// @namespace      https://github.com/optionsx
// @version        0.1
// @author         optionsx
// @description    detects if chatgpt needs refresh, access to chatgpt while down, favicon based on status
// @grant          GM.xmlHttpRequest
// @match          https://chat.openai.com/*
// @icon           https://www.google.com/s2/favicons?sz=64&domain=openai.com
// @license MIT
// ==/UserScript==
// check out TheTerrasque extension: https://github.com/TheTerrasque/chatgpt-firefox-extension

// access while down functionality
const timedLoop = setInterval(() => {
  if (document.getElementsByClassName("text-3xl font-medium").length > 0)
    location.reload();
  else clearInterval(timedLoop);
}, 500);

// reload if needed functionality
const triggerPoint = document.querySelector("textarea"); // "button.absolute" for submit button
triggerPoint.addEventListener("click", () => {
  try {
    GM.xmlHttpRequest({
      method: "GET",
      url: "https://chat.openai.com/api/auth/session",
      onload: function (response) {
        console.log(response.status);
        if (response.status === 403) {
          changeFavicon("yellow");
          location.reload();
        }
        if (response.status === 429) {
          changeFavicon("red");
          const popup = prompt(
            "You have been rate limited. wanna logout?, y/n"
          );
          popup.toLowerCase().startsWith("y") ? (localStorage.removeItem("__Secure-next-auth.session-token"),location.reload()) : null;
        }
      },
    });
  } catch (e) {
    console.log(e);
  }
});
const status = {
  yellow:
    "https://github.com/TheTerrasque/chatgpt-firefox-extension/blob/master/resources/favicon-32x32-yellow.png?raw=true",
  green:
    "https://github.com/TheTerrasque/chatgpt-firefox-extension/blob/master/resources/favicon-32x32.png?raw=true",
  red: "https://github.com/TheTerrasque/chatgpt-firefox-extension/blob/master/resources/favicon-32x32-red.png?raw=true",
  blue: "https://github.com/TheTerrasque/chatgpt-firefox-extension/blob/master/resources/favicon-32x32-blue.png?raw=true",
};

// change favicon color functionality
const changeFavicon = (color) => {
  const icons = document.querySelectorAll("head link[rel='icon']");
  for (let i = 0; i < icons.length; i++) {
    icons[i].href = status[color];
  }
};

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址