Simple ChatGPT

Press the shortcut "Ctrl+Q" to ask ChatGPT a question, and an alert box will return in your browser

  1. // ==UserScript==
  2. // @name Simple ChatGPT
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-02-15
  5. // @description Press the shortcut "Ctrl+Q" to ask ChatGPT a question, and an alert box will return in your browser
  6. // @description:ja ショートカット「Ctrl+Q」を押してChatGPTに質問すると、ブラウザに警告ボックスが表示されます。
  7. // @description:zh 按快捷键“Ctrl+Q”向 ChatGPT 提问,浏览器中将返回一个警告框
  8. // @description:fr Appuyez sur le raccourci "Ctrl+Q" pour poser une question à ChatGPT et une boîte d'alerte reviendra dans votre navigateur
  9. // @description:cs Stisknutím zkratky „Ctrl+Q“ položíte ChatGPT otázku a ve vašem prohlížeči se vrátí varovné pole
  10. // @description:es Presione el acceso directo "Ctrl+Q" para hacerle una pregunta a ChatGPT y aparecerá un cuadro de alerta en su navegador.
  11. // @description:pt Aperte o atalho "Ctrl+Q" para fazer uma pergunta ao ChatGPT, e retornara uma caixa de alerta no neu navegador
  12. // @description:pt-Br Aperte o atalho "Ctrl+Q" para fazer uma pergunta ao ChatGPT, e retornara uma caixa de alerta no neu navegador
  13. // @description:pt-PT Aperte o atalho "Ctrl+Q" para fazer uma pergunta ao ChatGPT, e retornara uma caixa de alerta no neu navegador
  14. // @author Pedro Henrique
  15. // @match *://*/*
  16. // @icon https://www.google.com/s2/favicons?sz=64&domain=greasyfork.org
  17. // @grant GM_xmlhttpRequest
  18. // @license MIT
  19. // ==/UserScript==
  20.  
  21. (function() {
  22. 'use strict';
  23. document.onkeyup = (event) => {
  24. if (event.ctrlKey == true && event.key.toLowerCase() == "q")
  25. {
  26. let prompt = window.prompt("Write the question:");
  27. if (prompt == null || prompt == "") // Caso o prompt for null ou cancelado
  28. return;
  29. let _data = { // Informações
  30. "type": "chat",
  31. "messagesHistory": [
  32. {
  33. "id": "",
  34. "from": "you",
  35. "content": prompt
  36. }
  37. ]
  38. }
  39. // Faz a solicitação
  40. GM_xmlhttpRequest({
  41. method: "POST",
  42. url: 'https://talkai.info/pt/chat/send/',
  43. data: JSON.stringify(_data),
  44. headers: {"Content-type": "text/plain; charset=UTF-16"},
  45. onload: (ev) => {
  46. // Decifra o Texto Retornado
  47. let _texto = decifrarTexto(ev.responseText);
  48. // Mostra a resposta na caixa de alerta
  49. alert(_texto.replace(/(\\r)|(\\n)/g,"\n"));
  50. },
  51. onerror: (er) => {
  52. alert("-- Error: There was no response from the API, please try again later");
  53. throw "Error returning ChatGPT response";
  54. }
  55. });
  56. function decifrarTexto(data) {
  57. // Divide o texto
  58. const linhas = data.split("data: ").map((i) => {return i.slice(0,-2)})
  59. // Remove as ultimas linhas inuteis
  60. linhas.pop();linhas.pop();
  61. // Retorna o texto
  62. return linhas.join("");
  63. }
  64. }
  65. };
  66. })();