ChatGPT 搜索

側欄顯示 ChatGPT 回答(Google、Bing、百度、DuckDuckGo和DeepL)

  1. // ==UserScript==
  2. // @name ChatGPT Search
  3. // @name:zh-CN ChatGPT 搜索
  4. // @name:zh-SG ChatGPT 搜索
  5. // @name:zh-TW ChatGPT 搜索
  6. // @name:zh-HK ChatGPT 搜索
  7. // @namespace https://gf.qytechs.cn/scripts/456077
  8. // @version 0.8.0
  9. // @author Zheng Bang-Bo(https://github.com/zhengbangbo)
  10. // @description ChatGPT answers displayed in sidebar after search (Google, Bing, Baidu, DuckDuckGo and DeepL)
  11. // @description:zh-CN 侧栏显示 ChatGPT 回答(Google、Bing、百度、DuckDuckGo和DeepL)
  12. // @description:zh-SG 侧栏显示 ChatGPT 回答(Google、Bing、百度、DuckDuckGo和DeepL)
  13. // @description:zh-TW 側欄顯示 ChatGPT 回答(Google、Bing、百度、DuckDuckGo和DeepL)
  14. // @description:zh-HK 側欄顯示 ChatGPT 回答(Google、Bing、百度、DuckDuckGo和DeepL)
  15. // @license MIT
  16. // @icon https://github.com/zhengbangbo/oss/raw/main/logo/chat-gpt-userscript.png
  17. // @match https://*.google.com/search*
  18. // @match https://*.google.ad/search*
  19. // @match https://*.google.ae/search*
  20. // @match https://*.google.com.af/search*
  21. // @match https://*.google.com.ag/search*
  22. // @match https://*.google.com.ai/search*
  23. // @match https://*.google.al/search*
  24. // @match https://*.google.am/search*
  25. // @match https://*.google.co.ao/search*
  26. // @match https://*.google.com.ar/search*
  27. // @match https://*.google.as/search*
  28. // @match https://*.google.at/search*
  29. // @match https://*.google.com.au/search*
  30. // @match https://*.google.az/search*
  31. // @match https://*.google.ba/search*
  32. // @match https://*.google.com.bd/search*
  33. // @match https://*.google.be/search*
  34. // @match https://*.google.bf/search*
  35. // @match https://*.google.bg/search*
  36. // @match https://*.google.com.bh/search*
  37. // @match https://*.google.bi/search*
  38. // @match https://*.google.bj/search*
  39. // @match https://*.google.com.bn/search*
  40. // @match https://*.google.com.bo/search*
  41. // @match https://*.google.com.br/search*
  42. // @match https://*.google.bs/search*
  43. // @match https://*.google.bt/search*
  44. // @match https://*.google.co.bw/search*
  45. // @match https://*.google.by/search*
  46. // @match https://*.google.com.bz/search*
  47. // @match https://*.google.ca/search*
  48. // @match https://*.google.cd/search*
  49. // @match https://*.google.cf/search*
  50. // @match https://*.google.cg/search*
  51. // @match https://*.google.ch/search*
  52. // @match https://*.google.ci/search*
  53. // @match https://*.google.co.ck/search*
  54. // @match https://*.google.cl/search*
  55. // @match https://*.google.cm/search*
  56. // @match https://*.google.cn/search*
  57. // @match https://*.google.com.co/search*
  58. // @match https://*.google.co.cr/search*
  59. // @match https://*.google.com.cu/search*
  60. // @match https://*.google.cv/search*
  61. // @match https://*.google.com.cy/search*
  62. // @match https://*.google.cz/search*
  63. // @match https://*.google.de/search*
  64. // @match https://*.google.dj/search*
  65. // @match https://*.google.dk/search*
  66. // @match https://*.google.dm/search*
  67. // @match https://*.google.com.do/search*
  68. // @match https://*.google.dz/search*
  69. // @match https://*.google.com.ec/search*
  70. // @match https://*.google.ee/search*
  71. // @match https://*.google.com.eg/search*
  72. // @match https://*.google.es/search*
  73. // @match https://*.google.com.et/search*
  74. // @match https://*.google.fi/search*
  75. // @match https://*.google.com.fj/search*
  76. // @match https://*.google.fm/search*
  77. // @match https://*.google.fr/search*
  78. // @match https://*.google.ga/search*
  79. // @match https://*.google.ge/search*
  80. // @match https://*.google.gg/search*
  81. // @match https://*.google.com.gh/search*
  82. // @match https://*.google.com.gi/search*
  83. // @match https://*.google.gl/search*
  84. // @match https://*.google.gm/search*
  85. // @match https://*.google.gr/search*
  86. // @match https://*.google.com.gt/search*
  87. // @match https://*.google.gy/search*
  88. // @match https://*.google.com.hk/search*
  89. // @match https://*.google.hn/search*
  90. // @match https://*.google.hr/search*
  91. // @match https://*.google.ht/search*
  92. // @match https://*.google.hu/search*
  93. // @match https://*.google.co.id/search*
  94. // @match https://*.google.ie/search*
  95. // @match https://*.google.co.il/search*
  96. // @match https://*.google.im/search*
  97. // @match https://*.google.co.in/search*
  98. // @match https://*.google.iq/search*
  99. // @match https://*.google.is/search*
  100. // @match https://*.google.it/search*
  101. // @match https://*.google.je/search*
  102. // @match https://*.google.com.jm/search*
  103. // @match https://*.google.jo/search*
  104. // @match https://*.google.co.jp/search*
  105. // @match https://*.google.co.ke/search*
  106. // @match https://*.google.com.kh/search*
  107. // @match https://*.google.ki/search*
  108. // @match https://*.google.kg/search*
  109. // @match https://*.google.co.kr/search*
  110. // @match https://*.google.com.kw/search*
  111. // @match https://*.google.kz/search*
  112. // @match https://*.google.la/search*
  113. // @match https://*.google.com.lb/search*
  114. // @match https://*.google.li/search*
  115. // @match https://*.google.lk/search*
  116. // @match https://*.google.co.ls/search*
  117. // @match https://*.google.lt/search*
  118. // @match https://*.google.lu/search*
  119. // @match https://*.google.lv/search*
  120. // @match https://*.google.com.ly/search*
  121. // @match https://*.google.co.ma/search*
  122. // @match https://*.google.md/search*
  123. // @match https://*.google.me/search*
  124. // @match https://*.google.mg/search*
  125. // @match https://*.google.mk/search*
  126. // @match https://*.google.ml/search*
  127. // @match https://*.google.com.mm/search*
  128. // @match https://*.google.mn/search*
  129. // @match https://*.google.ms/search*
  130. // @match https://*.google.com.mt/search*
  131. // @match https://*.google.mu/search*
  132. // @match https://*.google.mv/search*
  133. // @match https://*.google.mw/search*
  134. // @match https://*.google.com.mx/search*
  135. // @match https://*.google.com.my/search*
  136. // @match https://*.google.co.mz/search*
  137. // @match https://*.google.com.na/search*
  138. // @match https://*.google.com.ng/search*
  139. // @match https://*.google.com.ni/search*
  140. // @match https://*.google.ne/search*
  141. // @match https://*.google.nl/search*
  142. // @match https://*.google.no/search*
  143. // @match https://*.google.com.np/search*
  144. // @match https://*.google.nr/search*
  145. // @match https://*.google.nu/search*
  146. // @match https://*.google.co.nz/search*
  147. // @match https://*.google.com.om/search*
  148. // @match https://*.google.com.pa/search*
  149. // @match https://*.google.com.pe/search*
  150. // @match https://*.google.com.pg/search*
  151. // @match https://*.google.com.ph/search*
  152. // @match https://*.google.com.pk/search*
  153. // @match https://*.google.pl/search*
  154. // @match https://*.google.pn/search*
  155. // @match https://*.google.com.pr/search*
  156. // @match https://*.google.ps/search*
  157. // @match https://*.google.pt/search*
  158. // @match https://*.google.com.py/search*
  159. // @match https://*.google.com.qa/search*
  160. // @match https://*.google.ro/search*
  161. // @match https://*.google.ru/search*
  162. // @match https://*.google.rw/search*
  163. // @match https://*.google.com.sa/search*
  164. // @match https://*.google.com.sb/search*
  165. // @match https://*.google.sc/search*
  166. // @match https://*.google.se/search*
  167. // @match https://*.google.com.sg/search*
  168. // @match https://*.google.sh/search*
  169. // @match https://*.google.si/search*
  170. // @match https://*.google.sk/search*
  171. // @match https://*.google.com.sl/search*
  172. // @match https://*.google.sn/search*
  173. // @match https://*.google.so/search*
  174. // @match https://*.google.sm/search*
  175. // @match https://*.google.sr/search*
  176. // @match https://*.google.st/search*
  177. // @match https://*.google.com.sv/search*
  178. // @match https://*.google.td/search*
  179. // @match https://*.google.tg/search*
  180. // @match https://*.google.co.th/search*
  181. // @match https://*.google.com.tj/search*
  182. // @match https://*.google.tl/search*
  183. // @match https://*.google.tm/search*
  184. // @match https://*.google.tn/search*
  185. // @match https://*.google.to/search*
  186. // @match https://*.google.com.tr/search*
  187. // @match https://*.google.tt/search*
  188. // @match https://*.google.com.tw/search*
  189. // @match https://*.google.co.tz/search*
  190. // @match https://*.google.com.ua/search*
  191. // @match https://*.google.co.ug/search*
  192. // @match https://*.google.co.uk/search*
  193. // @match https://*.google.com.uy/search*
  194. // @match https://*.google.co.uz/search*
  195. // @match https://*.google.com.vc/search*
  196. // @match https://*.google.co.ve/search*
  197. // @match https://*.google.vg/search*
  198. // @match https://*.google.co.vi/search*
  199. // @match https://*.google.com.vn/search*
  200. // @match https://*.google.vu/search*
  201. // @match https://*.google.ws/search*
  202. // @match https://*.google.rs/search*
  203. // @match https://*.google.co.za/search*
  204. // @match https://*.google.co.zm/search*
  205. // @match https://*.google.co.zw/search*
  206. // @match https://*.google.cat/search*
  207. // @match https://www.bing.com/search*
  208. // @match https://cn.bing.com/search*
  209. // @match https://www.baidu.com/s*
  210. // @match https://duckduckgo.com/*
  211. // @match https://www.deepl.com/translator*
  212. // @connect chat.openai.com
  213. // @grant GM_addStyle
  214. // @grant GM_deleteValue
  215. // @grant GM_getValue
  216. // @grant GM_info
  217. // @grant GM_registerMenuCommand
  218. // @grant GM_setValue
  219. // @grant GM_unregisterMenuCommand
  220. // @grant GM_xmlhttpRequest
  221. // ==/UserScript==
  222.  
  223. (e=>{const t=document.createElement("style");t.dataset.source="vite-plugin-monkey",t.innerText=e,document.head.appendChild(t)})(".chat-gpt-container{max-width:369px;margin-bottom:30px;border-radius:8px;border:1px solid #dadce0;padding:15px;flex-basis:0;flex-grow:1;word-wrap:break-word;white-space:pre-wrap}.chat-gpt-container p{margin:0}.chat-gpt-container .prefix{font-weight:700}.chat-gpt-container .loading{color:#b6b8ba;animation:pulse 2s cubic-bezier(.4,0,.6,1) infinite}@keyframes pulse{0%,to{opacity:1}50%{opacity:.5}}.chat-gpt-container.sidebar-free{margin-left:60px;height:fit-content}.chat-gpt-container pre{white-space:pre-wrap;min-width:0;margin-bottom:0;line-height:20px}.chat-gpt-translate-button{border-radius:8px;border:1px solid #dadce0;padding:5px}.chat-gpt-translate-button:hover{color:#006494;transition:color .1s ease-out}.chat-gpt-translate-button[disabled]{color:#eee}");
  224.  
  225. (function() {
  226. "use strict";
  227. var monkeyWindow = window;
  228. var GM_info = /* @__PURE__ */ (() => monkeyWindow.GM_info)();
  229. var GM_setValue = /* @__PURE__ */ (() => monkeyWindow.GM_setValue)();
  230. var GM_deleteValue = /* @__PURE__ */ (() => monkeyWindow.GM_deleteValue)();
  231. var GM_addStyle = /* @__PURE__ */ (() => monkeyWindow.GM_addStyle)();
  232. var GM_registerMenuCommand = /* @__PURE__ */ (() => monkeyWindow.GM_registerMenuCommand)();
  233. var GM_unregisterMenuCommand = /* @__PURE__ */ (() => monkeyWindow.GM_unregisterMenuCommand)();
  234. var GM_xmlhttpRequest = /* @__PURE__ */ (() => monkeyWindow.GM_xmlhttpRequest)();
  235. var GM_getValue = /* @__PURE__ */ (() => monkeyWindow.GM_getValue)();
  236. function getUserscriptManager() {
  237. try {
  238. const userscriptManager = GM_info.scriptHandler;
  239. return userscriptManager;
  240. } catch (error) {
  241. return "other";
  242. }
  243. }
  244. function uuidv4() {
  245. var s = [];
  246. var hexDigits = "0123456789abcdef";
  247. for (var i = 0; i < 36; i++) {
  248. s[i] = hexDigits.substr(Math.floor(Math.random() * 16), 1);
  249. }
  250. s[14] = "4";
  251. s[19] = hexDigits.substr(s[19] & 3 | 8, 1);
  252. s[8] = s[13] = s[18] = s[23] = "-";
  253. var uuid = s.join("");
  254. return uuid;
  255. }
  256. const lang = navigator.appName == "Netscape" ? navigator.language : navigator.userLanguage;
  257. let config = {};
  258. switch (lang) {
  259. case "zh-CN":
  260. case "zh-SG":
  261. config = {
  262. waitingResponse: "等待 ChatGPT 响应...",
  263. login: "请在以下地址登录(不可用):",
  264. tooManyRequests: "1小时内请求太多。请稍后再试。",
  265. checkClouflare: "请通过 Cloudflare 安全检查,地址为",
  266. unknowError: "哦,可能是个错误,请检查或提交到",
  267. networkException: "网络异常,请刷新页面。",
  268. containerPosition: "容器位置 - 侧面(1)/顶部(0): ",
  269. chatGPTTranslate: "ChatGPT 翻译"
  270. };
  271. break;
  272. case "zh-TW":
  273. case "zh-HK":
  274. config = {
  275. waitingResponse: "等待 ChatGPT 回應...",
  276. login: "請在以下地址登錄:",
  277. tooManyRequests: "1小時內請求太多。請稍後再試。",
  278. checkClouflare: "請通過 Cloudflare 安全檢查,地址為",
  279. unknowError: "哦,可能是個錯誤,請檢查或提交到",
  280. networkException: "網路異常,請刷新頁面。",
  281. containerPosition: "容器位置 - 側面(1)/頂部(0):",
  282. chatGPTTranslate: "ChatGPT 翻譯"
  283. };
  284. break;
  285. default:
  286. config = {
  287. waitingResponse: "Waiting for ChatGPT response...",
  288. login: "Please login at ",
  289. tooManyRequests: "Too many requests in 1 hour. Try again later.",
  290. checkClouflare: "Please pass Cloudflare security check at ",
  291. unknowError: "Oops, maybe it is a bug, please check or submit ",
  292. networkException: "Network exception, please refresh the page.",
  293. containerPosition: "Container Position - Side(1)/Top(0): ",
  294. chatGPTTranslate: "ChatGPT Translate"
  295. };
  296. }
  297. function i18n(name, param) {
  298. return config[name] ? config[name].replace("#t#", param) : name;
  299. }
  300. const container = document.createElement("div");
  301. function getContainer() {
  302. return container;
  303. }
  304. function initContainer() {
  305. const container2 = getContainer();
  306. container2.className = "chat-gpt-container";
  307. container2.innerHTML = `<p class="loading">${i18n("waitingResponse")}</p>`;
  308. }
  309. function containerShow(answer) {
  310. const container2 = getContainer();
  311. container2.innerHTML = '<p><span class="prefix">ChatGPT</span><pre></pre></p>';
  312. container2.querySelector("pre").textContent = answer;
  313. }
  314. function containerAlert(htmlStr) {
  315. const container2 = getContainer();
  316. container2.innerHTML = htmlStr;
  317. }
  318. function alertLogin() {
  319. containerAlert(`<p>${i18n("login")}<a href="https://chat.openai.com" target="_blank" rel="noreferrer">chat.openai.com</a></p>`);
  320. }
  321. function alertBlockedByCloudflare() {
  322. containerAlert(`<p>${i18n("checkClouflare")}<a href="https://chat.openai.com" target="_blank" rel="noreferrer">chat.openai.com</a></p>`);
  323. }
  324. function alertFrequentRequests() {
  325. containerAlert(`<p>${i18n("tooManyRequests")}</p>`);
  326. }
  327. function isBlockedbyCloudflare(resp) {
  328. try {
  329. const html = new DOMParser().parseFromString(resp, "text/html");
  330. const title = html.querySelector("title");
  331. return title.innerText === "Just a moment...";
  332. } catch (error) {
  333. return false;
  334. }
  335. }
  336. async function getAnswer(question, callback) {
  337. try {
  338. const accessToken = await getAccessToken();
  339. GM_xmlhttpRequest({
  340. method: "POST",
  341. url: "https://chat.openai.com/backend-api/conversation",
  342. headers: {
  343. "Content-Type": " application/json",
  344. Authorization: `Bearer ${accessToken}`
  345. },
  346. responseType: responseType(),
  347. data: JSON.stringify({
  348. action: "next",
  349. messages: [
  350. {
  351. id: uuidv4(),
  352. role: "user",
  353. content: {
  354. content_type: "text",
  355. parts: [question]
  356. }
  357. }
  358. ],
  359. model: "text-davinci-002-render",
  360. parent_message_id: uuidv4()
  361. }),
  362. onloadstart: onloadstart(),
  363. onload: onload(),
  364. onerror: function(event) {
  365. console.error("getAnswer error: ", event);
  366. },
  367. ontimeout: function(event) {
  368. console.error("getAnswer timeout: ", event);
  369. }
  370. });
  371. } catch (error) {
  372. if (error === "UNAUTHORIZED") {
  373. removeAccessToken();
  374. alertLogin();
  375. }
  376. console.error("getAnswer error: ", error);
  377. }
  378. function responseType() {
  379. if (getUserscriptManager() === "Tampermonkey") {
  380. return "stream";
  381. } else {
  382. return "text";
  383. }
  384. }
  385. function onload() {
  386. function finish() {
  387. if (typeof callback === "function") {
  388. return callback("finish");
  389. }
  390. }
  391. finish();
  392. return function(event) {
  393. if (event.status === 401) {
  394. removeAccessToken();
  395. alertLogin();
  396. }
  397. if (event.status === 403) {
  398. alertBlockedByCloudflare();
  399. }
  400. if (event.status === 429) {
  401. alertFrequentRequests();
  402. }
  403. if (getUserscriptManager() !== "Tampermonkey") {
  404. if (event.response) {
  405. const answer = JSON.parse(event.response.split("\n\n").slice(-3, -2)[0].slice(6)).message.content.parts[0];
  406. containerShow(answer);
  407. }
  408. }
  409. };
  410. }
  411. function onloadstart() {
  412. if (getUserscriptManager() === "Tampermonkey") {
  413. return function(stream) {
  414. const reader = stream.response.getReader();
  415. reader.read().then(function processText({ done, value }) {
  416. if (done) {
  417. return;
  418. }
  419. let responseItem = String.fromCharCode(...Array.from(value));
  420. const items = responseItem.split("\n\n");
  421. if (items.length > 2) {
  422. const lastItem = items.slice(-3, -2)[0];
  423. if (lastItem.startsWith("data: [DONE]")) {
  424. responseItem = items.slice(-4, -3)[0];
  425. } else {
  426. responseItem = lastItem;
  427. }
  428. }
  429. if (responseItem.startsWith("data: {")) {
  430. const answer = JSON.parse(responseItem.slice(6)).message.content.parts[0];
  431. containerShow(answer);
  432. } else if (responseItem.startsWith("data: [DONE]")) {
  433. return;
  434. }
  435. return reader.read().then(processText);
  436. });
  437. };
  438. }
  439. }
  440. }
  441. function removeAccessToken() {
  442. GM_deleteValue("accessToken");
  443. }
  444. function getAccessToken() {
  445. return new Promise(async (resolve, rejcet) => {
  446. const accessToken = await GM_getValue("accessToken");
  447. if (!accessToken) {
  448. GM_xmlhttpRequest({
  449. url: "https://chat.openai.com/api/auth/session",
  450. onload: function(response) {
  451. if (isBlockedbyCloudflare(response.responseText)) {
  452. alertLogin();
  453. return;
  454. }
  455. const accessToken2 = JSON.parse(response.responseText).accessToken;
  456. if (!accessToken2) {
  457. rejcet("UNAUTHORIZED");
  458. }
  459. GM_setValue("accessToken", accessToken2);
  460. resolve(accessToken2);
  461. },
  462. onerror: function(error) {
  463. rejcet(error);
  464. },
  465. ontimeout: () => {
  466. console.error("getAccessToken timeout!");
  467. }
  468. });
  469. } else {
  470. resolve(accessToken);
  471. }
  472. });
  473. }
  474. const _default = "";
  475. function getWebsite() {
  476. if (location.hostname.indexOf(".google.") !== -1) {
  477. return configRequestImmediately("google");
  478. }
  479. switch (location.hostname) {
  480. case "www.bing.com":
  481. case "cn.bing.com":
  482. return configRequestImmediately("bing");
  483. case "www.baidu.com":
  484. return configRequestImmediately("baidu");
  485. case "duckduckgo.com":
  486. return configRequestImmediately("duckduckgo");
  487. case "www.deepl.com":
  488. return configRequestAfterClickButton("deepl");
  489. default:
  490. throw new Error(`unknow website: ${location.hostname}`);
  491. }
  492. function configRequestImmediately(name) {
  493. return {
  494. name,
  495. type: "immediately"
  496. };
  497. }
  498. function configRequestAfterClickButton(name) {
  499. return {
  500. name,
  501. type: "after-click-button"
  502. };
  503. }
  504. }
  505. function getQuestion() {
  506. switch (getWebsite().name) {
  507. case "baidu":
  508. return new URL(window.location.href).searchParams.get("wd");
  509. default:
  510. return new URL(window.location.href).searchParams.get("q");
  511. }
  512. }
  513. function getPosition() {
  514. return GM_getValue("containerPosition", 1);
  515. }
  516. function setPosition(newPosition) {
  517. GM_setValue("containerPosition", newPosition);
  518. }
  519. function initUI() {
  520. initContainer();
  521. switch (getWebsite().name) {
  522. case "google":
  523. googleInjectContainer();
  524. break;
  525. case "bing":
  526. bingInjectContainer();
  527. break;
  528. case "baidu":
  529. baiduInjectContainer();
  530. break;
  531. case "duckduckgo":
  532. duckduckgoInjectContainer();
  533. break;
  534. case "deepl":
  535. deeplInjectContainer();
  536. break;
  537. default:
  538. alertUnknowError();
  539. }
  540. function googleInjectContainer() {
  541. if (getPosition() === 1) {
  542. const container2 = getContainer();
  543. const siderbarContainer = document.getElementById("rhs");
  544. if (siderbarContainer) {
  545. siderbarContainer.prepend(container2);
  546. } else {
  547. container2.classList.add("sidebar-free");
  548. document.getElementById("rcnt").appendChild(container2);
  549. }
  550. } else {
  551. GM_addStyle(".chat-gpt-container{max-width: 100%!important}");
  552. const container2 = getContainer();
  553. const mainContainer = document.querySelector("#search");
  554. if (mainContainer) {
  555. mainContainer.prepend(container2);
  556. }
  557. }
  558. }
  559. function bingInjectContainer() {
  560. if (getPosition() === 1) {
  561. const container2 = getContainer();
  562. const siderbarContainer = document.getElementById("b_context");
  563. siderbarContainer.prepend(container2);
  564. } else {
  565. GM_addStyle(".chat-gpt-container{max-width: 100%!important}");
  566. GM_addStyle(".chat-gpt-container{width: 70vw}");
  567. const container2 = getContainer();
  568. const mainBarContainer = document.querySelector("main");
  569. mainBarContainer.prepend(container2);
  570. }
  571. }
  572. function baiduInjectContainer() {
  573. if (getPosition() === 1) {
  574. const container2 = getContainer();
  575. const siderbarContainer = document.getElementById("content_right");
  576. siderbarContainer.prepend(container2);
  577. } else {
  578. GM_addStyle(".chat-gpt-container{max-width: 100%!important}");
  579. const container2 = getContainer();
  580. const siderbarContainer = document.querySelector("#content_left");
  581. siderbarContainer.prepend(container2);
  582. }
  583. }
  584. function duckduckgoInjectContainer() {
  585. const container2 = getContainer();
  586. const siderbarContainer = document.getElementsByClassName("results--sidebar")[0];
  587. siderbarContainer.prepend(container2);
  588. }
  589. function deeplInjectContainer() {
  590. const container2 = getContainer();
  591. container2.style.maxWidth = "1000px";
  592. const button = document.createElement("button");
  593. button.innerHTML = i18n("chatGPTTranslate");
  594. button.className = "chat-gpt-translate-button";
  595. document.getElementsByClassName("lmt__textarea_container")[0].appendChild(button);
  596. button.addEventListener("click", function() {
  597. initContainer();
  598. button.disabled = true;
  599. try {
  600. document.getElementsByClassName("lmt__raise_alternatives_placement")[0].insertBefore(container2, document.getElementsByClassName("lmt__translations_as_text")[0]);
  601. } catch {
  602. document.getElementsByClassName("lmt__textarea_container")[1].insertBefore(container2, document.getElementsByClassName("lmt__translations_as_text")[0]);
  603. }
  604. let outlang = document.querySelectorAll("strong[data-testid='deepl-ui-tooltip-target']")[0].innerHTML;
  605. let question = "Translate the following paragraph into " + outlang + " and only " + outlang + "\n\n" + document.getElementById("source-dummydiv").innerHTML;
  606. getAnswer(question, (t) => {
  607. button.disabled = false;
  608. });
  609. });
  610. }
  611. }
  612. function initMenu() {
  613. let position_id = GM_registerMenuCommand(i18n("containerPosition") + getPosition(), position_switch, "M");
  614. function position_switch() {
  615. GM_unregisterMenuCommand(position_id);
  616. setPosition((getPosition() + 1) % 2);
  617. position_id = GM_registerMenuCommand(i18n("containerPosition") + getPosition(), position_switch, "M");
  618. location.reload();
  619. }
  620. }
  621. async function main() {
  622. initUI();
  623. initMenu();
  624. if (getWebsite().type === "immediately") {
  625. getAnswer(getQuestion());
  626. }
  627. }
  628. main().catch((e) => {
  629. console.error(e);
  630. });
  631. })();

QingJ © 2025

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