Greasy Fork is available in English.

ChatGPT Code Completer

ChatGPT limits the amount of code output. So this script adds a continue button on ChatGPT webpage to continue getting the output code stream. Make sure a previous response having a code block is present to make it work.

  1. // ==UserScript==
  2. // @name ChatGPT Code Completer
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description ChatGPT limits the amount of code output. So this script adds a continue button on ChatGPT webpage to continue getting the output code stream. Make sure a previous response having a code block is present to make it work.
  6. // @author Geetesh.Gupta
  7. // @match https://chat.openai.com/chat
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=openai.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. function insertButton(elem) {
  15. let formElem = document.getElementsByTagName('form')[0];
  16. let btnsParent = formElem.getElementsByTagName('button')[0].parentElement;
  17. btnsParent.insertBefore(elem, btnsParent.firstElementChild);
  18. }
  19.  
  20. function createBtn() {
  21. let continueBtn = document.createElement('button');
  22. continueBtn.textContent = "Continue";
  23. continueBtn.setAttribute('style', 'display: flex; cursor: pointer;');
  24. continueBtn.className = 'btn flex gap-2 justify-center btn-neutral';
  25. return continueBtn;
  26. }
  27.  
  28. function getPrevNodeValues() {
  29. let codeBlocks = document.querySelectorAll('code.hljs');
  30. let lastCodeBlock = codeBlocks[codeBlocks.length - 1];
  31. let children = lastCodeBlock.innerText.split("\n")
  32. let res = "";
  33. for (let i=children.length-1; i>=0 && res.trim().length < 20; i--) {
  34. res += children[i];
  35. }
  36. return res;
  37. }
  38.  
  39. function updateTextArea(value) {
  40. document.getElementsByTagName('textarea')[0].value = value
  41. }
  42.  
  43. function main() {
  44.  
  45. const btn = createBtn();
  46. insertButton(btn);
  47. btn.onclick = () => {
  48. try {
  49. updateTextArea("what is the remaining part of the previous code? It ended at " + getPrevNodeValues());
  50. } catch (error) {
  51. console.log("Some error occured. Possible reasons:- Previous ChatGPT response does not include any code block or Website structure changed. The actual error: ", error)
  52. }
  53. }
  54.  
  55. }
  56.  
  57. main();
  58.  
  59. })();
  60.