TheHickman commited on
Commit
27cfa2a
Β·
verified Β·
1 Parent(s): 87b8106

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -278,19 +278,26 @@ HEAD_HTML = """
278
  }
279
 
280
  /* ── Poll the hidden output textarea for results ────────────────── */
281
- function pollOutput() {
282
- if (isExplaining) {
283
- const outTA = document.querySelector('#hidden-output textarea');
284
- if (outTA) {
285
- const val = outTA.value.trim();
286
- if (val && val !== lastSeenOutput) {
 
 
 
 
 
 
 
287
  lastSeenOutput = val;
288
  applyExplanation(val);
289
  }
290
- }
 
 
291
  }
292
- setTimeout(pollOutput, 250);
293
- }
294
 
295
  function applyExplanation(text) {
296
  if (placeholder) {
@@ -323,7 +330,7 @@ HEAD_HTML = """
323
  /* ── Boot ───────────────────────────────────────────────────────── */
324
  function boot() {
325
  buildFAB();
326
- pollOutput();
327
  }
328
 
329
  if (document.readyState === 'loading') {
 
278
  }
279
 
280
  /* ── Poll the hidden output textarea for results ────────────────── */
281
+ function watchOutput() {
282
+ const target = document.querySelector('#hidden-output');
283
+ if (!target) {
284
+ setTimeout(watchOutput, 500);
285
+ return;
286
+ }
287
+
288
+ const observer = new MutationObserver(() => {
289
+ const ta = document.querySelector('#hidden-output textarea');
290
+ if (!ta) return;
291
+
292
+ const val = ta.value.trim();
293
+ if (isExplaining && val && val !== lastSeenOutput) {
294
  lastSeenOutput = val;
295
  applyExplanation(val);
296
  }
297
+ });
298
+
299
+ observer.observe(target, { subtree: true, childList: true });
300
  }
 
 
301
 
302
  function applyExplanation(text) {
303
  if (placeholder) {
 
330
  /* ── Boot ───────────────────────────────────────────────────────── */
331
  function boot() {
332
  buildFAB();
333
+ watchOutput();
334
  }
335
 
336
  if (document.readyState === 'loading') {