Google Forms Helper

Aids to solve google forms

目前為 2023-11-18 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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.";
        });
})
})();