Spaces:
Running
Running
You can elaborate and/or flesh it out and/or contextualize it any way you want, but I want it in tact (actually it would be great if you also wanted to contribute some novel ideas into the lists if you have any you see I'm missing or haven't talked about, that includes entire methods if you please) and to look less like a threat actor resource WHICH IT IS NOT and more as the quick reference which it is for my work:
348020b verified Download script.js from defuse/security-reference-guide: direct link, hf CLI and curl.
- Browser
- Download file 11.6 kB
-
https://huggingface.co/spaces/defuse/security-reference-guide/resolve/main/script.js
- Command line
-
hf download hf://spaces/defuse/security-reference-guide/script.js
-
curl -L -o script.js https://huggingface.co/spaces/defuse/security-reference-guide/resolve/main/script.js
11.6 kB
| // Security Reference Guide - Interactive Features | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Initialize Feather Icons | |
| feather.replace(); | |
| // Mobile menu toggle | |
| const mobileMenuButton = document.getElementById('mobile-menu-button'); | |
| const mobileMenu = document.getElementById('mobile-menu'); | |
| if (mobileMenuButton && mobileMenu) { | |
| mobileMenuButton.addEventListener('click', function() { | |
| mobileMenu.classList.toggle('hidden'); | |
| const icon = mobileMenuButton.querySelector('i'); | |
| if (mobileMenu.classList.contains('hidden')) { | |
| icon.setAttribute('data-feather', 'menu'); | |
| } else { | |
| icon.setAttribute('data-feather', 'x'); | |
| } | |
| feather.replace(); | |
| }); | |
| } | |
| // Smooth scrolling for navigation links | |
| const navLinks = document.querySelectorAll('a[href^="#"]'); | |
| navLinks.forEach(link => { | |
| link.addEventListener('click', function(e) { | |
| e.preventDefault(); | |
| const targetId = this.getAttribute('href'); | |
| const targetElement = document.querySelector(targetId); | |
| if (targetElement) { | |
| const offsetTop = targetElement.offsetTop - 80; // Account for fixed navbar | |
| window.scrollTo({ | |
| top: offsetTop, | |
| behavior: 'smooth' | |
| }); | |
| } | |
| // Close mobile menu if open | |
| if (mobileMenu && !mobileMenu.classList.contains('hidden')) { | |
| mobileMenu.classList.add('hidden'); | |
| const icon = mobileMenuButton.querySelector('i'); | |
| icon.setAttribute('data-feather', 'menu'); | |
| feather.replace(); | |
| } | |
| }); | |
| }); | |
| // Back to top button | |
| const backToTopButton = document.getElementById('back-to-top'); | |
| function toggleBackToTopButton() { | |
| if (window.pageYOffset > 300) { | |
| backToTopButton.classList.remove('opacity-0', 'invisible'); | |
| } else { | |
| backToTopButton.classList.add('opacity-0', 'invisible'); | |
| } | |
| } | |
| if (backToTopButton) { | |
| backToTopButton.addEventListener('click', function() { | |
| window.scrollTo({ | |
| top: 0, | |
| behavior: 'smooth' | |
| }); | |
| }); | |
| } | |
| // Scroll event listener | |
| window.addEventListener('scroll', toggleBackToTopButton); | |
| // Navbar background change on scroll | |
| const navbar = document.querySelector('nav'); | |
| function updateNavbarBackground() { | |
| if (window.scrollY > 50) { | |
| navbar.classList.add('bg-black-900/98'); | |
| navbar.classList.remove('bg-black-900/95'); | |
| } else { | |
| navbar.classList.add('bg-black-900/95'); | |
| navbar.classList.remove('bg-black-900/98'); | |
| } | |
| } | |
| window.addEventListener('scroll', updateNavbarBackground); | |
| // Intersection Observer for fade-in animations | |
| const observerOptions = { | |
| threshold: 0.1, | |
| rootMargin: '0px 0px -50px 0px' | |
| }; | |
| const observer = new IntersectionObserver(function(entries) { | |
| entries.forEach(entry => { | |
| if (entry.isIntersecting) { | |
| entry.target.classList.add('fade-in-up'); | |
| observer.unobserve(entry.target); | |
| } | |
| }); | |
| }, observerOptions); | |
| // Observe vulnerability cards | |
| const vulnerabilityCards = document.querySelectorAll('.vulnerability-card'); | |
| vulnerabilityCards.forEach(card => { | |
| observer.observe(card); | |
| }); | |
| // Observe sections | |
| const sections = document.querySelectorAll('section'); | |
| sections.forEach(section => { | |
| observer.observe(section); | |
| }); | |
| // Copy code functionality | |
| function addCopyButtons() { | |
| const codeBlocks = document.querySelectorAll('pre'); | |
| codeBlocks.forEach(block => { | |
| const copyButton = document.createElement('button'); | |
| copyButton.className = 'absolute top-2 right-2 bg-gray-700 hover:bg-gray-600 text-white px-3 py-1 rounded text-xs transition-colors'; | |
| copyButton.innerHTML = '<i data-feather="copy" class="w-3 h-3"></i>'; | |
| copyButton.title = 'Copy code'; | |
| const container = document.createElement('div'); | |
| container.className = 'relative'; | |
| block.parentNode.insertBefore(container, block); | |
| container.appendChild(block); | |
| container.appendChild(copyButton); | |
| copyButton.addEventListener('click', function() { | |
| const codeText = block.textContent; | |
| navigator.clipboard.writeText(codeText).then(() => { | |
| const icon = copyButton.querySelector('i'); | |
| icon.setAttribute('data-feather', 'check'); | |
| feather.replace(); | |
| setTimeout(() => { | |
| icon.setAttribute('data-feather', 'copy'); | |
| feather.replace(); | |
| }, 2000); | |
| }).catch(err => { | |
| console.error('Failed to copy text: ', err); | |
| }); | |
| }); | |
| }); | |
| } | |
| // Initialize copy buttons after a short delay to ensure DOM is ready | |
| setTimeout(addCopyButtons, 1000); | |
| // Active navigation highlighting | |
| function updateActiveNavigation() { | |
| const sections = document.querySelectorAll('section[id]'); | |
| const navLinks = document.querySelectorAll('nav a[href^="#"]'); | |
| let currentSection = ''; | |
| sections.forEach(section => { | |
| const sectionTop = section.offsetTop - 100; | |
| const sectionHeight = section.offsetHeight; | |
| if (window.pageYOffset >= sectionTop && window.pageYOffset < sectionTop + sectionHeight) { | |
| currentSection = section.getAttribute('id'); | |
| } | |
| }); | |
| navLinks.forEach(link => { | |
| link.classList.remove('text-accent-500'); | |
| if (link.getAttribute('href') === `#${currentSection}`) { | |
| link.classList.add('text-accent-500'); | |
| } | |
| }); | |
| } | |
| window.addEventListener('scroll', updateActiveNavigation); | |
| // Keyboard navigation enhancements | |
| document.addEventListener('keydown', function(e) { | |
| // Alt + number keys for quick section navigation | |
| if (e.altKey) { | |
| switch(e.key) { | |
| case '1': | |
| e.preventDefault(); | |
| document.querySelector('#overview')?.scrollIntoView({ behavior: 'smooth' }); | |
| break; | |
| case '2': | |
| e.preventDefault(); | |
| document.querySelector('#vulnerabilities')?.scrollIntoView({ behavior: 'smooth' }); | |
| break; | |
| case '3': | |
| e.preventDefault(); | |
| document.querySelector('#methodologies')?.scrollIntoView({ behavior: 'smooth' }); | |
| break; | |
| case '4': | |
| e.preventDefault(); | |
| document.querySelector('#resources')?.scrollIntoView({ behavior: 'smooth' }); | |
| break; | |
| } | |
| } | |
| }); | |
| // Print optimization | |
| window.addEventListener('beforeprint', function() { | |
| // Expand all collapsed sections for printing | |
| document.querySelectorAll('.hidden').forEach(element => { | |
| element.classList.remove('hidden'); | |
| }); | |
| }); | |
| // Search functionality (basic implementation) | |
| function initializeSearch() { | |
| const searchInput = document.getElementById('search-input'); | |
| if (!searchInput) return; | |
| searchInput.addEventListener('input', function() { | |
| const searchTerm = this.value.toLowerCase(); | |
| const vulnerabilityCards = document.querySelectorAll('.vulnerability-card'); | |
| vulnerabilityCards.forEach(card => { | |
| const title = card.querySelector('h3').textContent.toLowerCase(); | |
| const content = card.textContent.toLowerCase(); | |
| if (title.includes(searchTerm) || content.includes(searchTerm)) { | |
| card.style.display = 'block'; | |
| } else { | |
| card.style.display = 'none'; | |
| } | |
| }); | |
| }); | |
| } | |
| // Enhanced vulnerability filtering | |
| function initializeVulnerabilityFilters() { | |
| const filterButtons = document.querySelectorAll('[data-filter]'); | |
| filterButtons.forEach(button => { | |
| button.addEventListener('click', function() { | |
| const filter = this.getAttribute('data-filter'); | |
| const vulnerabilityCards = document.querySelectorAll('.vulnerability-card'); | |
| vulnerabilityCards.forEach(card => { | |
| if (filter === 'all') { | |
| card.style.display = 'block'; | |
| } else { | |
| const severity = card.querySelector('.bg-red-500, .bg-orange-500') ? | |
| (card.querySelector('.bg-red-500') ? 'critical' : 'high') : | |
| 'medium'; | |
| card.style.display = severity === filter ? 'block' : 'none'; | |
| } | |
| }); | |
| // Update active filter button | |
| filterButtons.forEach(btn => btn.classList.remove('bg-accent-500')); | |
| this.classList.add('bg-accent-500'); | |
| }); | |
| }); | |
| } | |
| // Performance monitoring | |
| function logPerformanceMetrics() { | |
| if ('performance' in window) { | |
| window.addEventListener('load', function() { | |
| setTimeout(() => { | |
| const perfData = performance.getEntriesByType('navigation')[0]; | |
| console.log('Page Load Time:', perfData.loadEventEnd - perfData.loadEventStart, 'ms'); | |
| console.log('DOM Content Loaded:', perfData.domContentLoadedEventEnd - perfData.domContentLoadedEventStart, 'ms'); | |
| }, 0); | |
| }); | |
| } | |
| } | |
| // Initialize all features | |
| initializeSearch(); | |
| initializeVulnerabilityFilters(); | |
| logPerformanceMetrics(); | |
| // Error handling for images | |
| document.querySelectorAll('img').forEach(img => { | |
| img.addEventListener('error', function() { | |
| this.style.display = 'none'; | |
| console.warn('Failed to load image:', this.src); | |
| }); | |
| }); | |
| // Accessibility enhancements | |
| function enhanceAccessibility() { | |
| // Add skip link | |
| const skipLink = document.createElement('a'); | |
| skipLink.href = '#main-content'; | |
| skipLink.textContent = 'Skip to main content'; | |
| skipLink.className = 'sr-only focus:not-sr-only focus:absolute focus:top-4 focus:left-4 bg-accent-500 text-white px-4 py-2 rounded z-50'; | |
| document.body.insertBefore(skipLink, document.body.firstChild); | |
| // Add ARIA labels to navigation | |
| const nav = document.querySelector('nav'); | |
| if (nav) nav.setAttribute('role', 'navigation'); | |
| // Add main landmark | |
| const mainContent = document.querySelector('section'); | |
| if (mainContent) { | |
| mainContent.setAttribute('id', 'main-content'); | |
| mainContent.setAttribute('role', 'main'); | |
| } | |
| } | |
| enhanceAccessibility(); | |
| console.log('Security Reference Guide initialized successfully'); | |
| }); |