-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
180 lines (160 loc) · 6.29 KB
/
index.js
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// random ad
let adTexts = [
"Do you know the likelihood that your colleague has a common hobby with you is 73.6%? Of course, you don't know because we made up this data. But have a try and ask them, maybe you'll find someone...",
"When you take the time to get to know someone on a personal level, you may be more likely to trust each other's intentions and actions. This can lead to a more supportive and productive work environment.",
"When people feel comfortable and connected with their colleagues, they may be more engaged and motivated in their work.",
"Time to expand your professional network! When you get to know people outside of your immediate team, you may learn about new projects, opportunities, or career paths that you wouldn't have otherwise known about."
];
function getRandomAdText() {
var randomIndex = Math.floor(Math.random() * adTexts.length);
var adText = adTexts[randomIndex];
var textStyles = [
{
styleClass: 'cute'
},
{
styleClass: 'elegant'
},
{
styleClass: 'playful'
},
{
styleClass: 'sophisticated'
},
{
styleClass: 'quirky'
}
];
var randomStyle = textStyles[Math.floor(Math.random() * textStyles.length)];
return '<span class="' + randomStyle.styleClass + '">' + adText + '</span>';
}
window.onload = function() {
var adText = getRandomAdText();
document.getElementById("random_opener").innerHTML = adText;
animateAd();
};
function animateAd() {
var adContainer = document.getElementById('ad-container');
adContainer.classList.add('animate');
}
//character initial setup
const characters = [{
name: 'Jane',
gender: 'female',
relationship: 'colleague',
interests: ['hiking', 'cats'],
hates: 'politics',
talking_context: 'at coffee break',
spark_for: 'casual chat starter',
sell_my: 'joke about job',
next_step: 'spend relaxed lunchtime',
other_info: 'has a daughter in primary school',
my_goal: 'get more information on how other people are performing',
tone: 'casual'
},{
name: 'John',
gender: 'male',
relationship: 'people with the same passion as me',
interests: ['footabll', 'dogs'],
hates: 'social',
talking_context: 'in washroom',
spark_for: 'personal greeting',
sell_my: 'my passion and knowledge about sports',
next_step: 'join my project team',
other_info: 'have a lot of knowledge on debugging',
my_goal: 'work with him and learn from his expereience',
tone: 'relaxed and considerate'
},
{
name:'Jose',
gender: 'neutral',
relationship: 'mentor',
interests: ['investment', 'cars'],
hates: 'travel',
talking_context: 'meeting',
spark_for: 'opening remark for team presentation',
sell_my: 'the quality and high aim of our team work',
next_step: 'give positive comments',
other_info: 'forgets things easily unless reminded repeatedly',
my_goal: 'get higher marks in performance evaluation',
tone: 'confident and ambitious'
}, {
name:'Jess',
gender: 'female',
relationship: 'LinkedIn contact',
interests: ['coding', 'start-ups'],
hates: 'gossip',
talking_context: 'online',
spark_for: 'LinkedIn message',
sell_my: 'my euthusiasm on work',
next_step: 'have a coffee chat',
other_info: 'likes to keep distance until she finds common interest with others',
my_goal: 'gather some information about her department and business, and know if they may have head count for hiring next quarter',
tone: 'respectful and passionate'
}
]
// based on the selected character to generate spark
const gridCards = document.querySelectorAll('.grid_card');
function generateMessage(characterIndex) {
const character = characters[characterIndex];
return `${character.name} is ${character.gender} and is my ${character.relationship}.
${character.name} is interested in ${character.interests}.
Normally, ${character.name} hates ${character.hates}.
In addition, ${character.name} ${character.other_info}.
Today I will meet and greet this person ${character.talking_context}. I hope to ${character.goal}. Based on the given information, if you were me, what would you say in ${character.spark_for} to impress the person about ${character.sell_my}, and ${character.next_step} with me? Please use ${character.tone} tone. Please limit your response to less than a hundred words`;
}
function Loading_spark() {
const Loading_spark = document.getElementById('response-container');
Loading_spark.innerHTML = '...';
const animationInterval = setInterval(() => {
Loading_spark.innerHTML += '.';
}, 500);
return animationInterval;
}
function getResponse(message) {
const api_spark = document.getElementById('response-container');
api_spark.innerHTML = '';
const animationInterval = Loading_spark();
fetch('http://localhost:3000/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ message }),
})
.then(response => response.json())
.then(data => {
clearInterval(animationInterval);
const responseDiv = document.createElement('div');
responseDiv.classList.add('response-context')
responseDiv.innerHTML = data.message;
api_spark.innerHTML = '';
api_spark.appendChild(responseDiv);
})
.catch(error => console.error(error));
}
gridCards.forEach((card, i) => {
card.addEventListener('click', () => {
const message = generateMessage(i);
getResponse(message);
});
});
//dark mode
const darkModeButton = document.getElementById('mymode');
const htmlRoot = document.querySelector('html');
darkModeButton.addEventListener('click', () => {
if (htmlRoot.getAttribute('data-bs-theme') === 'dark') {
htmlRoot.removeAttribute('data-bs-theme');
darkModeButton.textContent = 'Dark mode'
} else {
htmlRoot.setAttribute('data-bs-theme', 'dark');
darkModeButton.textContent = 'Light mode'
}
});
//jump to login page
const $tologins = document.querySelectorAll('.tologin');
$tologins.forEach($tologin => {
$tologin.addEventListener('click', () => {
window.location.href = 'login.html';
});
});