CoolFace
Apppublic

zainmax/bytebard-tech-tales-tips

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
script.js70 linesDownload Raw Back to root
1// Theme toggler functionality2document.addEventListener('DOMContentLoaded', () => {3    // Check for saved theme preference or use system preference4    if (localStorage.getItem('color-theme') === 'dark' || (!('color-theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {5        document.documentElement.classList.add('dark');6    } else {7        document.documentElement.classList.remove('dark');8    }9    10    // Initialize feather icons11    feather.replace();12});13 14// Function to toggle theme15function toggleTheme() {16    if (localStorage.getItem('color-theme') === 'dark') {17        localStorage.setItem('color-theme', 'light');18        document.documentElement.classList.remove('dark');19    } else {20        localStorage.setItem('color-theme', 'dark');21        document.documentElement.classList.add('dark');22    }23}24 25// Smooth scrolling for anchor links26document.querySelectorAll('a[href^="#"]').forEach(anchor => {27    anchor.addEventListener('click', function (e) {28        e.preventDefault();29        document.querySelector(this.getAttribute('href')).scrollIntoView({30            behavior: 'smooth'31        });32    });33});34// Mobile menu toggle functionality35function toggleMobileMenu() {36    const menu = document.getElementById('mobile-menu');37    menu.classList.toggle('hidden');38}39 40// Blog editor functionality41document.addEventListener('DOMContentLoaded', () => {42    const editors = document.querySelectorAll('blog-editor');43    editors.forEach(editor => {44        editor.shadowRoot.querySelector('.save-button').addEventListener('click', () => {45            const title = editor.shadowRoot.querySelector('.editor-title').value;46            const content = editor.shadowRoot.querySelector('.editor-content').innerHTML;47            48            const newArticle = {49                id: Date.now(),50                title: title,51                content: content,52                excerpt: content.substring(0, 100) + '...',53                date: new Date().toLocaleDateString(),54                category: 'Tech',55                readTime: '5 min read',56                author: 'You',57                authorImage: 'http://static.photos/people/200x200/1',58                image: 'http://static.photos/technology/640x360/1'59            };60            61            const existingArticles = JSON.parse(localStorage.getItem('blog-articles') || '[]');62            existingArticles.unshift(newArticle);63            localStorage.setItem('blog-articles', JSON.stringify(existingArticles));64            65            alert('Article published successfully!');66            window.location.href = '/articles.html';67        });68    });69});70