CoolFace
Apppublic

helpbot/assignment-buddy

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
script.js123 linesDownload Raw Back to root
1 2// Backend API URL 3const API_URL = 'http://localhost:3000';4// Premium feature flag5let isPremiumUser = false;6 7// Check if user is premium (mock for demo)8function checkPremiumStatus() {9    // In a real app, this would check localStorage or API10    return localStorage.getItem('isPremium') === 'true';11}12// Initialize app13document.addEventListener('DOMContentLoaded', function() {14    console.log('BrainyBytes app initialized');15    isPremiumUser = checkPremiumStatus();16    17    // Initialize all components18    if (window.location.pathname.includes('productivity.html')) {19        // Only initialize timer-related functions on productivity page20        initPomodoroTimer();21    } else {22        initGenerators();23    }24    initPremiumFeatures();25    loadRazorpayScript();26    27    // Update UI based on premium status28    updatePremiumUI();29});30function initGenerators() {31    document.querySelector('#generator button:contains("Generate Assignment")')?.addEventListener('click', generateAssignment);32    document.querySelector('#generator button:contains("Generate Questions")')?.addEventListener('click', generateQuestions);33}34// Form handling35    const loginForm = document.getElementById('loginForm');36    const signupForm = document.getElementById('signupForm');37    38    if (loginForm) {39        loginForm.addEventListener('submit', function(e) {40            e.preventDefault();41            const email = loginForm.querySelector('input[type="email"]').value;42            const password = loginForm.querySelector('input[type="password"]').value;43            44            // Simple validation45            if (email && password) {46                alert('Login successful! Redirecting...');47                window.location.href = 'index.html';48            } else {49                alert('Please fill in all fields');50            }51        });52    }53    54    if (signupForm) {55        signupForm.addEventListener('submit', function(e) {56            e.preventDefault();57            const password = signupForm.querySelectorAll('input[type="password"]')[0].value;58            const confirmPassword = signupForm.querySelectorAll('input[type="password"]')[1].value;59            60            if (password !== confirmPassword) {61                alert('Passwords do not match');62                return;63            }64            65            alert('Account created successfully! Redirecting to login...');66            window.location.href = 'login.html';67        });68    }69});70// Assignment Generation71async function generateAssignment() {72    const topic = document.querySelector('#generator input[placeholder="Enter your topic"]').value;73    const length = document.querySelector('#generator input[type="range"]').value;74    const type = document.querySelector('#generator select').value;75 76    if (!topic) {77        alert('Please enter a topic');78        return;79    }80 81    try {82        const response = await fetch(`${API_URL}/generate-assignment`, {83            method: 'POST',84            headers: {85                'Content-Type': 'application/json',86            },87            body: JSON.stringify({ topic, length, type })88        });89        const data = await response.json();90        document.querySelector('#output-section').innerHTML = `<div class="bg-white p-6 rounded-lg">${data.content}</div>`;91    } catch (error) {92        console.error('Error:', error);93        alert('Failed to generate assignment');94    }95}96 97// Question Generation98async function generateQuestions() {99    const fileInput = document.querySelector('#generator input[type="file"]');100    const questionType = document.querySelectorAll('#generator select')[1].value;101 102    if (!fileInput.files.length) {103        alert('Please upload a file');104        return;105    }106 107    const formData = new FormData();108    formData.append('file', fileInput.files[0]);109    formData.append('type', questionType);110 111    try {112        const response = await fetch(`${API_URL}/generate-questions`, {113            method: 'POST',114            body: formData115        });116        const data = await response.json();117        document.querySelector('#output-section').innerHTML = `<div class="bg-white p-6 rounded-lg">${data.questions.join('<br><br>')}</div>`;118    } catch (error) {119        console.error('Error:', error);120        alert('Failed to generate questions');121    }122}123