-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
146 lines (129 loc) · 6.03 KB
/
script.js
File metadata and controls
146 lines (129 loc) · 6.03 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
// Quotes of the day
const quotes = [
"'Happiness can be found even in the darkest of times, if one only remembers to turn on the light.' – J.K. Rowling",
"'Do what you can, with what you have, where you are.' – Theodore Roosevelt",
"'Not all storms come to disrupt your life, some come to clear your path.' – Unknown",
"'The only way to do great work is to love what you do.' – Steve Jobs",
"'Believe you can and you're halfway there.' – Theodore Roosevelt",
"'Sometimes you will never know the value of a moment until it becomes a memory.' – Dr. Seuss",
"'Every day may not be good… but there’s something good in every day.' – Alice Morse Earle",
"'The wound is the place where the Light enters you.' – Rumi",
"'Vulnerability is not winning or losing; it’s having the courage to show up and be seen.' – Brené Brown",
"'You are the sky. Everything else—it’s just the weather.' – Pema Chödrön",
"'Healing is not linear.' – Unknown",
"'What you hide, you carry. What you express, you let go.' – Unknown",
"'Owning our story can be hard but not nearly as difficult as spending our lives running from it.' – Brené Brown",
"'It’s okay not to be okay; it’s just not okay to stay that way.' – Perry Noble",
"'Your feelings are valid. You don’t need a reason to feel what you feel.' – Unknown",
"'The deepest pain sometimes empowers the greatest growth.' – Unknown",
"'To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment.' – Ralph Waldo Emerson",
"'Do not let the shadows of your past darken the doorstep of your future.' – Unknown",
"'The soul usually knows what to do to heal itself. The challenge is to silence the mind.' – Caroline Myss",
"'Maybe the journey isn’t so much about becoming anything. Maybe it’s about unbecoming everything that isn’t really you.' – Paulo Coelho",
"'I am not what happened to me, I am what I choose to become.' – Carl Jung",
"'You don't have to see the whole staircase, just take the first step.' – Martin Luther King Jr.",
"'Talk to yourself like you would to someone you love.' – Brené Brown",
"'Feelings are just visitors, let them come and go.' – Mooji",
"'Sometimes the bravest thing you can do is just show up.' – Unknown",
"'Quiet the mind, and the soul will speak.' – Ma Jaya Sati Bhagavati",
"'Self-care is how you take your power back.' – Lalah Delia"
];
// Display Quote of the Day
function displayQuoteOfTheDay() {
const today = new Date();
const dayOfYear = Math.floor(
(today - new Date(today.getFullYear(), 0, 0)) / 1000 / 60 / 60 / 24
);
const quoteIndex = dayOfYear % quotes.length;
document.querySelector(".quote-of-the-day").innerText = quotes[quoteIndex];
}
// Show AI response in the frontend
function setResponse(text) {
const responseArea = document.querySelector(".response-area");
responseArea.classList.remove("new-response");
void responseArea.offsetWidth; // trigger reflow
responseArea.innerText = text;
responseArea.classList.add("new-response");
}
// On page load
window.onload = () => {
displayQuoteOfTheDay();
};
// Copy UPI ID to clipboard
function copyUPI() {
const upiId = "saha1943@fam";
navigator.clipboard.writeText(upiId).then(() => {
const copyBtn = document.querySelector('.copy-btn');
const originalText = copyBtn.innerHTML;
copyBtn.innerHTML = '✅ Copied!';
copyBtn.style.background = '#4CAF50';
setTimeout(() => {
copyBtn.innerHTML = originalText;
copyBtn.style.background = '';
}, 2000);
}).catch(err => {
console.error('Failed to copy: ', err);
alert('Failed to copy UPI ID. Please copy manually: ' + upiId);
});
}
// Global conversation history
let conversationHistory = [];
// Handle Contribute Now button click
function contributeNow() {
const upiId = "saha1943@fam";
const contributeBtn = document.getElementById('contribute-btn');
const originalText = contributeBtn.innerHTML;
navigator.clipboard.writeText(upiId).then(() => {
contributeBtn.innerHTML = '✅ UPI ID Copied!';
contributeBtn.style.background = 'linear-gradient(135deg, #4CAF50, #45a049)';
setTimeout(() => {
contributeBtn.innerHTML = originalText;
contributeBtn.style.background = '';
}, 3000);
}).catch(err => {
console.error('Failed to copy: ', err);
// Fallback: try to open UPI app or show alert
const upiUrl = `upi://pay?pa=${upiId}&pn=MindSpace&cu=INR`;
window.open(upiUrl, '_blank');
alert('UPI ID copied to clipboard: ' + upiId + '\n\nIf copy failed, you can manually copy: ' + upiId);
});
}
// Clear conversation history
function clearConversation() {
conversationHistory = [];
const responseArea = document.querySelector(".response-area");
responseArea.innerText = "Your AI companion's thoughts will appear here 💭";
alert("Conversation cleared! Ready for a fresh start. 🌱");
}
// Send message to backend AI
async function sendMessage() {
const inputBox = document.querySelector(".mood-box");
const message = inputBox.value.trim();
const responseArea = document.querySelector(".response-area");
if (!message) {
alert("Write something first 💜");
return;
}
// Add user message to history
conversationHistory.push({ role: "user", content: message });
inputBox.value = "";
responseArea.innerText = "💭 MindSpace is thinking...";
try {
const res = await fetch("https://backend-snowy-sigma-85.vercel.app/api/chat", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
message: message,
history: conversationHistory.slice(-10) // Send last 10 messages to avoid token limits
})
});
const data = await res.json();
const aiReply = data.reply || "🤖 No reply from AI";
// Add AI response to history
conversationHistory.push({ role: "assistant", content: aiReply });
setResponse(aiReply);
} catch (err) {
console.error("Error contacting backend:", err);
setResponse("⚠️ Error: Could not reach AI");
}
}