chatGPT tools Plus ++ (cookie版)

chatGPT Google&必应&百度&startpage 侧边栏自定义搜索(免翻墙,cookie登录版)

  1. // ==UserScript==
  2. // @name chatGPT tools Plus ++ (cookie版)
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.4.5
  5. // @description chatGPT Google&必应&百度&startpage 侧边栏自定义搜索(免翻墙,cookie登录版)
  6. // @author Onion
  7. // @match https://cn.bing.com/*
  8. // @match https://www.bing.com/*
  9. // @match https://chat.openai.com/chat
  10. // @match https://www.google.com/*
  11. // @match https://www.google.com.hk/*
  12. // @match https://www.startpage.com/*
  13. // @match https://www.baidu.com/s?wd=*
  14. // @include /^https:\/\/www\.baidu\.com\/s\?wd.*$/
  15. // @icon https://www.google.com/s2/favicons?sz=64&domain=openai.com
  16. // @grant GM_xmlhttpRequest
  17. // @grant GM_addStyle
  18. // @require https://cdn.staticfile.org/jquery/3.4.0/jquery.min.js
  19. // @require https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js
  20. // @require https://cdn.jsdelivr.net/npm/marked@4.2.3/marked.min.js
  21. // @require https://cdnjs.cloudflare.com/ajax/libs/markdown-it/13.0.1/markdown-it.min.js
  22. // @require https://unpkg.com/axios/dist/axios.min.js
  23. // @connect ip-api.com
  24. // @connect chat.openai.com
  25. // @connect gpt.chatapi.art
  26. // @license MIT
  27. // @resource css https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.1.0/github-markdown.css
  28. // @resource css https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/default.min.css
  29. // @require https://cdn.jsdelivr.net/npm/showdown@2.1.0/dist/showdown.min.js
  30. // @require https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js
  31. // @run-at document-end
  32.  
  33. // ==/UserScript==
  34.  
  35. (function () {
  36. 'use strict';
  37. // @require https://cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.8.0/highlightjs-line-numbers.min.js
  38.  
  39. //重要声明:感谢隔壁作者:zhengbangbo (https://github.com/zhengbangbo/chat-gpt-userscript)的请求处理方式,之前一直不知道怎么处理SSE响应,原来直接就可以用一般的方式来接收,那么对返回数据处理切割就直接借鉴啦!(反正MIT不是嘛)
  40. //cookie 大家自己想办法弄到,别霍霍我了呜呜
  41. //对返回结果增加了markdown解析成html
  42.  
  43. //请在上面添加一句:油猴因为策略问题没法增加这个js
  44. //多亏了zhengbangbo大佬,现在已经解决这个策略问题了!
  45. // @require https://cdn.jsdelivr.net/npm/marked/marked.min.js
  46.  
  47.  
  48.  
  49. //顶级配置
  50. //可以手动配置your_cookie!
  51. const your_cookie = getCookieObject().your_cookie
  52. const requestUrl = `https://chat.openai.com/backend-api/moderations`
  53. var your_qus
  54. var abortXml
  55. if (window.location.href.indexOf("bing.com") > -1) {
  56. getYourCookie()
  57. GM_add_box_style(0)
  58. addBothStyle()
  59. keyEvent()
  60. appendBox(0).then((res) => { pivElemAddEventAndValue(0) })
  61. linkToBing_beautification_script()
  62. }
  63. if (window.location.href.indexOf("www.google.com") > -1) {
  64. getYourCookie()
  65. GM_add_box_style(1)
  66. addBothStyle()
  67. keyEvent()
  68. appendBox(1).then((res) => { pivElemAddEventAndValue(1) })
  69. }
  70. if (window.location.href.indexOf("https://www.baidu.com/s?wd") > -1) {
  71. getYourCookie()
  72. GM_add_box_style(2)
  73. addBothStyle()
  74. keyEvent()
  75. appendBox(2).then((res) => { pivElemAddEventAndValue(2) })
  76. }
  77. if (window.location.href.indexOf(`www.startpage.com/sp/search`) > -1) {
  78. GM_add_box_style(3)
  79. addBothStyle()
  80. keyEvent()
  81. appendBox(3).then((res) => { pivElemAddEventAndValue(3) })
  82. }
  83. if (window.location.href.indexOf("chat.openai.com") > -1) {
  84. //$.cookie('yourCookie','dumplings', {domain:'qq.com',path:'/'});
  85. getYourCookie()
  86. console.log("httpOnly保护,没法拿到cookie,自己复制粘贴控制台")
  87. }
  88.  
  89. //顶级函数
  90. function uuid() { //uuid 产生
  91. var s = [];
  92. var hexDigits = "0123456789abcdef";
  93. for (var i = 0; i < 36; i++) {
  94. s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  95. }
  96. s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
  97. s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
  98. s[8] = s[13] = s[18] = s[23] = "-";
  99.  
  100. var uuid = s.join("");
  101. return uuid;
  102. }
  103. function GM_add_box_style(case_web) {
  104. switch (case_web) {
  105. case 0://bing
  106. GM_addStyle(`
  107. #gptAnswer{
  108. margin: 15px;
  109. border-top: solid;
  110. border-bottom: solid;
  111. }
  112. #gptInput{
  113. width:74%;
  114. border-radius: 4px;
  115. }
  116. #gptInputBox{
  117. display: flex;
  118. justify-content: space-around;
  119. }
  120.  
  121. #button_GPT:hover{
  122. background:#ffffffcc;
  123. }
  124. #gptDiv{
  125. border-radius: 8px;
  126. padding: 10px;
  127. margin-bottom: 9px;
  128. width:452px;
  129. translate:-20px;
  130. background:#ffffffcc;
  131. backdrop-filter: blur(5px);
  132. display: flex;
  133. flex-direction: column;
  134. }
  135. #button_GPT{
  136. background: transparent;
  137. border-radius: 4px;
  138.  
  139. }
  140. #gptCueBox{
  141. translate: 3px;
  142. }
  143.  
  144.  
  145.  
  146. `)
  147. break;
  148. case 1: //google
  149. GM_addStyle(`
  150. #gptAnswer{
  151. margin: 15px;
  152. border-top: solid;
  153. border-bottom: solid;
  154. }
  155. #gptInput{
  156. border-radius: 4px;
  157. width: 68%;
  158. }
  159. #button_GPT:hover{
  160. background:#dcdcdccc;
  161. }
  162. #gptDiv{
  163. flex: 1;
  164. display: flex;
  165. flex-direction: column;
  166. height: fit-content;
  167.  
  168. }
  169. #gptInputBox{
  170. display:flex;
  171. justify-content: space-around;
  172. }
  173. #button_GPT{
  174. background: transparent;
  175. border-radius: 3px;
  176. font-size: 14px;
  177. }
  178. #gptStatus{
  179. margin-left: 7px;
  180. }
  181.  
  182. `)
  183. break;//baidu
  184. case 2: GM_addStyle(`
  185. #gptAnswer{
  186. margin: 15px;
  187. border-top: solid;
  188. border-bottom: solid;
  189. }
  190. #gptInput{
  191. border-radius: 4px;
  192. width: 68%;
  193. }
  194. #button_GPT:hover{
  195. background:#dcdcdccc;
  196. }
  197. #gptDiv{
  198. flex: 1;
  199. display: flex;
  200. flex-direction: column;
  201. height: fit-content;
  202.  
  203. }
  204. #gptInputBox{
  205. display:flex;
  206. justify-content: space-around;
  207. }
  208. #button_GPT{
  209. background: transparent;
  210. border-radius: 3px;
  211. font-size: 14px;
  212. }
  213. #gptStatus{
  214. margin-left: 7px;
  215. }
  216.  
  217.  
  218.  
  219. `)
  220. break;
  221. case 3: //startpage
  222. GM_addStyle(`
  223. #gptAnswer{
  224. margin: 15px;
  225. border-top: solid;
  226. border-bottom: solid;
  227. }
  228. #gptInput{
  229. border-radius: 4px;
  230. width: 68%;
  231. }
  232. #button_GPT:hover{
  233. background:#dcdcdccc;
  234. }
  235. #gptDiv{
  236. flex: 1;
  237. display: flex;
  238. flex-direction: column;
  239. height: fit-content;
  240.  
  241. }
  242. #gptInputBox{
  243. display:flex;
  244. justify-content: space-around;
  245. }
  246. #button_GPT{
  247. background: transparent;
  248. border-radius: 3px;
  249. font-size: 14px;
  250. }
  251. #gptStatus{
  252. margin-left: 7px;
  253. }
  254.  
  255. `)
  256. break;
  257. default:
  258. alert("参数没设定")
  259. }
  260.  
  261. }
  262. function do_it() {
  263. if (!your_cookie) {
  264. document.getElementById('gptAnswer').innerHTML = `<div>你的cookie好像不见了!<a href="https://chat.openai.com">点我去登录获取</a></div>`
  265. }
  266. else {
  267.  
  268.  
  269. let finalResult
  270. let normalArray
  271. let nowResult
  272. document.getElementById('gptAnswer').innerHTML = `<div>加载中<span id="dot"></span></div>`
  273.  
  274. abortXml = GM_xmlhttpRequest({
  275. method: "POST",
  276. url: "https://chat.openai.com/backend-api/conversation",
  277. headers: {
  278. "Content-Type": "application/json",
  279. Authorization: `${your_cookie}`,
  280. },
  281. data: JSON.stringify({//抓包conversation就可以看到这个结构
  282. action: "next",
  283. messages: [
  284. {
  285. id: uuid(),
  286. role: "user",
  287. content: {
  288. content_type: "text",
  289. parts: [your_qus],
  290. },
  291. },
  292. ],
  293. model: "text-davinci-002-render",
  294. parent_message_id: uuid(),
  295. }),
  296. // onprogress: function(msg){console.log(msg)},
  297. // onreadystatechange:function(msg){log(msg)},
  298. onloadstart: (stream) => { //肝了好久,终于找到油猴接受SSE的接受方法了
  299. let result = "";
  300. const reader = stream.response.getReader();
  301. // console.log(reader.read)
  302. let charsReceived = 0;
  303. reader.read().then(function processText({ done, value }) {
  304. if (done) {
  305. if (finalResult == 0) {
  306. document.getElementById('gptAnswer').innerHTML = `<div>你的cookie好像过期了!<a href="https://chat.openai.com">点我去登录获取</a></div>`
  307. }
  308. else {
  309. document.getElementById('gptAnswer').innerHTML = `${mdConverter(decodeUnicode(finalResult.replace(/\\n+/g, "\n")))}`
  310. // document.querySelector("code").setAttribute("class", "language-javascript hljs");
  311. for (let i = 0; i <= document.getElementsByTagName("code").length - 1; i++) {
  312. document.getElementsByTagName("code")[i].setAttribute("class", "language-javascript");
  313. hljs.highlightAll()//奇怪,为什么不行
  314. }
  315. }
  316. return;
  317. }
  318.  
  319. charsReceived += value.length;
  320. const chunk = value;
  321. result += chunk;
  322. // log(JSON.stringify(chunk).replace(/\{/,"").replace(/\}/,""))
  323. normalArray = Array.from(chunk)
  324. // String.fromCharCode.apply(null, normalArray)
  325. nowResult = String.fromCharCode.apply(null, normalArray).match(/(?<=\[).*(?=\])/g)[0]
  326.  
  327. // console.log(mdConverter(decodeUnicode(nowResult.replace(/\\n+/g,"<换行>"))))
  328. if (nowResult !== "DONE") {
  329. finalResult = nowResult
  330. }
  331.  
  332. // console.log(finalResult)
  333. document.getElementById('gptAnswer').innerHTML = `${mdConverter(decodeUnicode(finalResult.replace(/\\n+/g, "\n")))}`
  334. return reader.read().then(processText);
  335. });
  336. },
  337. responseType: "stream",
  338. /* onloadend: function (data) {
  339. var answer
  340. if (data.response) {
  341. var data_transform=data.response.split("\n\n")
  342. if(data_transform){
  343. try{
  344. data_transform=JSON.parse(data_transform.slice(-3,-2)[0].slice(6))
  345. answer=data_transform.message.content.parts[0]
  346. document.getElementById('gptAnswer').innerHTML=marked.parse(answer)
  347. // if(!getCookieObject().preQuesAns){
  348. // window.document.cookie=`preQuesAns=""`
  349. // }
  350. // let preQuesAns = getCookieObject().preQuesAns+answer
  351. // window.document.cookie=`preQuesAns=${your_qus}${preQuesAns}`
  352. // sendModerations()
  353. }catch(err){
  354. console.log(`err:${err}`)
  355. }
  356. }
  357. // const answer = JSON.parse(data.response.split("\n\n").slice(-3, -2)[0].slice(6)).message.content.parts[0]
  358. }
  359. },*/
  360. onprogress: function (msg) {
  361. //console.log(msg) //Todo
  362. },
  363. onerror: function (err) {
  364. document.getElementById('gptAnswer').innerHTML = `<div>some err happends,errinfo :<br>${err}</div>`
  365. },
  366. ontimeout: function (err) {
  367. document.getElementById('gptAnswer').innerHTML = `<div>Opps!TimeOut,Please try again,errinfo:<br>${err}</div>`
  368. }
  369. })
  370. }
  371. }
  372. function creatBox() {
  373. return new Promise((resolve) => {
  374. var divE = document.createElement('div');
  375. var divId = document.createAttribute("id"); //创建属性
  376. divId.value = 'gptDiv'; //设置属性值
  377. divE.setAttributeNode(divId); //给div添加属性
  378. var pE = document.createElement('p');
  379. var pClass = document.createAttribute('class');
  380. pClass.value = 'textClass';
  381. pE.setAttributeNode(pClass)
  382. var pText = document.createTextNode("chatGPT tools Plus ++ v0.0.1已启动");
  383. pE.appendChild(pText);
  384. divE.appendChild(pE);
  385. divE.innerHTML = `
  386. <div id="gptInputBox">
  387. <input id="gptInput" type=text><button id="button_GPT" >chat一下</button>
  388. </div>
  389. <div id=gptCueBox>
  390. <p id="gptStatus">&nbsp openAI 已就绪,请输入你的问题</p>
  391. <article id="gptAnswer" class="markdown-body"><div id="gptAnswer_inner">chatGPT tools Plus ++ v1.4.4已启动<div></article>
  392. </div><p></p>`
  393. resolve(divE)
  394. })
  395. }
  396. async function pivElemAddEventAndValue(append_case) {
  397. var search_content
  398. if (append_case === 3) {
  399. search_content = document.getElementById('q').value
  400. }
  401. if (append_case === 2) {
  402. search_content = document.getElementById('kw').value
  403. }
  404. if (append_case === 1) {
  405. search_content = document.querySelector("#tsf > div:nth-child(1) > div.A8SBwf > div.RNNXgb > div > div.a4bIc > input:nth-child(3)").value
  406. }
  407. if (append_case === 0) {
  408. search_content = document.getElementsByClassName('b_searchbox')[0].value
  409. }
  410. document.getElementById("gptInput").value = search_content
  411. document.getElementById('button_GPT').addEventListener('click', () => {
  412. your_qus = document.getElementById("gptInput").value
  413. do_it()
  414.  
  415. })
  416.  
  417.  
  418. }
  419. async function appendBox(append_case) {
  420. return new Promise((resolve, reject) => {
  421. creatBox().then((divE) => {
  422. switch (append_case) {
  423. case 0: //bing
  424. if (divE) {
  425. document.getElementById('b_context').prepend(divE)
  426. }
  427. break;
  428. case 1://google
  429. if (document.getElementsByClassName('TQc1id ')[0]) {
  430. document.getElementsByClassName('TQc1id ')[0].prepend(divE);
  431. }
  432. else {
  433. document.getElementById("rcnt").appendChild(divE);
  434. }
  435. break;
  436. case 2:
  437. if (document.getElementById('content_right')) {
  438. document.getElementById('content_right').prepend(divE)
  439. }
  440. break;
  441. case 3:
  442. if(document.getElementsByClassName("layout-web__sidebar")[0]){
  443. document.getElementsByClassName("layout-web__sidebar")[0].prepend(divE)
  444. }
  445. break;
  446. default:
  447. if (divE) {
  448. console.log(`啥情况${divE}`)
  449. }
  450. }
  451. }).catch((err) => {
  452. throw new Error(err)
  453. })
  454.  
  455. resolve("finished")
  456. })
  457. }
  458. //焦点函数
  459. function isBlur() {
  460. var myInput = document.getElementById('gptInput');
  461. if (myInput == document.activeElement) {
  462. return 1
  463. } else {
  464. return 0
  465. }
  466. }
  467. function keyEvent() {
  468. document.onkeydown = function (e) {
  469. var keyNum = window.event ? e.keyCode : e.which;
  470. if (13 == keyNum) {
  471. if (isBlur()) {
  472. document.getElementById('button_GPT').click()
  473. }
  474. else {
  475. console.log("失焦不执行")
  476. }
  477.  
  478. }
  479. }
  480.  
  481. }
  482. function checkIp() {
  483. GM_xmlhttpRequest({
  484. method: "GET",
  485. url: "http://ip-api.com/json/",
  486. onloadend: function (data) {
  487. if (data) {
  488. try {
  489. data = JSON.parse(data.response)
  490. } catch (err) {
  491. console.log(err)
  492. }
  493. console.log(data.country)
  494. if (data.country == "Hong Kong") {
  495. document.getElementById('gptStatus').innerHTML = `&nbsp openAI 已就绪,请输入你的问题`
  496. }
  497. }
  498. else {
  499. document.getElementById('gptStatus').innerHTML = `&nbsp openAI 没有就绪,请更换你的IP为非大陆节点`
  500. throw new Error('Error while executing the code');
  501. }
  502. },
  503. onerror: function (err) {
  504. document.getElementById('gptStatus').innerHTML = `&nbsp openAI 没有就绪,请更换你的IP为非大陆节点`
  505. throw new Error('Error while executing the code');
  506. },
  507. ontimeout: function (err) {
  508. document.getElementById('gptStatus').innerHTML = `&nbsp openAI 没有就绪,请更换你的IP为非大陆节点`
  509. throw new Error('Error while executing the code');
  510. }
  511. })
  512. }
  513. function addBothStyle() {
  514. GM_addStyle(`
  515. #dot{
  516. height: 4px;
  517. width: 4px;
  518. display: inline-block;
  519. border-radius: 2px;
  520. animation: dotting 2.4s infinite step-start;
  521. }
  522. @keyframes dotting {
  523. 25%{
  524. box-shadow: 4px 0 0 #71777D;
  525. }
  526. 50%{
  527. box-shadow: 4px 0 0 #71777D ,14px 0 0 #71777D;
  528. }
  529. 75%{
  530. box-shadow: 4px 0 0 #71777D ,14px 0 0 #71777D, 24px 0 0 #71777D;
  531. }
  532. }
  533. pre{
  534. overflow-x: auto;
  535. overflow-y: hidden;
  536. background: #fffaec;
  537. border-radius: 4px;
  538. padding: 14px 3px;
  539. }
  540. pre::-webkit-scrollbar {
  541. }
  542. pre code.hljs {
  543. display: block;
  544. overflow-x: auto;
  545. padding: 1em
  546. }
  547.  
  548. code.hljs {
  549. padding: 3px 5px
  550. }
  551.  
  552. .hljs {
  553. background: #fffaec;
  554. color: #612d2d
  555. }
  556.  
  557. .hljs-comment {
  558. color: #697070
  559. }
  560.  
  561. .hljs-punctuation,.hljs-tag {
  562. color: #444a
  563. }
  564.  
  565. .hljs-tag .hljs-attr,.hljs-tag .hljs-name {
  566. color: #444
  567. }
  568.  
  569. .hljs-attribute,.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-name,.hljs-selector-tag {
  570. font-weight: 700
  571. }
  572.  
  573. .hljs-deletion,.hljs-number,.hljs-quote,.hljs-selector-class,.hljs-selector-id,.hljs-string,.hljs-template-tag,.hljs-type {
  574. color: #098658
  575. }
  576.  
  577. .hljs-section,.hljs-title {
  578. color: #1313ffdb;
  579. font-weight: 700
  580. }
  581.  
  582. .hljs-link,.hljs-operator,.hljs-regexp,.hljs-selector-attr,.hljs-selector-pseudo,.hljs-symbol,.hljs-template-variable,.hljs-variable {
  583. color: #001080
  584. }
  585.  
  586. .hljs-literal {
  587. color: #695
  588. }
  589.  
  590. .hljs-addition,.hljs-built_in,.hljs-bullet,.hljs-code {
  591. color: #397300
  592. }
  593.  
  594. .hljs-meta {
  595. color: #1f7199
  596. }
  597.  
  598. .hljs-meta .hljs-string {
  599. color: #38a
  600. }
  601.  
  602. .hljs-emphasis {
  603. font-style: italic
  604. }
  605.  
  606. .hljs-strong {
  607. font-weight: 700
  608. }
  609. `)
  610. }
  611. function getYourCookie() {
  612. GM_xmlhttpRequest({
  613. method: "GET",
  614. url: "https://chat.openai.com/api/auth/session",
  615. onloadend: function (data) {
  616. if (data) {
  617. data = JSON.parse(data.response)
  618. console.log(data.accessToken)
  619. // window.document.cookie=`your_cookie=${data.accessToken};expire:1000*60*60*24`
  620. setCookie("your_cookie", data.accessToken, 1)
  621. }
  622. },
  623. onerror: function (err) {
  624. throw new Error('Error while executing the code');
  625.  
  626. },
  627. ontimeout: function (err) {
  628. throw new Error('Error while executing the code');
  629. }
  630. })
  631.  
  632.  
  633. }
  634. function setCookie(cname, cvalue, exdays) {
  635. var d = new Date();
  636. d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
  637. var expires = "expires=" + d.toGMTString();
  638. document.cookie = cname + "=" + cvalue + "; " + expires;
  639. }
  640. //原生cookie函数
  641. function getCookieObject() {
  642. let cookieString = document.cookie;
  643. cookieString = cookieString.substring(0, cookieString.length - 1);
  644. let tempCookieArray = cookieString.split('; ');
  645.  
  646. let cookieObject = {}; // 存放 cookie 键值对
  647.  
  648. tempCookieArray.forEach(item => {
  649. let name = item.substring(0, item.indexOf('='));
  650. let value = item.substring(item.indexOf('=') + 1);
  651. value = decodeURIComponent(value); // 还原字符串
  652. cookieObject[name] = value; // 将键值插入中这个对象中
  653. });
  654.  
  655. return cookieObject // 返回包含 cookie 键值对的对象
  656. }
  657. function sendModerations() {
  658. GM_xmlhttpRequest({
  659. method: "POST",
  660. url: requestUrl,
  661. headers: {
  662. "Content-Type": "application/json",
  663. Authorization: `Bearer ${your_cookie}`,
  664. },
  665. data: JSON.stringify({
  666. input: getCookieObject().preQuesAns,
  667. model: "text-moderation-playground"
  668. }),
  669. onloadend: function (data) {
  670. console.log(data)
  671. },
  672. onerror: function (err) {
  673. throw new Error('Error while executing the code');
  674.  
  675. },
  676. ontimeout: function (err) {
  677. throw new Error('Error while executing the code');
  678. }
  679. })
  680.  
  681.  
  682. }
  683. function autoClick() {
  684. document.getElementById('button_GPT').click()
  685. }
  686. function linkToBing_beautification_script() {
  687.  
  688. if (getCookieObject.blurDeg && getCookieObject.aDeg1 && getCookieObject.aDeg2) {
  689. document.getElementById('gptDiv').style.background = `#ffffff${getCookieObject.aDeg2}`
  690. document.getElementById('gptDiv').style.backdropFilter = `${getCookieObject.blurDeg}`
  691. }
  692. }
  693. function creatBox_and_addEventlis(append_case) {
  694. var divE = document.createElement('div');
  695. var divId = document.createAttribute("id"); //创建属性
  696. divId.value = 'gptDiv'; //设置属性值
  697. divE.setAttributeNode(divId); //给div添加属性
  698. var pE = document.createElement('p');
  699. var pClass = document.createAttribute('class');
  700. pClass.value = 'textClass';
  701. pE.setAttributeNode(pClass)
  702. var pText = document.createTextNode("chatGPT tools Plus ++ v0.1.3已启动");
  703. pE.appendChild(pText);
  704. divE.appendChild(pE);
  705. switch (append_case) {
  706. case 0:
  707. if (divE) {
  708. document.getElementById('b_context').prepend(divE)
  709. }
  710. break;
  711. case 1:
  712. if (document.getElementsByClassName('TQc1id ')[0]) {
  713. document.getElementsByClassName('TQc1id ')[0].prepend(divE);
  714. }
  715. else {
  716. document.getElementById("rcnt").appendChild(divE);
  717. }
  718. break;
  719. case 2:
  720. if (document.getElementById('content_right')) {
  721. document.getElementById('content_right').prepend(divE)
  722. }
  723. break;
  724. default:
  725. if (divE) {
  726. document.getElementById('b_context').prepend(divE)
  727. }
  728. }
  729. document.getElementById('gptDiv').innerHTML = `<div id="gptInputBox"><input id="gptInput"type=text><button id="button_GPT">chat一下</button></div><div id=gptCueBox><p id="gptStatus">&nbsp openAI已就绪,请输入你的问题</p><div id="gptAnswer">chatGPT tools Plus++免费版v0.1.3已启动</div></div><p></p>`
  730. var search_content
  731. if (append_case === 2) {
  732. search_content = document.getElementById('kw').value
  733. }
  734. if (append_case === 1) {
  735. search_content = document.querySelector("#tsf > div:nth-child(1) > div.A8SBwf > div.RNNXgb > div > div.a4bIc > input:nth-child(3)").value
  736. }
  737. if (append_case === 0) {
  738. search_content = document.getElementsByClassName('b_searchbox')[0].value
  739. }
  740. document.getElementById("gptInput").value = search_content
  741. document.getElementById('button_GPT').addEventListener('click', () => {
  742. your_qus = document.getElementById("gptInput").value
  743. do_it()
  744.  
  745. })
  746. }
  747. function log(a) {
  748. console.log(a)
  749. }
  750.  
  751. function Uint8ArrayToString(fileData) {
  752. var dataString = "";
  753. for (var i = 0; i < fileData.length; i++) {
  754. dataString += String.fromCharCode(fileData[i]);
  755. }
  756.  
  757. return dataString
  758. }
  759. function decodeUnicode(str) {
  760. str = str.replace(/\\/g, "%");
  761. //转换中文
  762. str = unescape(str);
  763. //将其他受影响的转换回原来
  764. str = str.replace(/%/g, "\\");
  765. //对网址的链接进行处理
  766. str = str.replace(/\\/g, "");
  767. return str;
  768. }
  769. function mdConverter(rawData) {
  770. var converter = new showdown.Converter(); //增加拓展table
  771. converter.setOption('tables', true); //启用表格选项。从showdown 1.2.0版开始,表支持已作为可选功能移入核心拓展,showdown.table.min.js扩展已被弃用
  772. var view = converter.makeHtml(rawData);
  773. return view;
  774. }
  775. function getCookie(cname) {
  776. var name = cname + "=";
  777. var ca = document.cookie.split(';');
  778. for (var i = 0; i < ca.length; i++) {
  779. var c = ca[i].trim();
  780. if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
  781. }
  782. return "";
  783. }
  784. const sleep = (time) => {
  785. return new Promise(resolve => setTimeout(resolve, time))
  786. }
  787. function sound2words(){
  788. var recognition = new webkitSpeechRecognition();
  789. recognition.lang = 'zh-CN';
  790. recognition.onresult = function(event) {
  791. console.log(event.results[0][0].transcript)
  792. }
  793. recognition.start();
  794. }
  795.  
  796.  
  797.  
  798.  
  799. })();