Prechádzať zdrojové kódy

Fixes generation restart not working for some users when 'Ctrl+Enter' is pressed

kaalibro 1 rok pred
rodič
commit
94e9669566
1 zmenil súbory, kde vykonal 12 pridanie a 3 odobranie
  1. 12 3
      script.js

+ 12 - 3
script.js

@@ -133,9 +133,18 @@ document.addEventListener('keydown', function(e) {
     if (isEnter && isModifierKey) {
         if (interruptButton.style.display === 'block') {
             interruptButton.click();
-            setTimeout(function() {
-                generateButton.click();
-            }, 500);
+            const callback = (mutationList) => {
+                for (const mutation of mutationList) {
+                    if (mutation.type === 'attributes' && mutation.attributeName === 'style') {
+                        if (interruptButton.style.display === 'none') {
+                            generateButton.click();
+                            observer.disconnect();
+                        }
+                    }
+                }
+            };
+            const observer = new MutationObserver(callback);
+            observer.observe(interruptButton, {attributes: true});
         } else {
             generateButton.click();
         }