source-code/
snakey
Public
codeCodeinfoIssues 0call_splitPull Requestsplay_circleActions
andreyyste
andreyysterefactor: implement localized DOM registry, debounce resize event, centralize constants, and resolve type compiler errors
ccdc03d8 days agohistory52 Commits
folderpublic
fix: update web game's DomScanner to allow eating tall/wide content cards
11 days ago
folderscripts
refactor(game): address codebase issues, improve React-Phaser score decoupling, resize layout calculations, and trailing queued segment growth
8 days ago
foldersrc
Change coverImage URL in .portfolio.json
13 days ago
description.gitignore
design: complete visual redesign of the web game website with glassmorphism layout
8 days ago
description.portfolio.json
fix: bypass react javascript url security block using DOM ref in footer
12 days ago
descriptioneslint.config.js
refactor: implement localized DOM registry, debounce resize event, centralize constants, and resolve type compiler errors
8 days ago
descriptionindex.html
Change coverImage URL in .portfolio.json
13 days ago
feat: add extension download buttons and detailed installation instructions
11 days ago
descriptionpackage.json
fix: update web game's DomScanner to allow eating tall/wide content cards
11 days ago
descriptionREADME.md
fix: bypass react javascript url security block using DOM ref in footer
12 days ago
chore: add id attributes to bookmarklet and extension sections in Footer
8 days ago
descriptiontsconfig.json
Update liveUrl in .portfolio.json
13 days ago
Update liveUrl in .portfolio.json
13 days ago
descriptionvite.config.ts
build: compile and package updated bookmarklet and extensions containing refactored codebase fixes
8 days ago
README.md

🐍 Snakey - Escape The Matrix

Live Demo

A modern twist on the classic Snake game, built with React 19, Vite, Tailwind CSS, and Phaser 3.

What starts as a simple, confined 800x600 arcade game quickly turns into an interactive web-breaking experience where the snake breaks out of its canvas and consumes the actual DOM elements of the website.


✨ Features

  • Classic Gameplay: A polished retro snake experience with smooth grid-based movement and responsive controls.
  • Escape Mode: Upon reaching a score of 100, the mysterious Red Pill appears. Eating it shatters the boundaries of the canvas, allowing the snake to roam freely across the entire webpage.
  • Universal DOM Eating Sandbox: Fully decoupled from local stylesheets and static class configurations. The snake can crawl on any website (e.g., Wikipedia, Google, blogs) and physically consume HTML elements (text, dropdowns, inputs, progress indicators, media, and cards) with dynamic visual card background extraction.
  • Dynamic Content Support: Relies on a reactive observer that immediately adapts when new elements are injected or loaded dynamically (e.g. lazy-loaded content, scrolls).
  • Cinematic Viewport Finale: Once you're done eating elements, crash the snake into any edge of the browser viewport to trigger a dramatic end-game sequence where the website collapses, folds, and falls off the screen, leaving a pitch-black void before resetting.

🧠 The DOM Destruction Engine (Architecture)

The heart of Snakey is its custom DOM parser and rendering pipeline, built to bridge the gap between Phaser's WebGL/Canvas game loops and the browser's Document Object Model (DOM).

                 [ Phaser Game Loop ]
                          │
            Detects head coordinate overlap
                          │
                          ▼
                    [ DomManager ]
             Orchestrates & tracks state
             │            │            │
      Scans dynamic       │      Triggers anims
      DOM updates         │      upon chomps
             │            │            │
             ▼            ▼            ▼
       [ DomScanner ]  [ Physics ]  [ DomAnimator ]
      Recurses shadow  Synchronizes  Applies tag-specific
       DOM / elements   rect bounds  CSS & pseudo transitions

🔍 1. DomScanner (The Parser)

