Greasy Fork is available in English.

OpenAI Chat AutoFiller

Automatically fill in chat messages on OpenAI Chat using a predefined text when checkbox is checked and user completes a message.补充说明:panel在窗口右上角, 触发条件为“///”。3.0更新说明:可以存储选择最近 3-4 个之前用户使用的自动填充文本

  1. // ==UserScript==
  2. // @name OpenAI Chat AutoFiller
  3. // @namespace openai-chat-autofiller
  4. // @version 3.1
  5. // @description Automatically fill in chat messages on OpenAI Chat using a predefined text when checkbox is checked and user completes a message.补充说明:panel在窗口右上角, 触发条件为“///”。3.0更新说明:可以存储选择最近 3-4 个之前用户使用的自动填充文本
  6. // @author ChatGPT & philos
  7. // @match https://chat.openai.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. const recentAutoFillTexts = [];
  13.  
  14. const controlPanel = document.createElement('div');
  15. controlPanel.style.position = 'fixed';
  16. controlPanel.style.top = '0';
  17. controlPanel.style.right = '0';
  18. controlPanel.style.padding = '10px';
  19. controlPanel.style.backgroundColor = '#fff';
  20. controlPanel.style.border = '1px solid #ccc';
  21. controlPanel.style.display = 'flex';
  22. controlPanel.style.alignItems = 'center';
  23.  
  24. const checkbox = document.createElement('input');
  25. checkbox.type = 'checkbox';
  26. checkbox.id = 'autofill-checkbox';
  27. controlPanel.appendChild(checkbox);
  28.  
  29. const inputGroup = document.createElement('div');
  30. inputGroup.style.display = 'none';
  31.  
  32. const fillText = document.createElement('input');
  33. fillText.type = 'text';
  34. fillText.id = 'autofill-text';
  35. fillText.value = '每段话的开头请加上“【见字如晤】”回答我';
  36. fillText.style.width = 'calc(100% - 30px)';
  37. inputGroup.appendChild(fillText);
  38.  
  39. const dropdown = document.createElement('select');
  40. dropdown.id = 'autofill-dropdown';
  41. dropdown.style.width = '30px';
  42. dropdown.style.overflow = 'hidden';
  43. inputGroup.appendChild(dropdown);
  44.  
  45. controlPanel.appendChild(inputGroup);
  46. document.body.appendChild(controlPanel);
  47.  
  48. checkbox.addEventListener('change', () => {
  49. if (checkbox.checked) {
  50. inputGroup.style.display = 'flex';
  51. document.querySelector('textarea').addEventListener('input', autofillText);
  52. } else {
  53. inputGroup.style.display = 'none';
  54. document.querySelector('textarea').removeEventListener('input', autofillText);
  55. }
  56. });
  57.  
  58. const autofillText = () => {
  59. const chatInput = document.querySelector('textarea');
  60. const lastChars = chatInput.value.slice(-3);
  61. if (lastChars === '///') {
  62. chatInput.value = chatInput.value.slice(0, -3);
  63. recentAutoFillTexts.unshift(fillText.value);
  64. if (recentAutoFillTexts.length > 4) {
  65. recentAutoFillTexts.pop();
  66. }
  67. updateDropdown();
  68. chatInput.value += fillText.value + '\n';
  69. }
  70. };
  71.  
  72. function updateDropdown() {
  73. dropdown.innerHTML = '';
  74. recentAutoFillTexts.forEach((text, index) => {
  75. const option = document.createElement('option');
  76. option.value = index;
  77. option.text = text;
  78. dropdown.appendChild(option);
  79. });
  80.  
  81. dropdown.addEventListener('change', () => {
  82. const selectedIndex = dropdown.value;
  83. if (selectedIndex !== '') {
  84. fillText.value = recentAutoFillTexts[selectedIndex];
  85. }
  86. });
  87. }
  88. })();