MOOC Utils

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

Applicator system

Introduction#

Writes AI answers into page form elements. DOM techniques, validation, submit flows, and what happens when a control does not match the expected shape.

Project structure#

The applicator system spans three layers:

  • Content script: Applies answers and submits forms on the target page
  • Background service worker: Routes messages and manages content script lifecycle
  • UI controllers: Drive the full flow, including progress reporting and user controls

Core components#

  • Applicator service: Applies answers to radio buttons, checkboxes, and text inputs; triggers form submission
  • Content script: Receives messages, initializes applicator, and forwards requests
  • Answer handler: Ensures content script is loaded and relays messages to it
  • UI controllers: Orchestrate extraction, solving, filling, and submission with progress feedback

Key responsibilities:

  • Answer application: Single choice, multi choice, and fill-in-the-blank
  • Form submission: Clicks submit button and handles confirmation dialogs
  • User interaction simulation: Dispatches change/input events and keyboard events
  • Error handling: Graceful logging and recovery for missing elements or invalid data

Architecture overview#

The applicator participates in a multi-step assignment-solving workflow:

  1. UI triggers extraction and solving
  2. Background routes messages to content script
  3. Content script applies answers and optionally submits
  4. UI updates progress and displays results

Detailed component analysis#

Applicator service#

The applicator encapsulates answer application and submission logic:

  • applyAnswers: Iterates through AI-generated answers and delegates by question type
  • applySingleChoice: Finds radio inputs by ID/value/name/partial ID and clicks/selects
  • applyMultiChoice: Handles multiple selections across checkbox groups
  • applyFillBlank: Sets text values and simulates user input via events
  • submitAssignment: Locates submit button by multiple strategies and triggers click

DOM manipulation techniques:

  • Element selection via getElementById, querySelector, and querySelectorAll
  • Programmatic clicking and event dispatching for change/input/keyup
  • Value assignment for text inputs and textareas

Validation and error handling:

  • Logs warnings for missing IDs or invalid arrays
  • Gracefully skips elements that cannot be found
  • Wraps per-answer application in try/catch to prevent single failures from stopping the batch

Content script integration#

The content script initializes applicator and exposes message handlers:

  • Listens for APPLY_ANSWERS and SUBMIT_ASSIGNMENT
  • Delegates to applicator and responds with success
  • Provides auxiliary handlers for page info and scrolling

Answer handler and message routing#

The background answer handler checks that the content script is loaded, injects it if needed, then forwards messages:

  • Verifies content script availability via PING
  • Injects content script if missing (with delays for Firefox)
  • Relays APPLY_ANSWERS and SUBMIT_ASSIGNMENT to content script

Submission workflow and user interaction simulation#

Submission involves locating the submit button and triggering a click:

  • Multiple strategies: explicit ID, standard submit button, generic onclick pattern
  • UI feedback: progress controller updates status and step markers
  • Auto-submit toggle: controlled by UI setting

Answer application logic by input type#

Radio buttons (single choice)#

  • Searches by ID, then by value attribute, then by name containing question ID, then by partial ID
  • Clicks the matched radio and dispatches a change event

Checkboxes (multiple choice)#

  • Queries all checkboxes matching the question ID (by name or ID)
  • Compares against expected IDs/values and toggles accordingly
  • Performs additional direct ID/value lookups for each option

Text inputs and text areas (fill in the blank)#

  • Attempts to locate by ID, then by question ID, then by partial ID match
  • Sets the value and dispatches input, change, and keyup events to simulate typing

Form compatibility and mapping examples#

The applicator uses flexible selectors to accommodate different assignment platforms:

  • Radio buttons: ID, value, name containing question ID, partial ID match
  • Checkboxes: name or ID containing question ID; direct ID/value lookups
  • Text inputs: ID, question ID, or partial ID match across input/textarea

These strategies ensure compatibility across NPTEL and similar platforms with varying markup patterns.

Integration with assignment submission process#

The UI orchestrates the full flow:

  • Extracts page data and captures screenshots
  • Sends answers to content script for application
  • Optionally submits automatically based on user preference
  • Updates progress and displays results

Dependency analysis#

The applicator depends on:

  • DOM APIs for element queries and events
  • Cross-browser compatibility via unified browser APIs
  • Message routing for background-to-content communication
  • UI state and progress controllers for user feedback

Performance considerations#

  • Batched application: Answers are sent one at a time with small delays to avoid overwhelming the page
  • Flexible selectors: Reduce re-querying by trying multiple strategies efficiently
  • Event simulation: Minimal synthetic events reduce overhead while so validation triggers
  • Retry logic: UI uses retry mechanisms for background communication to minimize stalls

Troubleshooting guide#

Common issues and resolutions:

  • Content script not loaded: Background handler injects content script and verifies with PING
  • Submit button not found: Applicator tries multiple selectors; UI falls back to defaults
  • Missing answer elements: Applicator logs and continues; UI shows progress and results
  • Cross-browser compatibility: Unified browser API abstraction keeps consistent behavior

Conclusion#

Match question type to the right control, fire the events the page listens for, and skip unknowns instead of guessing.