How ccu-class/homework2calendar works
The project “Moodle to Google Calendar Extension” is a Chrome/Edge browser extension that helps students export Moodle (eCourse2) calendar events to Google Calendar. Its purpose is to provide a convenient one-click solution to either download a .ics calendar file or directly update Google Calendar with events, streamlining the management of academic deadlines.
Main Components
• Chrome Extension Components: Since this is a Manifest V3 extension, include components such as:
• Manifest (src/manifest.json): The central configuration that defines extension permissions, background scripts, content scripts, and popup UI.
• Background Script (src/js/background.js): Manages persistent tasks, event listeners, and communication between components.
• Content Scripts (src/js/content.js, src/js/calendar.js, etc.): Injected into Moodle pages for harvesting calendar events.
• Popup UI (src/popup.html along with src/js/popup.js): Provides the interface for user interaction (e.g., selecting month/year, triggering export/import).
• Authentication and OAuth: Highlight integration with Google OAuth using chrome.identity and launchWebAuthFlow (src/js/oauth.js).
• Styling and Build Tools: Mention Tailwind CSS (src/css/input.css) for styling, while Vite (vite.config.js) is used as the build tool. ESLint (eslint.config.mjs) and Prettier (.prettierrc) are used for code quality.
• Supporting Scripts: Note additional scripts such as build/deployment scripts (upload.sh, zip_dist.sh) and markdown-to-HTML conversion (scripts/md-to-html.mjs).
Interactions Between Components
• User Action (Popup) → triggers events in popup.js.
• Popup → communicates with background.js (for authentication and data fetching).
• The Content Scripts are injected to extract calendar events from Moodle and then relay these events to either the background script or directly prepare download (.ics) or update Google Calendar.
• The OAuth component (oauth.js) interacts with external Google services:
• Background or Popup script initiates OAuth flow that uses secure communication with Google’s authentication endpoints.
• Build and Packaging:
• Use Vite as the build tool to bundle the extension code.
• That the end result is assembled into a distributable folder (dist/ directory produced after running “npm run build”).
Architectural Patterns and Design Principles
• Modular Structure: Code is organized into separate directories – JS logic (src/js), CSS styling (src/css) – representing clean separation of concerns.
• Event-Driven Communication: Use of background messaging and events to coordinate among popup, content scripts, and OAuth handling.
• Declarative Configuration: The manifest defines extension components, permissions, and resource locations.
• Developer Tooling: Incorporate development practices like linting and code formatting (via ESLint and Prettier).
Additional Details
• That deployment and build steps are captured even though they are developer-focused (represented by the configuration files like vite.config.js, tailwind.config.js, and GitHub Actions workflows in .github/workflows).
• Clear separation between user interface (Popup) and the extension’s processing logic (background and content scripts), which is central to the design.
• That the privacy and security aspects are important (the extension only accesses data upon user action, limited Google OAuth permissions).