How cm090/rhitweaks works
Project Type and Purpose
• This project is a browser extension (specifically for Chromium, with some Firefox compatibility files present) aimed at modifying and enhancing the user experience on RHIT websites.
• The functionality is split across various content injection points (such as banners, moodle modifications, print components, and schedule adjustments) and a user interface provided by a popup.
File Structure
• Top-level configuration and tooling files (e.g., package.json, rollup.config.js, tsconfig.json, .eslintrc.js, and .prettierrc.yaml) indicate a well-organized, modern JavaScript/TypeScript project.
• The “src” directory houses the core source code:
• The background script (src/background.ts) handles long-running processes and messaging.
• The “content” subdirectory contains subdirectories (banner, moodle, print, schedule, common) that house content scripts, HTML templates, CSS, and modular TypeScript files corresponding to different webpage enhancements.
• The “pages” subdirectory (especially under src/pages/popup) holds React components and supporting files for the extension’s popup UI.
• The “compatibility” folder contains modifications and manifest files supporting Firefox, underscoring cross-browser considerations.
• This structure shows a clear separation of concerns: background processes, injected content scripts for DOM manipulation/enhancement, and a standalone UI layer for settings and user interaction.
README File for Additional Insights
• The README confirms the project is a Chromium extension (with linkage to Chrome Web Store) and provides steps for development, implying active preparation for live development and build processes.
• It references this extension as the successor to a previous project, hinting at iterative improvements and maintained codebases.
a. Main Components to Include:
• Extension Core:
• Manifest (src/manifest.json) that defines the extension, permissions, and initialization scripts.
• Background Script (src/background.ts) that manages event handlers and interprocess communication.
• Content Scripts:
• Banner Scripts (src/content/banner/*): Modules, HTML, and CSS that dynamically modify banner elements on targeted pages.
• Moodle Tweaks (src/content/moodle/*): Scripts and modules that inject enhancements into Moodle pages, including UI components like buttons and search modals.
• Print Enhancements (src/content/print/*): Code that controls modifications on print-related pages.
• Schedule Adjustments (src/content/schedule/*): Scripts that reformat or enhance schedule displays.
• Shared/Utility Modules (within src/content/common and other common files such as src/defaults.ts) for data and configuration used across various injections.
• Popup UI:
• React-based popup components (src/pages/popup/components/*) including settings pages and dialogs that let the user configure which tweaks are active.
• The popup’s main page (src/pages/popup/index.tsx and its associated index.html and styles.css).
• Build/Tooling Components:
• Build configuration (rollup.config.js) and dependency management (package.json) that tie the project together.
• Linting and formatting configurations (.eslintrc.js, .prettierrc.yaml).
b. Relationships and Interactions:
• The extension manifest directs the browser to load the background script and inject specific content scripts into web pages based on URL matching rules.
• Background processes may communicate (using message passing APIs) with both the popup UI for settings and with content scripts to manage dynamic behavior.
• The React popup provides a front-end interface for configuration settings, which can influence the behavior of the content scripts.
• Modular content scripts (grouped by functionality such as banner, moodle, print, and schedule) interact directly with the web page’s DOM to implement the tweaks.
c. Architectural Patterns & Design Principles:
• Modular decomposition: Each enhancement (banner, moodle, print, schedule) is broken into its own directory with clearly defined modules.
• Separation of concerns: Distinct layers separate background processes (logic and messaging), content script injections (DOM manipulation), and UI presentation (React-based popup).
• Configuration-driven build and lint processes support maintainability and code quality.
• Cross-browser compatibility is addressed by having a designated folder (compatibility) for Firefox-specific changes.
d. Technologies, Frameworks, and Libraries:
• TypeScript is used throughout for robust type safety.
• React is used for building the popup UI.
• Rollup is used as the module bundler.
• Standard development tools: ESLint, Prettier, and npm scripts for build and development.
• Chromium extension APIs as defined in the manifest file.
Final Advice
• Be as detailed as possible. Don’t hesitate to break down umbrella components (like “Content Scripts”) into their individual submodules, showing the relationships between general-purpose modules (like shared utilities) and feature-specific modules.