[very crude, wip] post to bsky without the distraction of feeds
at main 3.6 kB view raw
1// Tab switching for login 2document.addEventListener('DOMContentLoaded', function() { 3 const tabs = document.querySelectorAll('.login-tabs .tab'); 4 tabs.forEach(function(tab) { 5 tab.addEventListener('click', function() { 6 // Update active tab 7 tabs.forEach(t => t.classList.remove('active')); 8 this.classList.add('active'); 9 10 // Update visible content 11 const targetId = this.dataset.tab + '-form'; 12 document.querySelectorAll('.tab-content').forEach(function(content) { 13 content.classList.remove('active'); 14 }); 15 document.getElementById(targetId).classList.add('active'); 16 }); 17 }); 18}); 19 20// Character count and thread management 21document.addEventListener('DOMContentLoaded', function() { 22 const charLimit = 300; 23 const container = document.getElementById('posts-container'); 24 const addButton = document.getElementById('addPost'); 25 26 if (!container) return; 27 28 // Update character count for a textarea 29 function updateCharCount(textarea) { 30 const countSpan = textarea.parentElement.querySelector('.count'); 31 if (!countSpan) return; 32 33 const count = textarea.value.length; 34 countSpan.textContent = count; 35 36 const countDiv = textarea.parentElement.querySelector('.char-count'); 37 countDiv.classList.remove('warning', 'danger'); 38 39 if (count > charLimit * 0.9) { 40 countDiv.classList.add('danger'); 41 } else if (count > charLimit * 0.75) { 42 countDiv.classList.add('warning'); 43 } 44 } 45 46 // Attach listeners to textareas 47 function attachListeners(textarea) { 48 textarea.addEventListener('input', function() { 49 updateCharCount(this); 50 }); 51 } 52 53 // Initialize existing textareas 54 document.querySelectorAll('.post-input textarea').forEach(attachListeners); 55 56 // Add post to thread 57 let postIndex = 1; 58 if (addButton) { 59 addButton.addEventListener('click', function() { 60 const div = document.createElement('div'); 61 div.className = 'post-input'; 62 div.dataset.index = postIndex; 63 div.innerHTML = ` 64 <button type="button" class="remove-post" title="Remove">&times;</button> 65 <textarea name="post" placeholder="Continue your thread..." maxlength="${charLimit}"></textarea> 66 <div class="char-count"><span class="count">0</span>/${charLimit}</div> 67 `; 68 69 container.appendChild(div); 70 71 const textarea = div.querySelector('textarea'); 72 attachListeners(textarea); 73 textarea.focus(); 74 75 // Remove button handler 76 div.querySelector('.remove-post').addEventListener('click', function() { 77 div.remove(); 78 }); 79 80 postIndex++; 81 }); 82 } 83 84 // Form validation 85 const form = document.getElementById('postForm'); 86 if (form) { 87 form.addEventListener('submit', function(e) { 88 const textareas = form.querySelectorAll('textarea'); 89 let hasContent = false; 90 91 textareas.forEach(function(ta) { 92 if (ta.value.trim()) { 93 hasContent = true; 94 } 95 }); 96 97 if (!hasContent) { 98 e.preventDefault(); 99 alert('Please write something to post!'); 100 } 101 }); 102 } 103});