ChatGPT Custom Button

Add a custom button to the ChatGPT site

当前为 2023-04-03 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name ChatGPT Custom Button
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Add a custom button to the ChatGPT site
  6. // @author Stucci
  7. // @license MIT
  8. // @match https://chat.openai.com/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function autoResize(textArea) {
  16. textArea.style.height = 'auto';
  17. textArea.style.height = textArea.scrollHeight + 'px';
  18. }
  19.  
  20. function createButton(text, handler) {
  21. const button = document.createElement('button');
  22. button.className = 'custombtn btn relative btn-neutral border-0 md:border';
  23. button.innerHTML = text;
  24. button.onclick = handler;
  25. return button;
  26. }
  27.  
  28. function addButtonIfNotExists() {
  29. if (document.querySelector('.custombtn')) {
  30. return;
  31. }
  32.  
  33. const textBox = document.querySelector('form');
  34. if (!textBox) {
  35. return;
  36. }
  37.  
  38. const buttonContainer = document.createElement('div');
  39. buttonContainer.style.display = 'flex';
  40. buttonContainer.style.justifyContent = 'center';
  41. buttonContainer.style.marginBottom = '10px';
  42.  
  43. buttonContainer.append(
  44. createButton('Continue⏎', function() {
  45. const textArea = document.querySelector('textarea');
  46. textArea.value = 'Continue';
  47. textArea.focus();
  48.  
  49. const keyDownEvent = new KeyboardEvent('keydown', {
  50. key: 'Enter',
  51. keyCode: 13,
  52. which: 13
  53. });
  54. textArea.dispatchEvent(keyDownEvent);
  55. const keyUpEvent = new KeyboardEvent('keyup', {
  56. key: 'Enter',
  57. keyCode: 13,
  58. which: 13
  59. });
  60. textArea.dispatchEvent(keyUpEvent);
  61. })
  62. );
  63.  
  64. textBox.parentNode.insertBefore(buttonContainer, textBox);
  65. }
  66.  
  67. const targetNode = document.body;
  68. const config = { childList: true, subtree: true };
  69. const observer = new MutationObserver(addButtonIfNotExists);
  70.  
  71. observer.observe(targetNode, config);
  72. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址