-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
39 lines (34 loc) · 1.4 KB
/
app.js
File metadata and controls
39 lines (34 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// app.js – Final clean version for Google Trends module (Dec 2025)
// Show/hide modules – keep this function
function showModule(id) {
document.querySelectorAll('.module').forEach(el => el.classList.add('hidden'));
const module = document.getElementById(id);
if (module) module.classList.remove('hidden');
window.scrollTo({ top: 0, behavior: 'smooth' }); // nice UX
}
// Single unified click handler – no duplicates
document.addEventListener('click', async (e) => {
const link = e.target.closest('[data-module="google-trends"]');
if (link) {
e.preventDefault();
showModule('google-trends');
// Load module only once, dynamically (best practice for GitHub Pages)
const module = await import('./modules/google-trends.js');
module.initGoogleTrends();
}
});
// Support direct URL like ?module=google-trends
if (new URLSearchParams(window.location.search).get('module') === 'google-trends') {
showModule('google-trends');
import('./modules/google-trends.js').then(m => m.initGoogleTrends());
}
// Force preventDefault on all forms (debug for reload bug)
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('form').forEach(form => {
form.addEventListener('submit', (e) => {
e.preventDefault();
e.stopImmediatePropagation(); // Stops other listeners
console.log('Form submit blocked – no reload'); // Check F12 console
});
});
});