Google Forms Helper

Aids to solve google forms

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

// ==UserScript==
// @name         Google Forms Helper
// @namespace    https://github.com
// @version      0.1
// @description  Aids to solve google forms
// @author       erucix
// @match        https://docs.google.com/forms/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const searchURL = "https://google.com/search?q=";
const container = document.querySelectorAll(".geS5n");

container.forEach((element, index) => {
    let questionContainer = element.querySelector(".z12JJ");
    let answersContainer = element.querySelectorAll(".nWQGrd");
    let options = "";
    let question = questionContainer.textContent;


    answersContainer.forEach((points) => {
        options += points.textContent + " \n";
    });

    let spanElement = document.createElement("span");

    spanElement.innerHTML = `
    <a href='${searchURL + question + options}' class="searchText" style="text-decoration:none;font-weight:bold;cursor:pointer;">SEARCH</a>
    &nbsp;&nbsp;&nbsp;
    <a class="copyText" style="text-decoration:none;font-weight:bold;cursor:pointer;transition:.3s">COPY</a>
    `;

    questionContainer.appendChild(spanElement);

    let copyButton = questionContainer.querySelector(".copyText");

    copyButton.addEventListener("click", function () {
        navigator.clipboard.writeText(question + "\n" + options);
        copyButton.innerText = "Copied";

        setTimeout(function(){
              copyButton.innerText = "Copy";
        },5000);
    });

    let anotherSpan = document.createElement("span");
    anotherSpan.innerHTML += `<br><div class="chatAnswer" style="border-radius:8px;padding:8px;background-color:#ADD8E6">
                    <p style="font-weight:bold;">GoogleAI Answer:</p>
                    <hr style="border: 1px solid black">
                    <p id="chatGPTAnswer">
                    Waiting for answer...
                    </p>
                    </span>
                    <br>
                    </div>`;
    element.appendChild(anotherSpan);
});


var a = document.querySelectorAll(".geS5n");

a.forEach((element)=>{
    let questionContainer = element.querySelector(".z12JJ");
    let answersContainer = element.querySelectorAll(".nWQGrd");
    let options = "";
    let question = questionContainer.textContent;


    answersContainer.forEach((points) => {
        options += points.textContent + " \n";
    });

    fetch("https://generativelanguage.googleapis.com/v1beta3/models/text-bison-001:generateText?key=AIzaSyC_Z67CTkUzwhybPrPexMqxIdvL7F3xhM0", {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            prompt: {
                text: "Which of the following option is correct for this question?\n" + question.replace("COPY", "").replace("SEARCH", "") + "\n" + options,
            },
        }),
    })
        .then(response => response.json())
        .then(data => {
            element.querySelector("#chatGPTAnswer").innerText = data.candidates[0].output;
        })
        .catch(error => {
            element.querySelector("#chatGPTAnswer").innerText = "Failed to fetch answer.";
        });
})
})();