Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions frontend/js/chatbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ restoreChatHistory();

// Load data
// Note: This path assumes index.html is in /pages/ and data is in /data/
fetch('../data/chatbot_data.json')
// Resolve path relative to root regardless of current page depth
const isPagesDir = window.location.pathname.includes('/pages/');
const chatbotDataPath = isPagesDir ? '../../frontend/data/chatbot_data.json' : './frontend/data/chatbot_data.json';
fetch(chatbotDataPath)
.then(response => response.json())
.then(data => {
intents = data.intents;
Expand Down Expand Up @@ -342,4 +345,4 @@ function parseMarkdown(text) {

return "I'm not sure about that. Try asking about open source programs or guides.";
}
});
});
75 changes: 10 additions & 65 deletions frontend/js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ document.addEventListener('DOMContentLoaded', () => {

// ===============================
// Scroll Progress Indicator (Top)
// FIX: Renamed variable from 'scrollProgressBar' to 'homeScrollProgressBar'
// to avoid conflict with the same variable name declared in theme.js
// ===============================
const scrollProgressBar = document.getElementById('scrollProgress');
const homeScrollProgressBar = document.getElementById('scrollProgress');

if (scrollProgressBar) {
if (homeScrollProgressBar) {
window.addEventListener(
'scroll',
() => {
Expand All @@ -136,12 +138,12 @@ if (scrollProgressBar) {
document.documentElement.clientHeight;

if (docHeight <= 0) {
scrollProgressBar.style.width = '0%';
homeScrollProgressBar.style.width = '0%';
return;
}

const scrollPercent = (scrollTop / docHeight) * 100;
scrollProgressBar.style.width = `${scrollPercent}%`;
homeScrollProgressBar.style.width = `${scrollPercent}%`;
},
{ passive: true }
);
Expand Down Expand Up @@ -190,6 +192,7 @@ if (scrollProgressBar) {
cursor.style.opacity = '';
});
})();

// ===============================
// Back to Top Button
// ===============================
Expand Down Expand Up @@ -285,6 +288,9 @@ document.addEventListener("DOMContentLoaded", () => {
const counters = document.querySelectorAll(".counter");
const statsSection = document.querySelector(".stats");

// FIX: Guard against null statsSection
if (!statsSection) return;

let hasAnimated = false;

const animateCounter = (counter) => {
Expand Down Expand Up @@ -334,65 +340,4 @@ document.addEventListener("DOMContentLoaded", () => {
});

observer.observe(statsSection);
});

function openModal(program) {
const modal = document.getElementById("programModal");
const title = document.getElementById("modalTitle");
const basicInfo = document.getElementById("modalBasicInfo");
const skills = document.getElementById("modalSkills");
const prepare = document.getElementById("modalPrepare");
const tips = document.getElementById("modalTips");

const data = {
gsoc: {
title: "Google Summer of Code",
basic: `
📅 <b>Duration:</b> 12 Weeks <br>
🌍 <b>Eligibility:</b> Students worldwide <br>
💰 <b>Stipend:</b> Paid <br>
⏳ <b>Timeline:</b> May–Aug
`,
skills: [
"Strong problem solving",
"Git & GitHub workflow",
"Open source contribution experience"
],
prepare: [
"Start contributing early",
"Fix good first issues",
"Interact with mentors",
"Understand project roadmap"
],
tips: [
"Write strong proposal",
"Be active in discussions",
"Submit quality PRs",
"Show consistency"
]
}
};

const programData = data[program];

title.innerHTML = programData.title;
basicInfo.innerHTML = programData.basic;

skills.innerHTML = "<ul>" + programData.skills.map(item => `<li>${item}</li>`).join("") + "</ul>";
prepare.innerHTML = "<ul>" + programData.prepare.map(item => `<li>${item}</li>`).join("") + "</ul>";
tips.innerHTML = "<ul>" + programData.tips.map(item => `<li>${item}</li>`).join("") + "</ul>";

modal.style.display = "flex";
}

function closeModal() {
document.getElementById("programModal").style.display = "none";
}

/* Accordion Toggle */
document.addEventListener("click", function (e) {
if (e.target.classList.contains("accordion-header")) {
const body = e.target.nextElementSibling;
body.style.display = body.style.display === "block" ? "none" : "block";
}
});
53 changes: 27 additions & 26 deletions frontend/js/pr-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
* Includes AI Assist Controls for fine-grained PR generation.
*/

// FIX: Declare aiAssistState on window to avoid re-declaration SyntaxError
// if this script is loaded more than once across pages
if (typeof window.aiAssistState === 'undefined') {
window.aiAssistState = {
creativity: 50,
strictness: 'best-practice',
autoSummarize: true,
autoDetectType: true,
rewriteInput: false,
};
}

document.addEventListener('DOMContentLoaded', () => {
const existingForm = document.getElementById('prGeneratorForm');

Expand Down Expand Up @@ -111,17 +123,6 @@ function getStructureSettings() {
};
}

// ==========================================
// AI Assist State
// ==========================================
const aiAssistState = {
creativity: 50,
strictness: 'best-practice',
autoSummarize: true,
autoDetectType: true,
rewriteInput: false,
};

function getCreativityLabel(value) {
if (value <= 20) return 'Low';
if (value <= 40) return 'Medium-Low';
Expand Down Expand Up @@ -151,7 +152,7 @@ function setupAIAssistControls() {
if (slider && valueLabel) {
const updateSlider = () => {
const val = parseInt(slider.value);
aiAssistState.creativity = val;
window.aiAssistState.creativity = val;
valueLabel.textContent = getCreativityLabel(val);

// Update slider track gradient
Expand All @@ -170,7 +171,7 @@ function setupAIAssistControls() {
btn.addEventListener('click', () => {
btns.forEach(b => b.classList.remove('active'));
btn.classList.add('active');
aiAssistState.strictness = btn.dataset.value;
window.aiAssistState.strictness = btn.dataset.value;
});
});
}
Expand All @@ -180,9 +181,9 @@ function setupAIAssistControls() {
const autoDetect = document.getElementById('autoDetectTypeToggle');
const rewriteInput = document.getElementById('rewriteInputToggle');

if (autoSummarize) autoSummarize.addEventListener('change', () => { aiAssistState.autoSummarize = autoSummarize.checked; });
if (autoDetect) autoDetect.addEventListener('change', () => { aiAssistState.autoDetectType = autoDetect.checked; });
if (rewriteInput) rewriteInput.addEventListener('change', () => { aiAssistState.rewriteInput = rewriteInput.checked; });
if (autoSummarize) autoSummarize.addEventListener('change', () => { window.aiAssistState.autoSummarize = autoSummarize.checked; });
if (autoDetect) autoDetect.addEventListener('change', () => { window.aiAssistState.autoDetectType = autoDetect.checked; });
if (rewriteInput) rewriteInput.addEventListener('change', () => { window.aiAssistState.rewriteInput = rewriteInput.checked; });

// Per-field AI assist buttons
const assistBtns = document.querySelectorAll('.ai-field-assist-btn');
Expand Down Expand Up @@ -219,8 +220,8 @@ async function handleFieldImprove(btn) {
body: JSON.stringify({
text,
fieldName: targetId,
creativity: aiAssistState.creativity,
strictness: aiAssistState.strictness,
creativity: window.aiAssistState.creativity,
strictness: window.aiAssistState.strictness,
}),
});

Expand Down Expand Up @@ -353,11 +354,11 @@ async function handlePRGeneration(submitBtn, previewSection, textarea) {
structureSettings,
// AI Assist parameters
aiAssist: {
creativity: aiAssistState.creativity,
strictness: aiAssistState.strictness,
autoSummarize: aiAssistState.autoSummarize,
autoDetectType: aiAssistState.autoDetectType,
rewriteInput: aiAssistState.rewriteInput,
creativity: window.aiAssistState.creativity,
strictness: window.aiAssistState.strictness,
autoSummarize: window.aiAssistState.autoSummarize,
autoDetectType: window.aiAssistState.autoDetectType,
rewriteInput: window.aiAssistState.rewriteInput,
},
}),
});
Expand Down Expand Up @@ -661,15 +662,15 @@ async function analyzePRStatus() {
if (data.merged) {
statusBadge = `<span class="pr-badge merged">Merged</span>`;
statusText = "This Pull Request has been successfully merged.";
}
}
else if (data.state === "open" && data.draft) {
statusBadge = `<span class="pr-badge draft">Draft</span>`;
statusText = "This PR is currently in draft state.";
}
}
else if (data.state === "open") {
statusBadge = `<span class="pr-badge open">Open</span>`;
statusText = "This PR is open and under review.";
}
}
else {
statusBadge = `<span class="pr-badge closed">Closed</span>`;
statusText = "This PR is closed without merge.";
Expand Down
18 changes: 11 additions & 7 deletions frontend/js/pwa.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,30 @@ if ('serviceWorker' in navigator) {
});
}

