How ogame-infinity/web-extension works
Project Type and Purpose
• This is a cross-browser (Chrome/Firefox/Edge) extension for the Ogame web game.
• It injects scripts into the Ogame page (content scripts), runs a background process, provides a popup/overview UI, and fetches/analyzes game data (players, planets, alliances, messages).
File Structure
• Top-level:
– manifest.json + manifestv2.json
– background.js (background/service worker)
– packaging.sh, build/config files, docs
• src/ctxcontent: all content-script modules injected into the game page
– callbacks, helpers, services (fetch Ogame data, store, analyze messages)
• src/ctxpage: UI pages loaded in extension popups or tabs (OverviewPage.js, messages analyzer UI, configuration)
• src/util: shared utilities (DOM helpers, data models, storage wrappers, messaging)
• src/assets + src/libs: static TSV data, fonts, images, Chart.js + plugins
• src/main.js & src/ogkush.js: entry points for registering context menus, initializing background listeners, and wiring everything together.
Harvest Insights from the README
• Monolithic JS codebase, uses 3rd-party libs (Chart.js, chartjs-plugin-labels, DOMPurify, lz-string).
• Automated CI/CD via GitHub Actions and packaging.sh.
• No direct local testing (must package to load).
Main Components & Their Roles
a. Manifest
– Declares extension metadata, permissions (webRequest, storage, contextMenus, activeTab), scripts.
b. Background Script (background.js & main.js)
– Central event hub, handles context-menu clicks, message routing between UI and content scripts, persistent storage access, scheduling updates.
c. Content Scripts (ctxcontent/)
– Inject into Ogame pages, scrape game data via XHR/DOM, call services/request.* to fetch alliance/highscore/planet/player data, store/cache via universe.storage, run analyzers on in-game messages.
d. UI Pages (ctxpage/)
– Popup and overview pages, render charts (Chart.js) and tables, consume analysis results, allow user configuration.
e. Services & Analyzers (ctxcontent/services & services/analyzer)
– Low-level request modules to Ogame endpoints, plus analyzers for expeditions, fights, harvests, trades, espionage.
f. Utilities (util/)
– Shared modules for fetching, date/time, DOM manipulation, notifications, internationalization, message passing, local storage abstraction, logging.
g. Assets & Third-Party Libraries
– Fonts, images, static data (expeditions.tsv), Chart.js and plugins, DOMPurify, lz-string.
Relationships & Data Flows
• Background ↔ Content Scripts: chrome.runtime.sendMessage / onMessage
• Content Scripts ↔ Ogame API: XHR/fetch calls in request.* modules
• Content Scripts ↔ Local Storage: universe.storage (caching, expirations)
• UI Pages ↔ Background: for persistent data reads/writes, config options
• Packaging/CD: packaging.sh bundles + minifies all JS and assets.
Architectural Patterns & Design Principles
• Modular separation: content vs. UI vs. background
• Message-driven communication (pub/sub via chrome.runtime)
• Single responsibility: each analyzer/service handles one data type
• Caching & TTL: universe.storage with expirations
• Pluggable charting: Chart.js + plugin architecture
• Strict manifest-driven registration of all components
Final Checklist
• Annotations for third-party libraries and build pipeline.
• Versioning/packaging step illustrated if desired.