Count your daily Chating

 <!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

  <title>Mantra Counter</title>

  <style>

    body {

      font-family: sans-serif;

      background-color: #fff7ed;

      color: #000;

      padding: 20px;

      text-align: center;

      transition: all 0.3s ease;

    }

    body.dark {

      background-color: #111827;

      color: #fff;

    }

    textarea {

      width: 100%;

      padding: 10px;

      font-size: 18px;

      text-align: center;

    }

    .btn {

      padding: 10px 20px;

      margin-top: 10px;

      font-size: 18px;

      cursor: pointer;

      border: none;

      border-radius: 8px;

    }

    .btn-primary {

      background-color: orange;

      color: white;

    }

    .btn-outline {

      background-color: white;

      border: 2px solid gray;

      color: black;

    }

    .btn-outline.dark {

      background-color: #1f2937;

      color: white;

      border-color: white;

    }

    .section {

      margin-top: 20px;

    }

    .toggle {

      margin-top: 10px;

    }

  </style>

</head>

<body>

  <h1>🕉️ Mantra Counter</h1>

  <textarea id="mantraInput" rows="2">ॐ नमः शिवाय</textarea>


  <div class="section">

    <div><strong>Current Count:</strong> <span id="currentCount">0</span></div>

    <div><strong>Completed Circles (108x):</strong> <span id="circleCount">0</span></div>

    <button class="btn btn-primary" onclick="handleTap()">Tap ✨</button>

    <button class="btn btn-outline" onclick="resetAll()">Reset All</button>

  </div>


  <div class="toggle">

    <label>

      <input type="checkbox" id="vibrationToggle" checked />

      Vibration on 108 Completion

    </label><br/>

    <label>

      <input type="checkbox" id="darkToggle" />

      Dark Mode

    </label>

  </div>


  <div class="section">

    <h3>📊 History</h3>

    <p>Today: <span id="todayCount">0</span> mala</p>

    <p>This Week: <span id="weeklyCount">0</span> mala</p>

    <p>This Month: <span id="monthlyCount">0</span> mala</p>

    <p>All Time: <span id="allTimeCount">0</span> mala</p>

  </div>


  <script>

    let count = 0;

    let circles = 0;

    const vibrationToggle = document.getElementById('vibrationToggle');

    const darkToggle = document.getElementById('darkToggle');

    const mantraInput = document.getElementById('mantraInput');


    const currentCount = document.getElementById('currentCount');

    const circleCount = document.getElementById('circleCount');

    const todayCount = document.getElementById('todayCount');

    const weeklyCount = document.getElementById('weeklyCount');

    const monthlyCount = document.getElementById('monthlyCount');

    const allTimeCount = document.getElementById('allTimeCount');


    const getToday = () => new Date().toISOString().split('T')[0];


    function loadHistory() {

      return JSON.parse(localStorage.getItem('malaHistory') || '{}');

    }


    function saveHistory(data) {

      localStorage.setItem('malaHistory', JSON.stringify(data));

    }


    function calculateHistoryStats(history) {

      const today = new Date();

      let week = 0, month = 0, total = 0;


      for (const [date, value] of Object.entries(history)) {

        const entryDate = new Date(date);

        const diffDays = Math.floor((today - entryDate) / (1000 * 60 * 60 * 24));

        total += value;


        if (diffDays < 7) week += value;

        if (entryDate.getMonth() === today.getMonth() &&

            entryDate.getFullYear() === today.getFullYear()) {

          month += value;

        }

      }


      todayCount.textContent = history[getToday()] || 0;

      weeklyCount.textContent = week;

      monthlyCount.textContent = month;

      allTimeCount.textContent = total;

    }


    function handleTap() {

      count++;

      if (count >= 108) {

        circles++;

        count = 0;


        if (vibrationToggle.checked && navigator.vibrate) {

          navigator.vibrate([200, 100, 200]);

        }


        const today = getToday();

        const history = loadHistory();

        history[today] = (history[today] || 0) + 1;

        saveHistory(history);

        calculateHistoryStats(history);

      }

      currentCount.textContent = count;

      circleCount.textContent = circles;

    }


    function resetAll() {

      count = 0;

      circles = 0;

      currentCount.textContent = 0;

      circleCount.textContent = 0;

      localStorage.removeItem('malaHistory');

      calculateHistoryStats({});

    }


    darkToggle.addEventListener('change', () => {

      document.body.classList.toggle('dark', darkToggle.checked);

      const btns = document.querySelectorAll('.btn-outline');

    

  btns.forEach(btn => btn.classList.toggle('dark', darkToggle.checked));

    });


    // Init

    calculateHistoryStats(loadHistory());

  </script>

</body>

</html>

Comments

Popular posts from this blog

Secondary Blasting Technique

Charge Preparation for Blating in Mines

Drilling Patterns