let deferredPrompt;
// FIX: Use window.deferredPrompt to avoid re-declaration errors
// if this script is ever executed more than once
if (typeof window.deferredPrompt === 'undefined') {
window.deferredPrompt = null;
}

window.addEventListener('beforeinstallprompt', (e) => {
e.preventDefault();
deferredPrompt = e;
window.deferredPrompt = e;

const showButton = () => {
const btn = document.getElementById('pwa-install-btn');
if (btn) {
btn.style.display = 'inline-flex';
btn.addEventListener('click', () => {
btn.style.display = 'none';
deferredPrompt.prompt();
deferredPrompt.userChoice.then((choiceResult) => {
window.deferredPrompt.prompt();
window.deferredPrompt.userChoice.then((choiceResult) => {
if (choiceResult.outcome === 'accepted') {
console.log('User accepted the install prompt');
} else {
console.log('User dismissed the install prompt');
}
deferredPrompt = null;
window.deferredPrompt = null;
});
});
} else {
Expand All @@ -78,6 +82,6 @@ window.addEventListener('beforeinstallprompt', (e) => {
});

window.addEventListener('appinstalled', () => {
deferredPrompt = null;
window.deferredPrompt = null;
console.log('PWA was installed');
});
});
14 changes: 8 additions & 6 deletions frontend/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,19 @@ function updateThemeIcon(isDark) {

/* ===============================
CURSOR HIGHLIGHT
FIX: Renamed variable from 'cursor' to 'themeCursor' to avoid
conflict with the 'cursor' variable declared in home.js
================================ */

const cursor = document.getElementById('cursor-highlight');
const themeCursor = document.getElementById('cursor-highlight');

if (cursor) {
if (themeCursor) {
document.addEventListener('mousemove', (e) => {
cursor.style.transform = `translate(${e.clientX}px, ${e.clientY}px)`;
cursor.style.opacity = '1';
themeCursor.style.transform = `translate(${e.clientX}px, ${e.clientY}px)`;
themeCursor.style.opacity = '1';
});

document.addEventListener('mouseleave', () => {
cursor.style.opacity = '0';
themeCursor.style.opacity = '0';
});
}
}
Loading