Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const editor = document.getElementById('editor');
+ const themeToggle = document.getElementById('theme-toggle');
+ const statsToggle = document.getElementById('stats-toggle');
+ const statsPanel = document.getElementById('stats-panel');
+
+ // Load saved content
+ editor.innerHTML = localStorage.getItem('content') || '';
+
+ // Load saved theme
+ if (localStorage.getItem('theme') === 'dark') {
+ document.body.classList.add('dark-theme');
+ }
+
+ // Theme toggle
+ themeToggle.addEventListener('click', () => {
+ document.body.classList.toggle('dark-theme');
+ localStorage.setItem('theme',
+ document.body.classList.contains('dark-theme') ? 'dark' : 'light'
+ );
+ });
+
+ // Stats toggle
+ statsToggle.addEventListener('click', () => {
+ statsPanel.classList.toggle('hidden');
+ });
+
+ // Save content
+ let saveTimeout;
+ editor.addEventListener('input', () => {
+ clearTimeout(saveTimeout);
+ saveTimeout = setTimeout(() => {
+ localStorage.setItem('content', editor.innerHTML);
+ updateStats();
+ }, 500);
+ });
+
+ function updateStats() {
+ const text = editor.innerText;
+ const words = text.trim().split(/\s+/).filter(word => word.length > 0);
+ const sentences = text.split(/[.!?]+/).filter(sentence => sentence.trim().length > 0);
+ const paragraphs = text.split('\n').filter(para => para.trim().length > 0);
+
+ // Word frequency
+ const wordFreq = {};
+ words.forEach(word => {
+ wordFreq[word.toLowerCase()] = (wordFreq[word.toLowerCase()] || 0) + 1;
+ });
+
+ const mostUsed = Object.entries(wordFreq)
+ .sort((a, b) => b[1] - a[1])[0];
+
+ // Update stats
+ document.getElementById('word-count').textContent = words.length;
+ document.getElementById('char-count').textContent = text.length;
+ document.getElementById('sentence-count').textContent = sentences.length;
+ document.getElementById('paragraph-count').textContent = paragraphs.length;
+ document.getElementById('reading-time').textContent =
+ `${Math.ceil(words.length / 200)} min`;
+ document.getElementById('speaking-time').textContent =
+ `${Math.ceil(words.length / 130)} min`;
+ document.getElementById('avg-word-length').textContent =
+ (words.join('').length / words.length || 0).toFixed(1);
+ document.getElementById('longest-word').textContent =
+ words.reduce((a, b) => a.length > b.length ? a : b, '');
+ document.getElementById('most-used-word').textContent =
+ mostUsed ? `${mostUsed[0]} (${mostUsed[1]}x)` : '-';
+ document.getElementById('unique-words').textContent =
+ Object.keys(wordFreq).length;
+ }
+
+ // Initial stats update
+ updateStats();
+ });