class ToolDecider extends HTMLElement { connectedCallback() { this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = `
Analysis paralysis killer

🎲
Result
`; this.inputArea = this.shadowRoot.getElementById('inputArea'); this.resultArea = this.shadowRoot.getElementById('resultArea'); this.textarea = this.shadowRoot.getElementById('options'); this.decideBtn = this.shadowRoot.getElementById('decideBtn'); this.resetLink = this.shadowRoot.getElementById('resetLink'); this.winnerText = this.shadowRoot.getElementById('winnerText'); this.decideBtn.addEventListener('click', () => this.decide()); this.resetLink.addEventListener('click', () => this.reset()); } decide() { const raw = this.textarea.value; // Split by comma or newline, filter empty const options = raw.split(/[\n,]+/).map(s => s.trim()).filter(s => s.length > 0); if (options.length < 2) { // Simple feedback this.textarea.style.borderColor = '#ef4444'; setTimeout(() => { this.textarea.style.borderColor = '#334155'; }, 1000); return; } // Simulate "thinking" or rolling this.decideBtn.textContent = 'Rolling...'; this.decideBtn.disabled = true; let counter = 0; const maxRolls = 15; const interval = setInterval(() => { this.winnerText.textContent = options[Math.floor(Math.random() * options.length)]; counter++; if (counter >= maxRolls) { clearInterval(interval); this.showResult(options); } }, 80); } showResult(options) { const winner = options[Math.floor(Math.random() * options.length)]; this.winnerText.textContent = winner; this.inputArea.style.display = 'none'; this.resultArea.classList.add('show'); } reset() { this.resultArea.classList.remove('show'); this.inputArea.style.display = 'block'; this.decideBtn.textContent = 'Decide For Me'; this.decideBtn.disabled = false; this.textarea.value = ''; this.textarea.focus(); } } customElements.define('tool-decider', ToolDecider);