调用gpt重写

在“发表帖子”页下方添加一个“gpt重写”的按钮,点击按钮,使用openai/chatgpt的接口重写输入框内的文本,防止魔典检测。自测每3千字约需要50秒。

  1. // ==UserScript==
  2. // @name 调用gpt重写
  3. // @description 在“发表帖子”页下方添加一个“gpt重写”的按钮,点击按钮,使用openai/chatgpt的接口重写输入框内的文本,防止魔典检测。自测每3千字约需要50秒。
  4. // @author You
  5. // @namespace http://tampermonkey.net/
  6. // @version 2024.7.27.2
  7. // @license MIT
  8. // @match https://jietiandi.net/forum.php?mod=post&action=newthread*
  9. // @noframes
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. "use strict";
  14.  
  15. // OpenAI API 的密钥
  16. const API_KEY = "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // 请替换为你的 OpenAI API 密钥
  17.  
  18. // 我使用的免费的国内代理
  19. const base_url = "https://api.chatanywhere.tech/v1/chat/completions";
  20.  
  21. // 向 OpenAI API 发送请求
  22. const fetchGpt = async (inputText) => {
  23. const response = await fetch(
  24. base_url, {
  25. method: "POST",
  26. headers: {
  27. "Content-Type": "application/json",
  28. Authorization: `Bearer ${API_KEY}`,
  29. },
  30. body: JSON.stringify({
  31. model: "gpt-4o-mini",
  32. messages: [{
  33. role: "system",
  34. content: "改写下面这几段小说,改变句子结构和语序,替换同义词",
  35. },
  36. {
  37. role: "user",
  38. content: inputText,
  39. },
  40. ],
  41. }), // max_tokens: isTextarea ? 3000 : 300,
  42. }
  43. );
  44.  
  45. if (!response.ok) {
  46. throw new Error(`Error: ${response.statusText}`);
  47. }
  48.  
  49. const data = await response.json();
  50. return data.choices[0]?.message?.content; // ?.trim()?.split("\n") || []
  51. };
  52.  
  53. const main = async () => {
  54. // 获取文本区域中的文本
  55. const textarea = document.querySelector("#e_textarea");
  56. const inputText = textarea.value;
  57. textarea.value = "请等待gpt请求返回结果,自测每3千字约需要50秒";
  58.  
  59. // 获取改写后的文本
  60. let result;
  61. try {
  62. result = await fetchGpt(inputText);
  63. } catch (error) {
  64. console.error("Error fetching data from OpenAI:", error);
  65. return;
  66. }
  67.  
  68. // 将返回的结果填入文本区域
  69. textarea.value = result;
  70. // debugger;
  71. }
  72.  
  73. setTimeout(() => {
  74. let _html = `<button type="button" id="rewrite" class="pn pnc" value="true" name="topicsubmit">
  75. <span>gpt重写</span>
  76. </button>`;
  77. var pnpost = document.querySelector("#postbox > div.mtm.mbm.pnpost");
  78. pnpost.insertAdjacentHTML('beforeend', _html);
  79. document.querySelector("#rewrite").addEventListener("click", main);
  80. }, 3000);
  81. // if (($('postsubmit').name != 'replysubmit' && !($('postsubmit').name == 'editsubmit' && !isfirstpost) && theform.subject.value == "") || !sortid && !special && trim(message) == "") {showError('抱歉,您尚未输入标题或内容');return false;
  82. // $('postform').onsubmit = function() { // type="submit"
  83.  
  84. })();

QingJ © 2025

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