Skip to content

Commit 9346e7a

Browse files
committed
Refactored dismissAlert() of alert() to rely on modal.onanimationend for precise removal timing
1 parent c9d60e8 commit 9346e7a

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

chatgpt.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const chatgpt = {
131131
modalMessage = document.createElement('p');
132132

133133
// Create/append/update modal style (if missing or outdated)
134-
const thisUpdated = 1735475757891 // timestamp of last edit for this file's `modalStyle`
134+
const thisUpdated = 1735768363880 // timestamp of last edit for this file's `modalStyle`
135135
let modalStyle = document.querySelector('#chatgpt-modal-style'); // try to select existing style
136136
if (!modalStyle || parseInt(modalStyle.getAttribute('last-updated'), 10) < thisUpdated) { // if missing or outdated
137137
if (!modalStyle) { // outright missing, create/id/attr/append it first
@@ -305,30 +305,29 @@ const chatgpt = {
305305

306306
// Define alert dismisser
307307
const dismissAlert = () => {
308-
modalContainer.style.backgroundColor = 'transparent';
309-
modal.style.animation = 'alert-zoom-fade-out 0.135s ease-out';
310-
setTimeout(() => { // delay removal for fade-out
308+
modalContainer.style.backgroundColor = 'transparent'
309+
modal.style.animation = 'alert-zoom-fade-out 0.135s ease-out'
310+
modal.onanimationend = () => {
311311

312312
// Remove alert
313-
modalContainer.remove(); // ...from DOM
314-
alertQueue = JSON.parse(localStorage.alertQueue);
315-
alertQueue.shift(); // + memory
316-
localStorage.alertQueue = JSON.stringify(alertQueue); // + storage
317-
document.removeEventListener('keydown', handlers.dismiss.key); // prevent memory leaks
313+
modalContainer.remove() // ...from DOM
314+
alertQueue = JSON.parse(localStorage.alertQueue)
315+
alertQueue.shift() // + memory
316+
localStorage.alertQueue = JSON.stringify(alertQueue) // + storage
317+
document.removeEventListener('keydown', handlers.dismiss.key) // prevent memory leaks
318318

319319
// Check for pending alerts in queue
320320
if (alertQueue.length > 0) {
321-
const nextAlert = document.getElementById(alertQueue[0]);
321+
const nextAlert = document.getElementById(alertQueue[0])
322322
setTimeout(() => {
323-
nextAlert.style.display = '';
324-
setTimeout(() => { nextAlert.classList.add('animated'); }, 100);
325-
}, 500);
323+
nextAlert.style.display = ''
324+
setTimeout(() => nextAlert.classList.add('animated'), 100)
325+
}, 500)
326326
}
327+
}
328+
}
327329

328-
}, 155);
329-
};
330-
331-
return modalContainer.id; // if assignment used
330+
return modalContainer.id // if assignment used
332331
},
333332

334333
async askAndGetReply(query) {

0 commit comments

Comments
 (0)