Google Forms Helper

Aids to solve google forms

目前为 2023-11-18 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Google Forms Helper
  3. // @namespace https://github.com
  4. // @version 0.1
  5. // @description Aids to solve google forms
  6. // @author erucix
  7. // @match https://docs.google.com/forms/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const searchURL = "https://google.com/search?q=";
  17. const container = document.querySelectorAll(".geS5n");
  18.  
  19. container.forEach((element, index) => {
  20. let questionContainer = element.querySelector(".z12JJ");
  21. let answersContainer = element.querySelectorAll(".nWQGrd");
  22. let options = "";
  23. let question = questionContainer.textContent;
  24.  
  25.  
  26. answersContainer.forEach((points) => {
  27. options += points.textContent + " \n";
  28. });
  29.  
  30. let spanElement = document.createElement("span");
  31.  
  32. spanElement.innerHTML = `
  33. <a href='${searchURL + question + options}' class="searchText" style="text-decoration:none;font-weight:bold;cursor:pointer;">SEARCH</a>
  34. &nbsp;&nbsp;&nbsp;
  35. <a class="copyText" style="text-decoration:none;font-weight:bold;cursor:pointer;transition:.3s">COPY</a>
  36. `;
  37.  
  38. questionContainer.appendChild(spanElement);
  39.  
  40. let copyButton = questionContainer.querySelector(".copyText");
  41.  
  42. copyButton.addEventListener("click", function () {
  43. navigator.clipboard.writeText(question + "\n" + options);
  44. copyButton.innerText = "Copied";
  45.  
  46. setTimeout(function(){
  47. copyButton.innerText = "Copy";
  48. },5000);
  49. });
  50.  
  51. let anotherSpan = document.createElement("span");
  52. anotherSpan.innerHTML += `<br><div class="chatAnswer" style="border-radius:8px;padding:8px;background-color:#ADD8E6">
  53. <p style="font-weight:bold;">GoogleAI Answer:</p>
  54. <hr style="border: 1px solid black">
  55. <p id="chatGPTAnswer">
  56. Waiting for answer...
  57. </p>
  58. </span>
  59. <br>
  60. </div>`;
  61. element.appendChild(anotherSpan);
  62. });
  63.  
  64.  
  65. var a = document.querySelectorAll(".geS5n");
  66.  
  67. a.forEach((element)=>{
  68. let questionContainer = element.querySelector(".z12JJ");
  69. let answersContainer = element.querySelectorAll(".nWQGrd");
  70. let options = "";
  71. let question = questionContainer.textContent;
  72.  
  73.  
  74. answersContainer.forEach((points) => {
  75. options += points.textContent + " \n";
  76. });
  77.  
  78. fetch("https://generativelanguage.googleapis.com/v1beta3/models/text-bison-001:generateText?key=AIzaSyC_Z67CTkUzwhybPrPexMqxIdvL7F3xhM0", {
  79. method: 'POST',
  80. headers: {
  81. 'Content-Type': 'application/json',
  82. },
  83. body: JSON.stringify({
  84. prompt: {
  85. text: "Which of the following option is correct for this question?\n" + question.replace("COPY", "").replace("SEARCH", "") + "\n" + options,
  86. },
  87. }),
  88. })
  89. .then(response => response.json())
  90. .then(data => {
  91. element.querySelector("#chatGPTAnswer").innerText = data.candidates[0].output;
  92. })
  93. .catch(error => {
  94. element.querySelector("#chatGPTAnswer").innerText = "Failed to fetch answer.";
  95. });
  96. })
  97. })();