// ==UserScript==
// @name KeepChatGPT
// @description 让我们在使用ChatGPT过程中更高效、更顺畅,完美解决ChatGPT网络错误,不再频繁地刷新网页,足足省去10个多余的步骤。解决了这几类报错: (1)NetworkError when attempting to fetch resource. (2)Something went wrong. If this issue persists please contact us through our help center at help.openai.com.
// @version 2.9
// @author xcanwin
// @description:en Let's make our use of ChatGPT more efficient and smoother, by perfecting the solution to ChatGPT network errors. This saves us from frequently refreshing the webpage and eliminates over 10 unnecessary steps. The following errors have been resolved: (1) NetworkError when attempting to fetch resource. (2) Something went wrong. If this issue persists please contact us through our help center at help.openai.com.
// @namespace https://github.com/xcanwin/KeepChatGPT/
// @supportURL https://github.com/xcanwin/KeepChatGPT/
// @icon data:image/svg+xml;utf8,
// @license GPL-2.0-only
// @match *://chat.openai.com/chat*
// @grant none
// @run-at document-idie
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
var loadifr = function() {
var u = `/api/${GM_info.script.author.slice(2,3)}uth/s${GM_info.script.name.slice(1, 2)}ssion`;
if(!window.xcanwin){
var ifr = document.createElement('iframe');
ifr.id = "xcanwin";
ifr.style.display = 'none';
ifr.src = u;
ifr.style.width = document.querySelector("nav a").offsetWidth + 'px';
ifr.style.height = '75px';
ifr.onload = function() {
try {
var cf_checkbox = document.querySelector(".ctp-checkbox-label");
if (cf_checkbox) {
cf_checkbox.click();
}
console.log(`KeepChatGPT: ${JSON.parse(ifr.contentDocument.body.innerText)['expires']}`);
ifr.contentWindow.document.body.style.background = '#555';
} catch (e) {
}
};
document.querySelector("nav").appendChild(ifr);
} else{
window.xcanwin.src = u;
}
}
var loadhead = function() {
if(!window.ndivid){
loadifr();
var ndiv = document.createElement("div");
ndiv.id = "ndivid";
ndiv.setAttribute("class", document.querySelector("nav a").className);
ndiv.innerHTML = `KeepChatGPT by xcanwin`;
var nav = document.querySelector('nav');
nav.insertBefore(ndiv, nav.childNodes[0]);
ndiv.insertAdjacentHTML('afterend', `