Kagi Assistant Auto-Scroll

Automatically scroll down when new content is added to Kagi Assistant

目前为 2025-03-06 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Kagi Assistant Auto-Scroll
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Automatically scroll down when new content is added to Kagi Assistant
  6. // @author You
  7. // @match *://kagi.com/assistant*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // The main container that holds the chat messages
  16. const targetSelector = '.main-center-box';
  17.  
  18. // Function to scroll to bottom
  19. function scrollToBottom() {
  20. const container = document.querySelector(targetSelector);
  21. if (container) {
  22. container.scrollTop = container.scrollHeight;
  23. }
  24. }
  25.  
  26. // Set up a mutation observer to watch for changes
  27. const observer = new MutationObserver((mutations) => {
  28. let shouldScroll = false;
  29.  
  30. // Check if content was added
  31. mutations.forEach((mutation) => {
  32. if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
  33. shouldScroll = true;
  34. } else if (mutation.type === 'characterData') {
  35. shouldScroll = true;
  36. }
  37. });
  38.  
  39. if (shouldScroll) {
  40. scrollToBottom();
  41. }
  42. });
  43.  
  44. // Function to initialize the observer when the target element exists
  45. function initObserver() {
  46. const target = document.querySelector(targetSelector);
  47. if (target) {
  48. observer.observe(target, {
  49. childList: true,
  50. subtree: true,
  51. characterData: true
  52. });
  53. console.log('Kagi Assistant Auto-Scroll: Observer initialized');
  54.  
  55. // Initial scroll to bottom
  56. scrollToBottom();
  57. } else {
  58. // If target doesn't exist yet, try again shortly
  59. setTimeout(initObserver, 1000);
  60. }
  61. }
  62.  
  63. // Start the initialization process
  64. initObserver();
  65.  
  66. // Also scroll on window resize
  67. window.addEventListener('resize', scrollToBottom);
  68. })();