ChatGPT Monitor

Monitor ChatGPT's response on chat.openai.com/chat and add "continue" if no period is detected

当前为 2023-01-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name ChatGPT Monitor
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Monitor ChatGPT's response on chat.openai.com/chat and add "continue" if no period is detected
  6. // @author Your Name
  7. // @match https://chat.openai.com/chat
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. var targetNode = document.getElementById("__next");
  16. var config = { childList: true };
  17. var callback = function(mutationsList) {
  18. for(var mutation of mutationsList) {
  19. if (mutation.addedNodes.length > 0) {
  20. var lastNode = mutation.addedNodes[mutation.addedNodes.length - 1];
  21. if (lastNode.classList.contains("text-md") && lastNode.classList.contains("text-white") && lastNode.classList.contains("bg-blue-500") && lastNode.classList.contains("p-2")) {
  22. var text = lastNode.innerText;
  23. if (text.endsWith(".") || text.endsWith("。")) {
  24. console.log("Period detected, no need to add 'continue'");
  25. } else {
  26. console.log("No period detected, adding 'continue'");
  27. var inputNode = document.querySelector("#__next > div.overflow-hidden.w-full.h-full.relative > div.flex.h-full.flex-1.flex-col.md\\:pl-[260px] > main > div.flex-1.overflow-hidden > div > div > div > div:nth-child(4) > div > div.relative.flex.w-[calc(100%-50px)].flex-col.gap-1.md\\:gap-3.lg\\:w-[calc(100%-115px)] > div.flex.flex-grow.flex-col.gap-3 > div > div");
  28. inputNode.value = "continue";
  29. inputNode.dispatchEvent(new Event("input", { bubbles: true }));
  30. inputNode.form.dispatchEvent(new Event("submit", { bubbles: true }));
  31. }
  32. }
  33. }
  34. }
  35. };
  36. var observer = new MutationObserver(callback);
  37. observer.observe(targetNode, config);
  38. })();