fix links

This commit is contained in:
overcuriousity 2025-07-27 21:18:11 +02:00
parent 0eed65e623
commit 6c7d3528f7

View File

@ -20,215 +20,220 @@ const { title, description = 'ForensicPathways - A comprehensive directory of di
<title>{title} - ForensicPathways</title> <title>{title} - ForensicPathways</title>
<link rel="icon" type="image/x-icon" href="/favicon.ico"> <link rel="icon" type="image/x-icon" href="/favicon.ico">
<script> <script>
document.addEventListener('DOMContentLoaded', () => { // Move utility functions OUTSIDE DOMContentLoaded to avoid race conditions
const THEME_KEY = 'dfir-theme'; function createToolSlug(toolName) {
if (!toolName || typeof toolName !== 'string') {
console.warn('[toolHelpers] Invalid toolName provided to createToolSlug:', toolName);
return '';
}
function getSystemTheme() { return toolName.toLowerCase()
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; .replace(/[^a-z0-9\s-]/g, '') // Remove special characters
} .replace(/\s+/g, '-') // Replace spaces with hyphens
.replace(/-+/g, '-') // Remove duplicate hyphens
.replace(/^-|-$/g, ''); // Remove leading/trailing hyphens
}
function getStoredTheme() { function findToolByIdentifier(tools, identifier) {
return localStorage.getItem(THEME_KEY) || 'auto'; if (!identifier || !Array.isArray(tools)) return undefined;
}
function applyTheme(theme) { return tools.find(tool =>
const effectiveTheme = theme === 'auto' ? getSystemTheme() : theme; tool.name === identifier ||
document.documentElement.setAttribute('data-theme', effectiveTheme); createToolSlug(tool.name) === identifier.toLowerCase()
} );
}
function updateThemeToggle(theme) { function isToolHosted(tool) {
document.querySelectorAll('[data-theme-toggle]').forEach(button => { return tool.projectUrl !== undefined &&
button.setAttribute('data-current-theme', theme); tool.projectUrl !== null &&
}); tool.projectUrl !== "" &&
} tool.projectUrl.trim() !== "";
}
function initTheme() { // Consolidated scrolling utility - also moved outside DOMContentLoaded
const storedTheme = getStoredTheme(); function scrollToElement(element, options = {}) {
applyTheme(storedTheme); if (!element) return;
updateThemeToggle(storedTheme);
}
function toggleTheme() { // Calculate target position manually to avoid double-scroll
const current = getStoredTheme(); setTimeout(() => {
const themes = ['light', 'dark', 'auto']; const headerHeight = document.querySelector('nav')?.offsetHeight || 80;
const currentIndex = themes.indexOf(current); const elementRect = element.getBoundingClientRect();
const nextIndex = (currentIndex + 1) % themes.length; const absoluteElementTop = elementRect.top + window.pageYOffset;
const nextTheme = themes[nextIndex]; const targetPosition = absoluteElementTop - headerHeight - 20; // Adjust this 20 as needed
localStorage.setItem(THEME_KEY, nextTheme); window.scrollTo({
applyTheme(nextTheme); top: targetPosition,
updateThemeToggle(nextTheme); behavior: 'smooth'
}
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
if (getStoredTheme() === 'auto') {
applyTheme('auto');
}
}); });
}, 100);
}
(window as any).themeUtils = { // Convenience functions for common scroll targets
initTheme, function scrollToElementById(elementId, options = {}) {
toggleTheme, const element = document.getElementById(elementId);
getStoredTheme scrollToElement(element, options);
}; }
// Consolidated scrolling utility function scrollToElementBySelector(selector, options = {}) {
(window as any).scrollToElement = function(element, options = {}) { const element = document.querySelector(selector);
if (!element) return; scrollToElement(element, options);
}
// Calculate target position manually to avoid double-scroll // Attach to window immediately - BEFORE DOMContentLoaded
setTimeout(() => { (window as any).createToolSlug = createToolSlug;
const headerHeight = document.querySelector('nav')?.offsetHeight || 80; (window as any).findToolByIdentifier = findToolByIdentifier;
const elementRect = element.getBoundingClientRect(); (window as any).isToolHosted = isToolHosted;
const absoluteElementTop = elementRect.top + window.pageYOffset; (window as any).scrollToElement = scrollToElement;
const targetPosition = absoluteElementTop - headerHeight - 20; // Adjust this 20 as needed (window as any).scrollToElementById = scrollToElementById;
(window as any).scrollToElementBySelector = scrollToElementBySelector;
window.scrollTo({ document.addEventListener('DOMContentLoaded', () => {
top: targetPosition, const THEME_KEY = 'dfir-theme';
behavior: 'smooth'
});
}, 100);
};
// Convenience functions for common scroll targets function getSystemTheme() {
(window as any).scrollToElementById = function(elementId, options = {}) { return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
const element = document.getElementById(elementId); }
(window as any).scrollToElement(element, options);
};
(window as any).scrollToElementBySelector = function(selector, options = {}) { function getStoredTheme() {
const element = document.querySelector(selector); return localStorage.getItem(THEME_KEY) || 'auto';
(window as any).scrollToElement(element, options); }
};
function createToolSlug(toolName) { function applyTheme(theme) {
if (!toolName || typeof toolName !== 'string') { const effectiveTheme = theme === 'auto' ? getSystemTheme() : theme;
console.warn('[toolHelpers] Invalid toolName provided to createToolSlug:', toolName); document.documentElement.setAttribute('data-theme', effectiveTheme);
return ''; }
}
return toolName.toLowerCase() function updateThemeToggle(theme) {
.replace(/[^a-z0-9\s-]/g, '') // Remove special characters document.querySelectorAll('[data-theme-toggle]').forEach(button => {
.replace(/\s+/g, '-') // Replace spaces with hyphens button.setAttribute('data-current-theme', theme);
.replace(/-+/g, '-') // Remove duplicate hyphens });
.replace(/^-|-$/g, ''); // Remove leading/trailing hyphens }
function initTheme() {
const storedTheme = getStoredTheme();
applyTheme(storedTheme);
updateThemeToggle(storedTheme);
}
function toggleTheme() {
const current = getStoredTheme();
const themes = ['light', 'dark', 'auto'];
const currentIndex = themes.indexOf(current);
const nextIndex = (currentIndex + 1) % themes.length;
const nextTheme = themes[nextIndex];
localStorage.setItem(THEME_KEY, nextTheme);
applyTheme(nextTheme);
updateThemeToggle(nextTheme);
}
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
if (getStoredTheme() === 'auto') {
applyTheme('auto');
} }
function findToolByIdentifier(tools, identifier) {
if (!identifier || !Array.isArray(tools)) return undefined;
return tools.find(tool =>
tool.name === identifier ||
createToolSlug(tool.name) === identifier.toLowerCase()
);
}
function isToolHosted(tool) {
return tool.projectUrl !== undefined &&
tool.projectUrl !== null &&
tool.projectUrl !== "" &&
tool.projectUrl.trim() !== "";
}
(window as any).createToolSlug = createToolSlug;
(window as any).findToolByIdentifier = findToolByIdentifier;
(window as any).isToolHosted = isToolHosted;
async function checkClientAuth(context = 'general') {
try {
const response = await fetch('/api/auth/status');
const data = await response.json();
switch (context) {
case 'contributions':
return {
authenticated: data.contributionAuthenticated,
authRequired: data.contributionAuthRequired,
expires: data.expires
};
case 'ai':
return {
authenticated: data.aiAuthenticated,
authRequired: data.aiAuthRequired,
expires: data.expires
};
default:
return {
authenticated: data.authenticated,
authRequired: data.contributionAuthRequired || data.aiAuthRequired,
expires: data.expires
};
}
} catch (error) {
console.error('Auth check failed:', error);
return {
authenticated: false,
authRequired: true
};
}
}
async function requireClientAuth(callback, returnUrl, context = 'general') {
const authStatus = await checkClientAuth(context);
if (authStatus.authRequired && !authStatus.authenticated) {
const targetUrl = returnUrl || window.location.href;
window.location.href = `/api/auth/login?returnTo=${encodeURIComponent(targetUrl)}`;
return false;
} else {
if (typeof callback === 'function') {
callback();
}
return true;
}
}
async function showIfAuthenticated(selector, context = 'general') {
const authStatus = await checkClientAuth(context);
const element = document.querySelector(selector);
if (element) {
element.style.display = (!authStatus.authRequired || authStatus.authenticated)
? 'inline-flex'
: 'none';
}
}
function setupAuthButtons(selector = '[data-contribute-button]') {
document.addEventListener('click', async (e) => {
if (!e.target) return;
const button = (e.target as Element).closest(selector);
if (!button) return;
e.preventDefault();
console.log('[AUTH] Contribute button clicked:', button.getAttribute('data-contribute-button'));
await requireClientAuth(() => {
console.log('[AUTH] Navigation approved, redirecting to:', (button as HTMLAnchorElement).href);
window.location.href = (button as HTMLAnchorElement).href;
}, (button as HTMLAnchorElement).href, 'contributions');
});
}
(window as any).checkClientAuth = checkClientAuth;
(window as any).requireClientAuth = requireClientAuth;
(window as any).showIfAuthenticated = showIfAuthenticated;
(window as any).setupAuthButtons = setupAuthButtons;
initTheme();
setupAuthButtons('[data-contribute-button]');
const initAIButton = async () => {
await showIfAuthenticated('#ai-view-toggle', 'ai');
};
initAIButton();
console.log('[CONSOLIDATED] All utilities loaded and initialized');
}); });
</script>
(window as any).themeUtils = {
initTheme,
toggleTheme,
getStoredTheme
};
async function checkClientAuth(context = 'general') {
try {
const response = await fetch('/api/auth/status');
const data = await response.json();
switch (context) {
case 'contributions':
return {
authenticated: data.contributionAuthenticated,
authRequired: data.contributionAuthRequired,
expires: data.expires
};
case 'ai':
return {
authenticated: data.aiAuthenticated,
authRequired: data.aiAuthRequired,
expires: data.expires
};
default:
return {
authenticated: data.authenticated,
authRequired: data.contributionAuthRequired || data.aiAuthRequired,
expires: data.expires
};
}
} catch (error) {
console.error('Auth check failed:', error);
return {
authenticated: false,
authRequired: true
};
}
}
async function requireClientAuth(callback, returnUrl, context = 'general') {
const authStatus = await checkClientAuth(context);
if (authStatus.authRequired && !authStatus.authenticated) {
const targetUrl = returnUrl || window.location.href;
window.location.href = `/api/auth/login?returnTo=${encodeURIComponent(targetUrl)}`;
return false;
} else {
if (typeof callback === 'function') {
callback();
}
return true;
}
}
async function showIfAuthenticated(selector, context = 'general') {
const authStatus = await checkClientAuth(context);
const element = document.querySelector(selector);
if (element) {
element.style.display = (!authStatus.authRequired || authStatus.authenticated)
? 'inline-flex'
: 'none';
}
}
function setupAuthButtons(selector = '[data-contribute-button]') {
document.addEventListener('click', async (e) => {
if (!e.target) return;
const button = (e.target as Element).closest(selector);
if (!button) return;
e.preventDefault();
console.log('[AUTH] Contribute button clicked:', button.getAttribute('data-contribute-button'));
await requireClientAuth(() => {
console.log('[AUTH] Navigation approved, redirecting to:', (button as HTMLAnchorElement).href);
window.location.href = (button as HTMLAnchorElement).href;
}, (button as HTMLAnchorElement).href, 'contributions');
});
}
(window as any).checkClientAuth = checkClientAuth;
(window as any).requireClientAuth = requireClientAuth;
(window as any).showIfAuthenticated = showIfAuthenticated;
(window as any).setupAuthButtons = setupAuthButtons;
initTheme();
setupAuthButtons('[data-contribute-button]');
const initAIButton = async () => {
await showIfAuthenticated('#ai-view-toggle', 'ai');
};
initAIButton();
console.log('[CONSOLIDATED] All utilities loaded and initialized');
});
</script>
</head> </head>
<body> <body>
<Navigation /> <Navigation />