167 lines
5.8 KiB
JavaScript
167 lines
5.8 KiB
JavaScript
// Field Guide for Subversives - Main JavaScript
|
||
|
||
document.addEventListener('DOMContentLoaded', function() {
|
||
// Mobile navigation toggle
|
||
const navToggle = document.getElementById('nav-toggle');
|
||
const sidebar = document.getElementById('sidebar');
|
||
|
||
if (navToggle && sidebar) {
|
||
navToggle.addEventListener('click', function() {
|
||
sidebar.classList.toggle('active');
|
||
});
|
||
}
|
||
|
||
// Smooth scrolling for anchor links
|
||
const anchorLinks = document.querySelectorAll('a[href^="#"]');
|
||
anchorLinks.forEach(link => {
|
||
link.addEventListener('click', function(e) {
|
||
e.preventDefault();
|
||
const target = document.querySelector(this.getAttribute('href'));
|
||
if (target) {
|
||
target.scrollIntoView({
|
||
behavior: 'smooth',
|
||
block: 'start'
|
||
});
|
||
}
|
||
});
|
||
});
|
||
|
||
// Add security warning for external links
|
||
const externalLinks = document.querySelectorAll('a[href^="http"]:not([href*="' + window.location.hostname + '"])');
|
||
externalLinks.forEach(link => {
|
||
link.addEventListener('click', function(e) {
|
||
if (!confirm('You are about to visit an external site. Ensure you are using secure browsing practices. Continue?')) {
|
||
e.preventDefault();
|
||
}
|
||
});
|
||
|
||
// Add visual indicator for external links
|
||
link.setAttribute('title', 'External link - opens in new tab');
|
||
link.setAttribute('target', '_blank');
|
||
link.setAttribute('rel', 'noopener noreferrer');
|
||
});
|
||
|
||
// Keyboard navigation
|
||
document.addEventListener('keydown', function(e) {
|
||
// Alt + Left Arrow: Previous page
|
||
if (e.altKey && e.key === 'ArrowLeft') {
|
||
const prevLink = document.querySelector('.section-nav .nav-link:first-child');
|
||
if (prevLink && prevLink.href) {
|
||
window.location.href = prevLink.href;
|
||
}
|
||
}
|
||
|
||
// Alt + Right Arrow: Next page
|
||
if (e.altKey && e.key === 'ArrowRight') {
|
||
const nextLink = document.querySelector('.section-nav .nav-link:last-child');
|
||
if (nextLink && nextLink.href) {
|
||
window.location.href = nextLink.href;
|
||
}
|
||
}
|
||
|
||
// Escape: Close mobile menu
|
||
if (e.key === 'Escape' && sidebar && sidebar.classList.contains('active')) {
|
||
sidebar.classList.remove('active');
|
||
}
|
||
});
|
||
|
||
// Print functionality
|
||
function addPrintButton() {
|
||
const contentHeader = document.querySelector('.content-header');
|
||
if (contentHeader) {
|
||
const printButton = document.createElement('button');
|
||
printButton.textContent = 'Print Section';
|
||
printButton.className = 'print-button';
|
||
printButton.style.cssText = `
|
||
background: #333;
|
||
color: #00ff00;
|
||
border: 1px solid #00ff00;
|
||
padding: 0.5rem 1rem;
|
||
border-radius: 3px;
|
||
cursor: pointer;
|
||
font-family: inherit;
|
||
margin-top: 1rem;
|
||
`;
|
||
printButton.addEventListener('click', function() {
|
||
window.print();
|
||
});
|
||
contentHeader.appendChild(printButton);
|
||
}
|
||
}
|
||
|
||
addPrintButton();
|
||
|
||
// Security reminder
|
||
function showSecurityReminder() {
|
||
const reminder = document.createElement('div');
|
||
reminder.style.cssText = `
|
||
position: fixed;
|
||
bottom: 20px;
|
||
right: 20px;
|
||
background: rgba(255, 170, 0, 0.9);
|
||
color: #000;
|
||
padding: 1rem;
|
||
border-radius: 5px;
|
||
max-width: 300px;
|
||
font-size: 0.9rem;
|
||
z-index: 1000;
|
||
display: none;
|
||
`;
|
||
reminder.innerHTML = `
|
||
<strong>Security Reminder:</strong> Ensure you're using Tails OS or a secure browser when accessing this guide.
|
||
<button onclick="this.parentElement.style.display='none'" style="float: right; background: none; border: none; font-size: 1.2rem; cursor: pointer;">×</button>
|
||
`;
|
||
document.body.appendChild(reminder);
|
||
|
||
// Show reminder after 30 seconds
|
||
setTimeout(() => {
|
||
reminder.style.display = 'block';
|
||
}, 30000);
|
||
|
||
// Auto-hide after 10 seconds
|
||
setTimeout(() => {
|
||
reminder.style.display = 'none';
|
||
}, 40000);
|
||
}
|
||
|
||
// Only show security reminder on first visit
|
||
if (!localStorage.getItem('security_reminder_shown')) {
|
||
showSecurityReminder();
|
||
localStorage.setItem('security_reminder_shown', 'true');
|
||
}
|
||
|
||
// Add copy-to-clipboard functionality for code blocks
|
||
const codeBlocks = document.querySelectorAll('pre code');
|
||
codeBlocks.forEach(block => {
|
||
const button = document.createElement('button');
|
||
button.textContent = 'Copy';
|
||
button.className = 'copy-button';
|
||
button.style.cssText = `
|
||
position: absolute;
|
||
top: 0.5rem;
|
||
right: 0.5rem;
|
||
background: #333;
|
||
color: #00ff00;
|
||
border: 1px solid #00ff00;
|
||
padding: 0.25rem 0.5rem;
|
||
border-radius: 3px;
|
||
cursor: pointer;
|
||
font-size: 0.8rem;
|
||
`;
|
||
|
||
const pre = block.parentElement;
|
||
pre.style.position = 'relative';
|
||
pre.appendChild(button);
|
||
|
||
button.addEventListener('click', function() {
|
||
navigator.clipboard.writeText(block.textContent).then(() => {
|
||
button.textContent = 'Copied!';
|
||
setTimeout(() => {
|
||
button.textContent = 'Copy';
|
||
}, 2000);
|
||
});
|
||
});
|
||
});
|
||
});
|
||
|