Guest User

paste in google ai studio dev tools console to fix lag

a guest
May 25th, 2025
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1.  
  2. (function() {
  3. const targetSelector = 'textarea.textarea';
  4. const debounceDelay = 500; // Adjust as needed
  5. let debounceTimer;
  6. const SYNTHETIC_EVENT_FLAG = 'isAISyntheticFixEvent'; // Custom property name
  7.  
  8. const textarea = document.querySelector(targetSelector);
  9.  
  10. if (!textarea) {
  11. console.error("AI Studio Fix: Could not find the target textarea with selector:", targetSelector);
  12. alert("AI Studio Fix: Textarea not found. The script couldn't be applied.");
  13. return;
  14. }
  15.  
  16. console.log("AI Studio Fix: Attempting to apply input debouncing to:", textarea);
  17. let lastKnownValue = textarea.value;
  18.  
  19. textarea.addEventListener('input', function(event) {
  20. // If this event was dispatched by our script, let it pass through normally
  21. // and don't start another debounce cycle.
  22. if (event[SYNTHETIC_EVENT_FLAG]) {
  23. console.log("AI Studio Fix: Allowing synthetic event to pass through.", event);
  24. return; // Do nothing more for our own synthetic events
  25. }
  26.  
  27. // This is a user-generated event, so stop it and debounce
  28. event.stopImmediatePropagation();
  29. console.log("AI Studio Fix: User input captured and stopped. Current value:", event.target.value);
  30.  
  31. clearTimeout(debounceTimer);
  32. const currentTarget = event.target;
  33.  
  34. debounceTimer = setTimeout(() => {
  35. console.log("AI Studio Fix: Debounce timeout. Current textarea value:", currentTarget.value);
  36.  
  37. // Create synthetic 'input' event and mark it
  38. const inputEvent = new Event('input', {
  39. bubbles: true,
  40. cancelable: true
  41. });
  42. inputEvent[SYNTHETIC_EVENT_FLAG] = true; // Mark as our synthetic event
  43. currentTarget.dispatchEvent(inputEvent);
  44. console.log("AI Studio Fix: Synthetic 'input' event dispatched.");
  45.  
  46. // Dispatch synthetic 'change' event if value actually changed
  47. if (currentTarget.value !== lastKnownValue) {
  48. const changeEvent = new Event('change', {
  49. bubbles: true,
  50. cancelable: true
  51. });
  52. // No need to mark 'change' event unless it could also trigger an 'input' listener
  53. // For safety, we could, but usually 'input' listeners don't listen for 'change' specifically.
  54. // changeEvent[SYNTHETIC_EVENT_FLAG] = true; // Optional, probably not needed
  55. currentTarget.dispatchEvent(changeEvent);
  56. console.log("AI Studio Fix: Synthetic 'change' event dispatched because value changed.");
  57. lastKnownValue = currentTarget.value;
  58. } else {
  59. console.log("AI Studio Fix: Skipped synthetic 'change' event as value hasn't changed since last dispatch.");
  60. }
  61.  
  62. }, debounceDelay);
  63.  
  64. }, true); // true for 'useCapture'
  65.  
  66. console.log(`AI Studio Fix: Input debouncing (delay: ${debounceDelay}ms) with loop prevention is now active.`);
  67. alert(`AI Studio Fix: Input debouncing with loop prevention is active. Try typing.`);
  68. lastKnownValue = textarea.value;
  69. })();
Advertisement
Add Comment
Please, Sign In to add comment