-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
149 lines (122 loc) · 5 KB
/
script.js
File metadata and controls
149 lines (122 loc) · 5 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Loading Screen Logic
window.addEventListener('load', () => {
const loadingScreen = document.getElementById('loading-screen');
// Animate progress counter
const progressFill = document.querySelector('.progress-fill');
const percentage = document.querySelector('.loading-percentage');
let count = 0;
const counter = setInterval(() => {
count += Math.random() * 15;
if (count > 100) count = 100;
percentage.textContent = Math.floor(count) + '%';
if (count >= 100) clearInterval(counter);
}, 100);
// Hide loading screen after 3 seconds
setTimeout(() => {
loadingScreen.style.display = 'none';
initScrollAnimations();
}, 3000);
});
// Scroll Progress Indicator
window.addEventListener('scroll', () => {
const scrollProgress = document.getElementById('scroll-progress');
const scrollTop = window.pageYOffset;
const docHeight = document.body.offsetHeight - window.innerHeight;
const scrollPercent = (scrollTop / docHeight) * 100;
scrollProgress.style.width = scrollPercent + '%';
});
// Scroll Animations
function initScrollAnimations() {
const animateElements = document.querySelectorAll('.scroll-animate');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate');
}
});
}, { threshold: 0.1 });
animateElements.forEach(el => observer.observe(el));
}
//API Integration ---
const ideasLoader = document.getElementById('ideas-loader');
const ideasOutput = document.getElementById('ideas-output');
const generateIdeasBtn = document.getElementById('generate-ideas-btn');
const blogTopicInput = document.getElementById('blog-topic-input');
async function callGemini(prompt) {
try {
const response = await fetch('/api/gemini', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prompt })
});
if (!response.ok) {
const errorData = await response.json().catch(() => ({ error: 'Unknown error' }));
throw new Error(errorData.error || `API call failed with status: ${response.status}`);
}
const result = await response.json();
if (result.text) {
return result.text;
} else if (result.error) {
throw new Error(result.error);
} else {
return "Sorry, I couldn't generate a response. Please try again.";
}
} catch (error) {
console.error("API call error:", error);
return `Error: ${error.message}`;
}
}
// Format markdown-style text to HTML
function formatText(text) {
return text
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>') // **bold** to <strong>
.replace(/\*(.*?)\*/g, '<em>$1</em>') // *italic* to <em>
.replace(/\n/g, '<br>'); // newlines to <br>
}
// Blog Idea Generator Logic
generateIdeasBtn.addEventListener('click', async () => {
const topic = blogTopicInput.value.trim();
if (!topic) {
ideasOutput.textContent = "Please enter a topic.";
return;
}
ideasLoader.style.display = 'flex';
ideasOutput.textContent = '';
const prompt = `Generate 5 creative and engaging blog post titles about "${topic}". Format them as a numbered list.`;
const result = await callGemini(prompt);
ideasLoader.style.display = 'none';
ideasOutput.innerHTML = formatText(result);
});
// --- Existing Page Logic ---
const filterButtons = document.querySelectorAll('.filter-btn');
const projectGrid = document.getElementById('project-grid');
const projectCards = document.querySelectorAll('.project-card');
// Initially add scroll class for 'All'
projectGrid.classList.add('project-grid-scrollable');
filterButtons.forEach(button => {
button.addEventListener('click', () => {
filterButtons.forEach(btn => btn.classList.remove('active-filter'));
button.classList.add('active-filter');
const filter = button.getAttribute('data-filter');
if (filter === 'all') {
projectGrid.classList.add('project-grid-scrollable');
} else {
projectGrid.classList.remove('project-grid-scrollable');
}
projectCards.forEach(card => {
const category = card.getAttribute('data-category');
if (filter === 'all' || filter === category) {
card.style.display = 'block';
} else {
card.style.display = 'none';
}
});
});
});
const menuToggleBtn = document.querySelector('[data-collapse-toggle="navbar-sticky"]');
const navbar = document.getElementById('navbar-sticky');
menuToggleBtn.addEventListener('click', () => {
const isExpanded = menuToggleBtn.getAttribute('aria-expanded') === 'true';
menuToggleBtn.setAttribute('aria-expanded', !isExpanded);
navbar.classList.toggle('hidden');
});