A mystical Magic 8-Ball web app โ think your question, shake your phone (or tap the button), and receive your answer from the universe.
๐ฎ Live app โ zhannam85.github.io/magic-ball
- Shake detection โ uses the
DeviceMotionEventAPI on mobile; iOS 13+ asks for permission once, and gracefully falls back to button-only mode if denied - Shake button โ always visible, works on desktop and any device regardless of motion permission
- 20 classic answers โ 10 positive, 5 neutral, 5 negative, colour-coded green / yellow / red
- English & Russian โ auto-detects nothing (Russian is the default); toggle with the EN / RU switcher in the top-right corner, choice is saved across visits
- Smooth animations โ wobble shake, triangle window fade-in, answer text fade-up
- Mobile-first โ optimised for phones, works in all modern browsers
- Capacitor-ready โ structured for a future App Store / Google Play release with minimal changes
| Framework | React 18 + TypeScript (strict) |
| Build tool | Vite 5 |
| i18n | react-i18next + i18next-browser-languagedetector |
| Styling | CSS Modules (no UI library) |
| Hosting | GitHub Pages via GitHub Actions |
| Future mobile | Capacitor (stub committed, ready to add) |
# Install dependencies
npm install
# Start dev server
npm run dev
# Production build
npm run build
# Preview production build locally
npm run previewsrc/
โโโ components/
โ โโโ MagicBall.tsx # The ball visual + shake button
โ โโโ LanguageSwitcher.tsx # EN / RU toggle
โโโ hooks/
โ โโโ useDeviceMotion.ts # Shake detection (Capacitor swap-point)
โโโ data/
โ โโโ answers.ts # 20 classic answers ร 2 languages
โโโ i18n/
โ โโโ index.ts # i18next initialisation
โ โโโ locales/
โ โโโ en.ts # English UI strings
โ โโโ ru.ts # Russian UI strings
โโโ styles/ # CSS Modules
โโโ types/index.ts # Shared TypeScript types
โโโ App.tsx # State machine & orchestration
Every push to main automatically builds and deploys to GitHub Pages via GitHub Actions (.github/workflows/deploy.yml). No manual steps needed.
A capacitor.config.ts stub is already committed. When ready:
npm install @capacitor/core @capacitor/cli @capacitor/ios @capacitor/android
npx cap add ios
npx cap add android
# Build for native (overrides the GitHub Pages base path)
npx vite build --base /
npx cap sync
npx cap open iosTo use native shake detection, replace the DeviceMotionEvent listener in src/hooks/useDeviceMotion.ts with @capacitor/motion.