ChatGPT Conversation Seeker Newer Version

Search past conversations with auto-load using up to three scrollbars and keyboard enter support

当前为 2024-08-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name ChatGPT Conversation Seeker Newer Version
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.6
  5. // @description Search past conversations with auto-load using up to three scrollbars and keyboard enter support
  6. // @author Emree.el on Instagram :)
  7. // @match https://chatgpt.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Create a container for the search bar and button
  16. const searchBarContainer = document.createElement('div');
  17. searchBarContainer.style.position = 'fixed';
  18. searchBarContainer.style.top = '0';
  19. searchBarContainer.style.left = 'calc(50% + 280px)';
  20. searchBarContainer.style.transform = 'translateX(-50%)';
  21. searchBarContainer.style.zIndex = '9999';
  22. searchBarContainer.style.background = '#171717';
  23. searchBarContainer.style.padding = '5px';
  24. searchBarContainer.style.boxShadow = '0 2px 4px rgba(0,0,0,0.1)';
  25. searchBarContainer.style.display = 'flex';
  26. searchBarContainer.style.alignItems = 'center';
  27.  
  28. // Create the search input
  29. const searchInput = document.createElement('input');
  30. searchInput.type = 'text';
  31. searchInput.placeholder = 'Enter text to search';
  32. searchInput.style.marginRight = '5px';
  33. searchInput.style.padding = '5px';
  34. searchInput.style.fontSize = '14px';
  35. searchInput.style.backgroundColor = 'black';
  36.  
  37. // Create the search button
  38. const searchButton = document.createElement('button');
  39. searchButton.textContent = 'Enter';
  40. searchButton.style.padding = '5px';
  41. searchButton.style.fontSize = '14px';
  42.  
  43. // Append the input and button to the container
  44. searchBarContainer.appendChild(searchInput);
  45. searchBarContainer.appendChild(searchButton);
  46.  
  47. // Append the container to the body
  48. document.body.appendChild(searchBarContainer);
  49.  
  50. // Function to continuously scroll down and up an element
  51. function scrollElement(element, resolve) {
  52. let lastScrollTop = element.scrollTop;
  53. const scrollDownInterval = setInterval(() => {
  54. element.scrollTop += 100;
  55. if (element.scrollTop === lastScrollTop) {
  56. clearInterval(scrollDownInterval);
  57. scrollUp(element, resolve);
  58. }
  59. lastScrollTop = element.scrollTop;
  60. }, 50); // Adjust speed if necessary
  61. }
  62.  
  63. // Function to scroll up an element
  64. function scrollUp(element, callback) {
  65. const scrollUpInterval = setInterval(() => {
  66. element.scrollTop -= 100;
  67. if (element.scrollTop === 0) {
  68. clearInterval(scrollUpInterval);
  69. callback();
  70. }
  71. }, 50); // Adjust speed if necessary
  72. }
  73.  
  74. // Function to perform search
  75. function performSearch() {
  76. const searchText = searchInput.value.trim().toLowerCase();
  77. const elements = document.querySelectorAll('a.flex.items-center.gap-2.p-2');
  78.  
  79. elements.forEach(element => {
  80. const text = element.textContent.trim().toLowerCase();
  81. if (text.includes(searchText)) {
  82. element.style.display = 'block';
  83. } else {
  84. element.style.display = 'none';
  85. }
  86. });
  87. }
  88.  
  89. // Function to handle scrolling for up to three scrollable elements
  90. function handleScrollForElements(elements) {
  91. if (elements.length === 0) {
  92. performSearch();
  93. return;
  94. }
  95.  
  96. let index = 0;
  97. function scrollNext() {
  98. if (index < elements.length && index < 3) {
  99. scrollElement(elements[index], () => {
  100. index++;
  101. scrollNext();
  102. });
  103. } else {
  104. performSearch();
  105. }
  106. }
  107.  
  108. scrollNext();
  109. }
  110.  
  111. // Add event listener to the button
  112. searchButton.addEventListener('click', function() {
  113. const scrollableElements = Array.from(document.querySelectorAll('*')).filter(el => el.scrollHeight > el.clientHeight);
  114. handleScrollForElements(scrollableElements);
  115. });
  116.  
  117. // Add event listener for Enter key press in the search input
  118. searchInput.addEventListener('keydown', function(e) {
  119. if (e.key === 'Enter') {
  120. const scrollableElements = Array.from(document.querySelectorAll('*')).filter(el => el.scrollHeight > el.clientHeight);
  121. handleScrollForElements(scrollableElements);
  122. }
  123. });
  124.  
  125. // Automatically trigger loading on page load
  126. window.addEventListener('load', function() {
  127. const scrollableElements = Array.from(document.querySelectorAll('*')).filter(el => el.scrollHeight > el.clientHeight);
  128. handleScrollForElements(scrollableElements);
  129. });
  130.  
  131. })();