The DomScanner acts as the parser. It crawls the webpage DOM and generates target coordinate bodies for Phaser.

  • Recursive Tree Walking: Walks the DOM tree node-by-node. If it finds text nodes, it safely splits them character-by-character and wraps them inside individual .edible-char spans to allow letter-by-letter consumption.
  • Shadow DOM Traversal: Recursively traverses shadow roots (shadowRoot), unlocking the ability to scan inside custom Web Components and embedded widgets.
  • Computed Visibility Filtering: Checks computed style values (window.getComputedStyle) to ignore elements hidden via display: none, visibility: hidden, or opacity: 0.
  • Phaser Canvas Excluder: Automatically identifies the Phaser game canvas and prevents the snake from eating the container rendering the game.
  • Multi-Element Mapping: Targets a wide array of tags: img, svg, video, input, textarea, button, a, select, progress, meter, canvas, hr, iframe, and audio.
  • Universal Card Detection: Dynamically identifies card-like block layouts on any webpage using style-based heuristics (backgrounds, borders, shadows, and dimensions) rather than static class name checks.

⚙️ 2. DomManager (The Orchestrator)

The DomManager acts as the main bridge keeping state and listening to browser viewport changes.

  • Dynamic Mutation Observer: Integrates a MutationObserver to watch for dynamically added elements (lazy-loaded elements, infinite scrolling) and triggers rescans safely by temporarily disconnecting/connecting to prevent infinite loops.
  • Viewport Scroll-Aware Bounds: Keeps snake movement bound within the current viewport (window.scrollX / window.scrollY limits), allowing the snake to feel like it scrolls dynamically with the page.
  • Collision Syncing: Compares Phaser's head coordinates to domBodies coordinates (updated dynamically on resize/scroll) and flags them in memory.
  • Canvas Lifecycle Restoration: When the game restarts, it completely restores the Phaser canvas back to its original layout container (#game-container-shell), strips off full-screen fixed styling, resets the scale resolution back to 800x600, and cleans up observers.

🎨 3. DomAnimator (The Animator)

The DomAnimator triggers specific transitions on HTML elements when eaten by the snake:

  • select (Dropdown): Dynamically expands the dropdown option list (select.size) for 300ms, simulating a visual dropdown click, before chomping and shrinking.
  • hr (Horizontal Line): Scales horizontally down (scaleX(0)) to center before fading.
  • progress / meter: Animates the value bar draining down to 0 over 200ms before scaling to 0.
  • input[type=checkbox] / input[type=radio]: Triggers a rapid click toggle (6 times at 50ms interval) to simulate click madness before disappearing.
  • input / textarea: Shakes horizontally (vibration effect) for 400ms before spinning and shrinking.
  • audio / video: Instantly speeds up playback rate to 3.0x and fades out audio volume to 0 (if playing) before pausing and shrinking.
  • Universal Card Chomping: Lazily clones any card's computed styles (shadow, border, background, border-radius) onto an absolutely positioned dynamic background wrapper div (.dynamic-card-bg), hides the original card background, and scales the wrapper to 0. This allows card backgrounds to crumble on any website while keeping inner text intact and edible.
  • Descendant Cleanup: Automatically marks all children of eaten elements as eaten to avoid leaving "ghost" collider blocks.

🚀 Getting Started

Prerequisites

Make sure you have Node.js installed on your machine.

Installation

  1. Clone the repository

    git clone https://github.com/andreyyste/snakey.git
    cd snakey
    
  2. Install dependencies

    npm install
    
  3. Start the development server

    npm run dev
    
  4. Play! Open http://localhost:5173 in your browser. Use the Arrow Keys or WASD to control the snake.


🛠️ Built With


📜 License

This project is open-source and available under the MIT License.

warningDESIGN PHILOSOPHY
  • Containment: Every element lives within a rigid bounding box. No floating content.
  • Contrast: High contrast borders (#1e1b19) are mandatory. 3px standard, 6px heavy.
  • Depth: Hard solid shadows. No blur. Physical displacement on interaction.

LIVE PRODUCTION DEMO

Experience the rigid geometry in real-time.

REBEL

About

Snakey Web Game is the official hub and sandbox playground for the Snakey project. Built with React 19, Phaser 3, and Tailwind CSS, it offers a central playable zone alongside a Sandbox Playground that lets visitors test eating custom HTML elements. It also hosts and serves self-compiled browser extension packages (ZIP) for Chrome and Firefox, as well as a dynamically-generated bookmarklet installer that enables users to drag-and-drop a shortcut to run the game on any external website.

Web GamePhaserReactTypeScriptTailwind CSSViteBookmarklet

Contributors

1