Advertisement
paralax034

Fix the ai google console scroll (auto)

Mar 8th, 2025
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.35 KB | Source Code | 0 0
  1. // Use extension for auto execute javascript runner
  2.  
  3. /**
  4.  * @type {HTMLElement}
  5.  */
  6. let blockChat;
  7.  
  8. window.addEventListener('load', () => {
  9.     console.log("Window loaded");
  10.  
  11.     // Смотри есть ли /prompts/ в url
  12.     const prompt = window.location.href.match(/\/prompts\/\d+/);
  13.     if (prompt == undefined) {
  14.         console.log("You are not in chat");
  15.         throw new Error("You are not in chat");
  16.     }
  17.  
  18.     console.log("You are in chat");
  19.  
  20.     const interval = 200;
  21.  
  22.     const intervalId = setInterval(() => {
  23.         blockChat = document.querySelector("ms-chat-session");
  24.         console.log("blockChat", blockChat != undefined, blockChat);
  25.         if (blockChat != undefined) {
  26.             console.log("Call")
  27.             paralax();
  28.             clearInterval(intervalId);
  29.         }
  30.     }, interval);
  31. })
  32.  
  33. function paralax() {
  34.     console.log("main", blockChat.cloneNode(true));
  35.  
  36.     // Just paste into browser console
  37.     let scrollThreshold = 5;
  38.  
  39.     function updateForEach(xTurns) {
  40.         xTurns.forEach(turn => {
  41.             contentBlock.removeChild(turn);
  42.             lastTurn = turn;
  43.         });
  44.     }
  45.  
  46.     const scrollBlock = blockChat.querySelector("ms-autoscroll-container");
  47.     const contentBlock = scrollBlock.querySelector("div");
  48.  
  49.     let turns = Array.from(contentBlock.querySelectorAll("ms-chat-turn"));
  50.     let lastTurn;
  51.  
  52.     updateForEach(turns);
  53.  
  54.     let observer = new MutationObserver((mutations) => {
  55.         mutations.forEach((mutation) => {
  56.             mutation.addedNodes.forEach((node) => {
  57.                 if (node.nodeType == 1 && node.tagName == "MS-CHAT-TURN" && node != lastTurn && turns.find(nide) == undefined) {
  58.                     turns.push(node);
  59.                     contentBlock.appendChild(node);
  60.                     updateForEach(turns);
  61.                 }
  62.             })
  63.         })
  64.     })
  65.  
  66.     observer.observe(contentBlock, { childList: true });
  67.  
  68.     scrollBlock.onscroll = () => {
  69.         if (scrollBlock.scrollTop < scrollThreshold) {
  70.             let newTurn = turns.pop();
  71.             contentBlock.insertBefore(newTurn, contentBlock.firstChild);
  72.             scrollBlock.scrollTop = newTurn.offsetTop + newTurn.offsetHeight - scrollThreshold;
  73.             lastTurn = newTurn;
  74.         } else if (lastTurn != undefined && scrollBlock.scrollTop > lastTurn.offsetTop + lastTurn.offsetHeight + scrollThreshold) {
  75.             contentBlock.removeChild(lastTurn);
  76.             turns.push(lastTurn);
  77.             lastTurn = undefined;
  78.  
  79.             requestAnimationFrame(() => {
  80.                 scrollBlock.scrollTop = scrollThreshold * 2;
  81.                 lastTurn = contentBlock.querySelector("ms-chat-turn:first-child");
  82.             })
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement