LiveWorksheets Auto-Magic Solver

Detecta, preenche e salva automaticamente assim que a página carrega

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         LiveWorksheets Auto-Magic Solver
// @namespace    http://tampermonkey.net/
// @version      7.0
// @description  Detecta, preenche e salva automaticamente assim que a página carrega
// @author       User & Gemini
// @match        https://*.liveworksheets.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Função que faz o trabalho sujo
    function solveEverything() {
        if (typeof jQuery === 'undefined' || !jQuery("#worksheet-preview").worksheetPreview) return;

        console.log("🚀 Iniciando preenchimento automático...");

        // 1. Ativa o motor de respostas que você descobriu
        jQuery("#worksheet-preview").worksheetPreview("validation", {
            clicked: true, 
            showAnswers: true, 
            showRightAnswers: true
        });

        // 2. Busca o JSON de respostas
        let answers = [];
        document.querySelectorAll('script[type="application/json"]').forEach(s => {
            try {
                const json = JSON.parse(s.textContent);
                const raw = json?.worksheet?.json || json?.props?.pageProps?.worksheet?.json;
                if (raw) answers = JSON.parse(raw);
            } catch(e) {}
        });

        if (answers.length === 0) return;

        // 3. Preenche e força o salvamento em cada campo
        const elements = document.querySelectorAll('#worksheet-preview-elements > *');
        elements.forEach((el, i) => {
            const data = answers[i];
            if (!data) return;
            const val = data[0];

            if (el.tagName === 'INPUT' || el.hasAttribute('contenteditable')) {
                el.focus();
                if (el.hasAttribute('contenteditable')) el.innerText = val;
                else el.value = val;

                // Dispara os eventos para o site entender que houve digitação real
                ['input', 'change', 'blur', 'keyup'].forEach(evt => {
                    el.dispatchEvent(new Event(evt, { bubbles: true }));
                });
            } 
            else if (el.classList.contains('worksheet-select-div') && val === 'select:yes') {
                if (!el.classList.contains('worksheet-select-div-selected')) {
                    el.click();
                }
            }
        });

        console.log("✅ Tudo preenchido e salvo automaticamente!");
    }

    // Tenta executar a cada 1 segundo até encontrar os elementos
    const autoRun = setInterval(() => {
        const elements = document.querySelectorAll('#worksheet-preview-elements > *');
        if (elements.length > 0 && typeof jQuery !== 'undefined') {
            solveEverything();
            clearInterval(autoRun); // Para de tentar depois que conseguir
        }
    }, 1000);

})();