-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
59 lines (48 loc) · 2.32 KB
/
script.js
File metadata and controls
59 lines (48 loc) · 2.32 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
// === DriftLens Mini Insight OS™ Script ===
// This script connects a simple journal reflection input with a Make.com webhook to generate a real-time AI insight.
document.addEventListener('DOMContentLoaded', function () {
const reflectionInput = document.getElementById('reflectionInput');
const generateInsightBtn = document.getElementById('generateInsightBtn');
const insightOutput = document.getElementById('insightOutput');
const insightText = document.getElementById('insightText');
// Replace this with your actual Make.com webhook URL
const MAKE_WEBHOOK_URL = 'https://hook.us2.make.com/yyu85glrlx0m8lwp7lmrc6myqtlx2pqk';
generateInsightBtn.addEventListener('click', async () => {
const reflection = reflectionInput.value.trim();
if (reflection.length < 10) {
insightText.textContent = 'Could you share a little more about what’s on your mind?';
showInsight();
return;
}
generateInsightBtn.textContent = 'Generating Insight...';
generateInsightBtn.disabled = true;
hideInsight();
try {
const response = await fetch(MAKE_WEBHOOK_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ reflection: reflection }),
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const data = await response.json();
insightText.textContent = data && data.insight
? data.insight
: 'The insight couldn’t surface right now. Reflection itself is still meaningful. Try again soon.';
} catch (error) {
console.error('Error fetching insight:', error);
insightText.textContent = 'Something went wrong while generating your insight. Please try again later.';
} finally {
showInsight();
generateInsightBtn.textContent = 'Generate Insight';
generateInsightBtn.disabled = false;
}
});
function showInsight() {
insightOutput.style.display = 'block';
setTimeout(() => { insightOutput.style.opacity = 1; }, 50);
}
function hideInsight() {
insightOutput.style.display = 'none';
insightOutput.style.opacity = 0;
}
});