TutorMe By U.K - Mathspace Helper

Free mathematics learning companion for Mathspace

目前为 2025-02-15 提交的版本。查看 最新版本

// ==UserScript==
// @name         TutorMe By U.K - Mathspace Helper
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Free mathematics learning companion for Mathspace
// @author       U.K
// @match        https://*.mathspace.co/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Styles for our UI
    const styles = `
        .tutorme-panel {
            position: fixed;
            right: 20px;
            top: 20px;
            background: white;
            padding: 15px;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            z-index: 10000;
            width: 300px;
            font-family: Inter, system-ui, sans-serif;
        }
        .tutorme-button {
            background: #34D399;
            color: white;
            border: none;
            padding: 8px 16px;
            border-radius: 4px;
            cursor: pointer;
            width: 100%;
            margin-top: 10px;
            font-weight: 500;
        }
        .tutorme-button:hover {
            background: #2EBE8A;
        }
        .tutorme-solution {
            margin-top: 15px;
            padding: 10px;
            background: #f8f9fa;
            border-radius: 4px;
            white-space: pre-wrap;
        }
        .tutorme-input {
            width: 100%;
            padding: 8px;
            border: 1px solid #e2e8f0;
            border-radius: 4px;
            margin-bottom: 10px;
        }
        .tutorme-calculator {
            margin-top: 15px;
            padding: 10px;
            background: #f8f9fa;
            border-radius: 4px;
        }
        .tutorme-calculator input {
            width: 70%;
            padding: 8px;
            border: 1px solid #e2e8f0;
            border-radius: 4px;
            margin-right: 10px;
        }
        .tutorme-calculator button {
            width: 25%;
        }
    `;

    // Add styles to document
    const styleSheet = document.createElement("style");
    styleSheet.textContent = styles;
    document.head.appendChild(styleSheet);

    // Create UI panel
    const panel = document.createElement('div');
    panel.className = 'tutorme-panel';
    panel.innerHTML = `
        <h3 style="margin: 0 0 10px 0; font-weight: 600;">TutorMe By U.K</h3>
        <div id="current-question" style="min-height: 50px; background: #f8f9fa; padding: 8px; border-radius: 4px; margin-bottom: 10px; cursor: pointer">
            <input type="text" class="tutorme-input" placeholder="Click here to type your question..." style="display: none;">
            <span class="question-text">Waiting for question...</span>
        </div>
        <div id="calculator" class="tutorme-calculator" style="display: none;">
            <input type="text" placeholder="Enter expression (e.g., 2 + 2)">
            <button class="tutorme-button" style="width: auto;">Calculate</button>
            <div id="calc-result" style="margin-top: 10px;"></div>
        </div>
        <button id="analyze-btn" class="tutorme-button">Analyze Question</button>
        <div id="solution" class="tutorme-solution" style="display: none;"></div>
    `;

    document.body.appendChild(panel);

    // Make panel draggable
    let isDragging = false;
    let currentX;
    let currentY;
    let initialX;
    let initialY;
    let xOffset = 0;
    let yOffset = 0;

    panel.addEventListener("mousedown", dragStart);
    document.addEventListener("mousemove", drag);
    document.addEventListener("mouseup", dragEnd);

    function dragStart(e) {
        initialX = e.clientX - xOffset;
        initialY = e.clientY - yOffset;

        if (e.target === panel) {
            isDragging = true;
        }
    }

    function drag(e) {
        if (isDragging) {
            e.preventDefault();
            currentX = e.clientX - initialX;
            currentY = e.clientY - initialY;

            xOffset = currentX;
            yOffset = currentY;

            setTranslate(currentX, currentY, panel);
        }
    }

    function setTranslate(xPos, yPos, el) {
        el.style.transform = `translate3d(${xPos}px, ${yPos}px, 0)`;
    }

    function dragEnd(e) {
        initialX = currentX;
        initialY = currentY;
        isDragging = false;
    }

    // Question detection and interaction logic
    const analyzeBtn = document.getElementById('analyze-btn');
    const questionDiv = document.getElementById('current-question');
    const questionText = questionDiv.querySelector('.question-text');
    const questionInput = questionDiv.querySelector('input');
    const solutionDiv = document.getElementById('solution');
    const calculator = document.getElementById('calculator');
    const calcInput = calculator.querySelector('input');
    const calcButton = calculator.querySelector('button');
    const calcResult = document.getElementById('calc-result');

    // Toggle calculator and input field
    questionDiv.addEventListener('click', () => {
        if (questionText.textContent === 'Waiting for question...') {
            questionText.style.display = 'none';
            questionInput.style.display = 'block';
            calculator.style.display = 'block';
        }
    });

    // Handle calculator
    calcButton.addEventListener('click', () => {
        try {
            const result = new Function('return ' + calcInput.value)();
            calcResult.textContent = `Result: ${result}`;
        } catch (error) {
            calcResult.textContent = 'Error: Invalid expression';
        }
    });

    // Handle question input
    questionInput.addEventListener('change', (e) => {
        questionText.textContent = e.target.value;
        questionText.style.display = 'block';
        questionInput.style.display = 'none';
    });

    // Monitor for question changes
    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            if (mutation.type === 'childList') {
                const questionElements = document.querySelectorAll('.question-text, .problem-text');
                if (questionElements.length > 0) {
                    const question = questionElements[0].textContent;
                    questionText.textContent = question;
                }
            }
        });
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    analyzeBtn.addEventListener('click', async () => {
        const question = questionText.textContent;
        if (question === 'Waiting for question...') return;

        analyzeBtn.textContent = 'Analyzing...';
        analyzeBtn.disabled = true;

        try {
            // Simulate analysis (replace with actual implementation)
            await new Promise(resolve => setTimeout(resolve, 1500));
            
            solutionDiv.style.display = 'block';
            solutionDiv.textContent = `Step 1: Read and understand the problem
Step 2: Identify key information
Step 3: Choose appropriate method
Step 4: Solve step by step
Step 5: Verify the answer`;
        } catch (error) {
            solutionDiv.textContent = "Error analyzing question. Please try again.";
        } finally {
            analyzeBtn.textContent = 'Analyze Question';
            analyzeBtn.disabled = false;
        }
    });
})();


QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址