-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
465 lines (399 loc) · 13.5 KB
/
Copy pathcontent.js
File metadata and controls
465 lines (399 loc) · 13.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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
function getText(){
return document.body.innerText
}
function logSadness()
{
var quant;
chrome.storage.local.get('sadNum', function(item) {
quant = item.sadNum;
if (quant == null)
{
quant = 1;
chrome.storage.local.set({'sadNum': quant});
}
else if (quant == 11)
{
quant = 1;
chrome.storage.local.set({'sadNum': quant})
}
else
{
quant++;
chrome.storage.local.set({'sadNum': quant});
}
alert(quant - 1)
});
}
function makeYouHappy()
{
chrome.storage.local.get('sadNum', function(item) {
if (item.sadNum >= 8)
{
modal5.open();
}
else
{
modal.open();
}
});
}
//tingle modal
// instantiate new modal
var modal = new tingle.modal({
footer: true,
stickyFooter: false,
closeMethods: ['overlay', 'button', 'escape'],
closeLabel: "Close",
cssClass: ['custom-class-1', 'custom-class-2'],
onOpen: function() {
console.log('modal open');
},
onClose: function() {
console.log('modal closed');
},
beforeClose: function() {
return true; // close the modal
}
});
// set content
var nameToOutput = "";
chrome.storage.local.get('submitted', function(item) {
if (item.submitted != null)
{
nameToOutput = item.submitted.toString();
}
});
modal.setContent('<h1>hey! we noticed you might be feeling a bit stressed out.</h1>');
//modal.setContent(nameToOutput);
//document.getElementById('dispName').innerHTML = nameToOutput;
// add a button
modal.addFooterBtn('yeah, a bit', 'tingle-btn tingle-btn--primary', function() {
// here goes some logic
modal.close();
modal2.open();
});
// add another button
modal.addFooterBtn("nah it's chill, just reading some heavy content", 'tingle-btn tingle-btn--danger', function(){
// here goes some logic
modal.close();
chrome.storage.local.get('sadNum', function(item) {
if (item.sadNum >= 6)
{
modal5.open();
}
})
});
// mood options
var modal2 = new tingle.modal({
footer: true,
stickyFooter: false,
closeMethods: ['overlay', 'button', 'escape'],
closeLabel: "Close",
cssClass: ['custom-class-1', 'custom-class-2'],
onOpen: function() {
console.log('modal open');
},
onClose: function() {
console.log('modal closed');
},
beforeClose: function() {
// here's goes some logic
// e.g. save content before closing the modal
return true; // close the modal
return false; // nothing happens
}
});
modal2.setContent('<h1> let\'s make a playlist to help you out. how are you feeling right now? </h1>');
// add a button
modal2.addFooterBtn('sad', 'tingle-btn tingle-btn--primary', function() {
// here goes some logic
modal2.close();
modal3.open();
});
// add another button
modal2.addFooterBtn('anxious', 'tingle-btn tingle-btn--default', function() {
// here goes some logic
modal2.close();
openInNewTab('https://open.spotify.com/embed?uri=spotify:user:spotify:playlist:' + choosePlaylist('anxiousFear')[0]);
});
// add a button
modal2.addFooterBtn('angry', 'tingle-btn tingle-btn--primary', function() {
// here goes some logic
modal2.close();
modal4.open();
});
// add another button
modal2.addFooterBtn('maybe later', 'tingle-btn tingle-btn--default', function() {
// here goes some logic
modal2.close();
//express concern bc have visited lots of sad pages
var quant;
chrome.storage.local.get('sadNum', function(item) {
if (item.sadNum > 5)
{
modal5.open();
}
});
});
// further options for sad
var modal3 = new tingle.modal({
footer: true,
stickyFooter: false,
closeMethods: ['overlay', 'button', 'escape'],
closeLabel: "Close",
cssClass: ['custom-class-1', 'custom-class-2', 'custom-class-3'],
onOpen: function() {
console.log('modal open');
},
onClose: function() {
console.log('modal closed');
},
beforeClose: function() {
// here's goes some logic
// e.g. save content before closing the modal
return true; // close the modal
return false; // nothing happens
}
});
modal3.setContent('<h1>what would you like to do?</h1>');
// add a button
modal3.addFooterBtn('cheer up!', 'tingle-btn tingle-btn--primary', function() {
// here goes some logic
openInNewTab('https://open.spotify.com/embed?uri=spotify:user:spotify:playlist:' + choosePlaylist('happy')[0]);
modal3.close();
});
// add another button
modal3.addFooterBtn('feel it out', 'tingle-btn tingle-btn--default', function() {
// here goes some logic
openInNewTab('https://open.spotify.com/embed?uri=spotify:user:spotify:playlist:' + choosePlaylist('sad')[0]);
modal3.close();
});
// futher options for angry
var modal4 = new tingle.modal({
footer: true,
stickyFooter: false,
closeMethods: ['overlay', 'button', 'escape'],
closeLabel: "Close",
cssClass: ['custom-class-1', 'custom-class-2'],
onOpen: function() {
console.log('modal open');
},
onClose: function() {
console.log('modal closed');
},
beforeClose: function() {
// here's goes some logic
// e.g. save content before closing the modal
return true; // close the modal
}
});
modal4.setContent('<h1>what would you like to do?</h1>');
// add a button
modal4.addFooterBtn('calm down', 'tingle-btn tingle-btn--primary', function() {
// here goes some logic
openInNewTab('https://open.spotify.com/embed/user/spotify/playlist/' + choosePlaylist('anxiousFear')[0]);
modal4.close();
});
// add another button
modal4.addFooterBtn('let it out', 'tingle-btn tingle-btn--default', function() {
// here goes some logic
openInNewTab('https://open.spotify.com/embed?uri=spotify:user:spotify:playlist:' + choosePlaylist('angry')[0]);
modal4.close();
});
// if visited several sad pages
var modal5 = new tingle.modal({
footer: true,
stickyFooter: false,
closeMethods: ['overlay', 'button', 'escape'],
closeLabel: "Close",
cssClass: ['custom-class-1', 'custom-class-2'],
onOpen: function() {
console.log('modal open');
},
onClose: function() {
console.log('modal closed');
},
beforeClose: function() {
// here's goes some logic
// e.g. save content before closing the modal
return true; // close the modal
}
});
modal5.setContent('<h1>you\'ve been looking at quite a lot of heavy content and we\'re getting worried. please reach out to a mental health hotline if you\'re struggling.</h1>');
// add a button
modal5.addFooterBtn('call a mental health hotline - teenline', 'tingle-btn tingle-btn--primary', function() {
// here goes some logic
callHotline();
modal5.close();
});
modal5.addFooterBtn('call a family member', 'tingle-btn tingle-btn--primary', function() {
// here goes some logic
modal5.close();
});
modal5.addFooterBtn('call a friend', 'tingle-btn tingle-btn--primary', function() {
// here goes some logic
modal5.close();
});
function callHotline()
{
$(function() {
const accountSid = 'AC789d4c412fd6578d774753707937db8b';
const authToken = 'b9b64a1dacafd3f1a8b8408ba5513e7f';
var body = {
'Url': 'https://handler.twilio.com/twiml/EH49f3c8b695ed4c888a72d8d799e5bd84',
'To': '+19252095421',
'From': '+18186167686'
};
var encoded = btoa(`${accountSid}:${authToken}`);
$.ajax({
url: `https://api.twilio.com/2010-04-01/Accounts/${accountSid}/Calls.json`,
beforeSend: function(xhrObj){
// Request headers
xhrObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhrObj.setRequestHeader("Authorization",`Basic ${encoded}`);
},
type: "POST",
// Request body
data: body,
})
.done(function(data){
console.log(data);
})
.fail(function(){
});
});
}
function sentimentAnalysis()
{
$(function() {
var params = {
// Request parameters
};
var docs = {'id' : '1', 'language': 'en', 'text' : getText()};
//content size should be min between size and 5100
var end = getText().toString().length;
if (end > 5000)
{
end = 5000;
}
//display number of words to analyse
//alert(end);
var words = getText().toString().substring(0, end);
//display words to be analysed
//alert(words);
// let word = 'I am so happy!!!!';
/* let documents = { 'documents': [
{ 'id': '1', 'language': 'en', 'text': 'I really enjoy the new XBox One S. It has a clean look, it has 4K/HDR resolution and it is affordable.' },
{ 'id': '2', 'language': 'es', 'text': 'Este ha sido un dia terrible, llegué tarde al trabajo debido a un accidente automobilistico.' },
{ 'id': '3', 'language': 'en', 'text': word}
]};*/
let blahblah = { 'documents': [
{ 'id': '1', 'language': 'en', 'text': words}]};
let body = JSON.stringify(blahblah);
//let body = JSON.stringify(documents);
$.ajax({
url: "https://westcentralus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment?" + $.param(params),
beforeSend: function(xhrObj){
// Request headers
xhrObj.setRequestHeader("Content-Type","application/json");
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","fcb5a3418b80487ebd1c94d899ca8b65 ");
},
type: "POST",
// Request body
data: body,
})
.done(function(data) {
alert("success");
console.log(data);
alert(data.documents[0].score);
if (data.documents[0].score < 0.2)
{
makeYouHappy();
logSadness();
}
//else youre already reading happy stuff and don't need to be reminded to be happy!
})
.fail(function() {
alert("error");
});
});
}
//alert(getText())
//var toggleOnOff = getToggleOnOff();
if(true){
console.log("start sentiment analysis");
sentimentAnalysis();
}
function openInNewTab(url) {
var win = window.open(url, '_blank', 'width=300,height=300,frameborder=0,allowtransparency=true,allow=encrypted-media');
win.focus();
}
//all the playlist IDs and titles
var anxiousFearPlaylists = ['37i9dQZF1DX4sWSpwq3LiO', '37i9dQZF1DX3Ogo9pFvBkY', '37i9dQZF1DXcCnTAt8CfNe',
'37i9dQZF1DWU0ScTcjJBdj', '37i9dQZF1DX3PIPIT6lEg5', '37i9dQZF1DX1s9knjP51Oa', '37i9dQZF1DXa9xHlDa5fc6',
'37i9dQZF1DWTkxQvqMy4WW', '37i9dQZF1DX8ymr6UES7vc', '37i9dQZF1DWZqd5JICZI0u'];
var happyPlaylists = ['37i9dQZF1DX3rxVfibe1L0', '37i9dQZF1DX7KNKjOK0o75', '37i9dQZF1DWYBO1MoTDhZI',
'37i9dQZF1DXdPec7aLTmlC', '37i9dQZF1DWSkMjlBZAZ07', '37i9dQZF1DX9XIFQuFvzM4', '37i9dQZF1DX2sUQwD7tbmL',
'37i9dQZF1DX0UrRvztWcAU', '37i9dQZF1DXaK0O81Xtkis', '37i9dQZF1DWSf2RDTDayIx'];
var sadPlaylists = ['37i9dQZF1DX3YSRoSdA634', '37i9dQZF1DWSqBruwoIXkA', '37i9dQZF1DWVV27DiNWxkR'];
var angryPlaylists = ['37i9dQZF1DWU6kYEHaDaGA', '37i9dQZF1DWWJOmJ7nRx0C', '5s7Sp5OZsw981I2OkQmyrz',
'37i9dQZF1DWTcqUzwhNmKv', '37i9dQZF1DWXIcbzpLauPS'];
var anxiousFearPlaylistsTitles = ['Peaceful Piano', 'Ambient Chill', 'Musical Therapy', 'Relax & Unwind',
'Microtherapy', 'Calm Vibes', 'License to Chill', 'Chillin on a Dirt Road', 'Rain Sounds', 'Peaceful Meditation'];
var happyPlaylistsTitles = ['Mood Booster', 'Have a Great Day!', 'Good Vibes', 'Happy Hits', 'Happy Folk', 'Feelin Good',
'Feel-Good Indie Rock', 'Wake Up Happy', 'Happy Chill Good Time Vibes', 'Happy Beats'];
var sadPlaylistsTitles = ['Life Sucks', 'Down in the Dumps', 'Melancholia'];
var angryPlaylistsTitles = ['Unleash the Fury', 'Rock Hard', 'Rage Quit', 'Kickass Metal', 'Metalcore'];
function choosePlaylist(mood) {
var playlist;
var title;
if (mood == 'anxiousFear'){
var index = Math.floor(Math.random() * anxiousFearPlaylists.length);
playlist = anxiousFearPlaylists[index];
title = anxiousFearPlaylistsTitles[index];
}
else if (mood == 'happy'){
var index = Math.floor(Math.random() * happyPlaylists.length);
playlist = happyPlaylists[index];
title = happyPlaylistsTitles[index];
}
else if (mood == 'sad'){
var index = Math.floor(Math.random() * sadPlaylists.length);
playlist = sadPlaylists[index];
title = sadPlaylistsTitles[index];
}
else if (mood == 'angry'){
var index = Math.floor(Math.random() * angryPlaylists.length);
playlist = angryPlaylists[index];
title = angryPlaylistsTitles[index];
}
return [playlist, title];
}
/*
function addButton()
{
var buttonnode = document.createElement("input");
buttonnode.setAttribute('type', 'button');
buttonnode.setAttribute('name', 'sal');
buttonnode.setAttribute('value', 'sal');
var main = document.getElementById("main");
var button = document.createElement("button");
var text = document.createTextNode("test");
buttonnode.appendChild(text);
main.prepend(buttonnode);
buttonnode.onclick = Hi;
}
addButton()
function button()
{
$("body").wrapAll("<div class='wrapper'></div>");
$("body").prepend("<div class=''></div>");
}
/*
function addBanner()
{
$("body").wrapAll("<div class='oldBody'></div>");
$("body").prepend("<div id='banner'></div>");
}
addBanner()
*/