// ==UserScript== // @name Auto Refresh ChatGPT session // @namespace http://github.com/zhaohongxuan // @version 0.3 // @description Auto refresh chatGPT session // @author hank zhao // @match https://chat.openai.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=openai.com // @grant GM_notification // @license AGPL-3.0-or-later // @downloadURL none // ==/UserScript== (function() { 'use strict'; function showNotification() { GM_notification({ title: 'chatGPT session auto refresh Failed', text: 'You can click this notification to reload page mannuly', timeout: 5000, // time in milliseconds the notification should stay visible (optional) onclick: function() { // callback function to execute when the notification is clicked (optional) location.reload() } }); } const intervalId = setInterval(function() { var xhr = new XMLHttpRequest() xhr.open('GET', "https://chat.openai.com/api/auth/session") xhr.onload = function() { if (xhr.status === 200) { console.debug('refresh chatGPT session Success') } else { console.warn('refresh chatGPT session Failed: ', xhr.status) clearInterval(intervalId) showNotification() } } xhr.onerror = function() { console.warn('refresh chatGPT session Error: ', xhr.status) clearInterval(intervalId) showNotification() } xhr.send() }, 60000); })();