Skip to content

Commit

Permalink
Moved sporadic convo reset prevention to main routine for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlui committed Nov 23, 2024
1 parent 571e110 commit 2d34a02
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions chatgpt-auto-refresh/greasemonkey/chatgpt-auto-refresh.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
// @description:zu *NGOKUPHEPHA* susa ukusetha kabusha ingxoxo yemizuzu eyi-10 + amaphutha enethiwekhi ahlala njalo + Ukuhlolwa kwe-Cloudflare ku-ChatGPT.
// @author Adam Lui
// @namespace https://github.com/adamlui
// @version 2024.11.22.10
// @version 2024.11.22.11
// @license MIT
// @match *://chatgpt.com/*
// @match *://chat.openai.com/*
Expand Down Expand Up @@ -374,22 +374,6 @@
} ; settings.load('arDisabled', 'notifDisabled', 'refreshInterval', 'toggleHidden')
if (!config.refreshInterval) settings.save('refreshInterval', 30) // init refresh interval to 30 secs if unset

// Prevent sporadic convo RESETS
const ogAEL = EventTarget.prototype.addEventListener
EventTarget.prototype.addEventListener = function(type, listener, optionsOrUseCapture) {
let calledByOpenAI = false
if (type == 'focus' && this == unsafeWindow || type == 'visibilitychange') {
const callStack = new Error().stack + '\n',
aelCaller = /-extension:\/\/.*\n(.+)/.exec(callStack)?.[1]
calledByOpenAI = !aelCaller?.includes('-extension://')
if (calledByOpenAI && type == 'visibilitychange') {
ogAEL.call(this, type, function(event) {
if (document.visibilityState != 'visible') listener.call(this, event)
}, optionsOrUseCapture)
}}
if (!calledByOpenAI) ogAEL.apply(this, arguments)
}

// Define MENU functions

const menu = {
Expand Down Expand Up @@ -802,6 +786,22 @@

sidebarToggle.insert()

// Prevent sporadic convo RESETS
const ogAEL = EventTarget.prototype.addEventListener
EventTarget.prototype.addEventListener = function(type, listener, optionsOrUseCapture) {
let calledByOpenAI = false
if (type == 'focus' && this == unsafeWindow || type == 'visibilitychange') {
const callStack = new Error().stack + '\n',
aelCaller = /-extension:\/\/.*\n(.+)/.exec(callStack)?.[1]
calledByOpenAI = !aelCaller?.includes('-extension://')
if (calledByOpenAI && type == 'visibilitychange') {
ogAEL.call(this, type, function(event) {
if (document.visibilityState != 'visible') listener.call(this, event)
}, optionsOrUseCapture)
}}
if (!calledByOpenAI) ogAEL.apply(this, arguments)
}

// Activate AUTO-REFRESH on first visit if enabled
if (!config.arDisabled) {
chatgpt.autoRefresh.activate(config.refreshInterval)
Expand Down

0 comments on commit 2d34a02

Please sign in to comment.