MOOC Utils

Utils like auto assignment solver extension and course notice announcment notification for MOOC courses

Assignment solver extension

Introduction#

Assignment Solver is a Chrome and Firefox extension that helps with online assignments through Google’s Gemini API. Study Hints mode gives guidance without filling forms. Auto-Solve can apply answers. It handles single-choice, multi-choice, fill-in-the-blank, and image questions, keeps your API key on the device, and talks to Gemini from the client.

Project structure#

The extension is organized into modular layers:

  • background: Service worker with message routing and platform adapters
  • content: Content script for DOM extraction and answer application
  • ui: Side panel UI with controllers, state, and settings
  • core: Shared messaging, logging, and type utilities
  • platform: Unified adapters for browser APIs (runtime, storage, tabs, scripting, panel)
  • services: Business logic (Gemini integration, local storage)
  • public: Static assets (side panel HTML/CSS/icons)

Core components#

  • Dual-mode operation:
  • Study Hints: Retrieve AI guidance without applying answers
  • Auto-Solve: Extract, analyze, apply answers, and optionally auto-submit
  • Supported question types:
  • Single-choice (radio)
  • Multi-choice (checkbox)
  • Fill-in-the-blank (text/textarea)
  • Image-based (embedded images and full-page screenshots)
  • Privacy-first design:
  • API key stored locally via browser storage
  • All processing occurs client-side or via official Gemini API
  • Cross-browser compatibility:
  • Uses webextension-polyfill
  • Dynamic manifest differences for Chrome (side_panel) and Firefox (sidebar_action)

Architecture overview#

The extension follows a layered architecture:

  • UI (Side Panel) communicates with background worker via typed messages
  • Background worker orchestrates content script interactions and Gemini API calls
  • Content script extracts page data, applies answers, and submits forms
  • Platform adapters abstract browser-specific APIs behind a unified interface

Detailed component analysis#

Background service worker#

Responsibilities:

  • Initialize platform adapters and services
  • Register message handlers for extraction, screenshots, Gemini requests, answer application, and submission
  • Route messages to appropriate handlers
  • Open side panel on icon click

Key behaviors:

  • Uses a message router to dispatch to handlers based on message type
  • Relays Gemini debug payloads to the content script for visibility
  • Waits for content script readiness before applying answers

Content script#

Responsibilities:

  • Extract page HTML and images
  • Provide scroll info and scrolling control for screenshot capture
  • Apply answers to the page (radio, checkbox, text input)
  • Submit assignments
  • Relay debug logs to the page console

Implementation highlights:

  • Uses a switch-based message listener to respond to UI commands
  • Extracts images with base64 conversion and metadata
  • Applies answers with synthetic events to trigger change/input handlers

Side panel UI#

Responsibilities:

  • Initialize UI, controllers, state, and storage
  • Wait for background readiness (with retry/backoff)
  • Drive the solve workflow: extract, solve, apply, submit
  • Present results and manage settings

Key features:

  • Progress tracking with steps (extract, analyze, fill, submit)
  • Results display with confidence and AI reasoning
  • Settings modal for API key and model preferences
  • Automatic background readiness checks for Firefox

Gemini service#

Responsibilities:

  • Construct prompts and payloads for extraction and solving
  • Manage thinking budgets and reasoning levels
  • Call Gemini API directly from background or via message channel
  • Parse responses and handle token limit retries

Notable capabilities:

  • Supports multiple models and reasoning levels
  • Embeds full-page screenshots and embedded images
  • Implements recursive splitting to handle MAX_TOKENS errors

Message passing system#

  • Centralized message types define UI-to-background and content-script interactions
  • Retry logic with exponential backoff for transient connection failures
  • Dedicated debug relay to surface AI payloads in the page console

Platform abstraction layer#

  • Unified browser detection and API access
  • Runtime adapter for messaging
  • Storage adapter for local persistence
  • Optional API checks for side panel availability

Dependency analysis#

  • Build and packaging:
  • Vite builds separate bundles for background, content script, and UI
  • Scripts support watch mode for both Chrome and Firefox
  • Manifest differences:
  • Chrome uses side_panel; Firefox uses sidebar_action
  • Host permissions include Google Generative Language API domain
  • Cross-browser compatibility:
  • webextension-polyfill keeps consistent APIs
  • Optional API checks prevent runtime errors on missing features

Performance considerations#

  • Rate limiting:
  • 500 ms delay between answer applications
  • 200 ms delay between DOM operations
  • Token handling:
  • Recursive splitting of HTML and question sets to avoid MAX_TOKENS
  • Network resilience:
  • Retry logic with backoff for background communication
  • Model selection:
  • Choose models aligned with free tier limits and stability

Troubleshooting guide#

Common issues and resolutions:

  • Could not get page HTML:
  • Ensure you are on a real assignment page and fully loaded
  • Refresh and re-extract
  • Question container not found:
  • Re-extract; verify selectors match the platform
  • Check console for detailed error info
  • API Key invalid:
  • Verify key at Google AI Studio
  • Ensure Gemini access is enabled
  • Check for extra spaces when pasting
  • Answers not being applied:
  • Some platforms use custom components
  • Inspect console for errors
  • Apply answers individually to isolate issues
  • Rate limit errors:
  • Wait before retrying
  • Upgrade quota or reduce concurrent questions

Conclusion#

Client-side Gemini calls, two modes, and structured prompts. Submit the form yourself after Auto-Solve unless you have verified the page selectors.

Appendices#

Installation and setup#

  • Clone and install dependencies
  • Build for Chrome or Firefox
  • Load the extension in developer mode
  • Configure your Gemini API key in the side panel settings

Supported question types#

  • Single Choice: Clicks the correct radio option
  • Multi Choice: Checks all correct options, unchecks wrong ones
  • Fill-in-the-Blank: Types the answer and triggers input events

Configuration options#

  • API Key Storage: Local browser storage via polyfill
  • Model Selection: Choose extraction and solving models
  • Reasoning Levels: Configure reasoning budgets per model family
  • Auto-submit: Toggle automatic submission after filling

Usage examples#

  • Basic Workflow:
  • Navigate to an assignment page
  • Open the side panel and click “Solve Assignment”
  • Review results and confirm auto-submit if enabled
  • Manual Mode:
  • Extract questions
  • Get hints, select answers, and apply one by one
  • Submit manually when finished