// ==UserScript== // @name KeepChatGPT // @description 完美解决ChatGPT网络错误, 不再频繁地刷新网页, 非常顺畅. 解决了这几类报错: (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.3 // @author xcanwin // @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 { 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`; ndiv.onclick = kcg; var nav = document.querySelector('nav'); nav.insertBefore(ndiv, nav.childNodes[0]); var newstyle = document.createElement('style'); newstyle.innerHTML = ` #ndivid { color: #555; background: linear-gradient(to top right, #F0B27A, #FDE184, #F0B27A); animation: gradient 6s ease-in-out infinite; position: relative; overflow: hidden; font-weight: bold; } @keyframes gradient { 0%{background-color:#F0B27A;} 50%{background-color:#FDE184;} 100%{background-color:#F0B27A;} } #ndivid::before { content: ''; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%; background: linear-gradient( to bottom right, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0) ); transform: rotate(-45deg); animation: shine 2.8s linear infinite; } @keyframes shine { from { transform: translateX(-50%) translateY(-50%) rotate(-45deg); } to { transform: translateX(150%) translateY(150%) rotate(-45deg); } } `; document.body.appendChild(newstyle); } } var kcg = function() { window.xcanwin ? xcanwin.style.display == "none" ? xcanwin.style.display = "" : xcanwin.style.display = "none" : 0; } setInterval(function() { if (document.querySelector("nav a")) { loadhead(); } }, 300); setInterval(function() { if (document.querySelector("nav a")) { loadifr(); } }, 1000 * 30); })();