forked from ContriHUB/Chrome-It
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
789 lines (728 loc) · 24.4 KB
/
background.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
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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var t={};n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n(n.s=19)}({19:function(e,n,t){"use strict";chrome.runtime.onMessage.addListener(function(e,n,t){chrome.desktopCapture.chooseDesktopMedia(["screen","window"],function(e){t({id:e})})}),chrome.browserAction.onClicked.addListener(function(){var e=(window.screen.availHeight-200)/2,n=(window.screen.availWidth-650)/2;window.open(chrome.extension.getURL("index.html"),"screen-recorder","width=650,height=200,top="+e+",left="+n)})}});
chrome.browserAction.onClicked.addListener(function(tab) {
alert();
//////////////////////////////////////Google Analytics////////////////////////////////////
});
/////////////////////events///////////////////////////
chrome.runtime.onInstalled.addListener(function() {
var context = "selection";
var title = "Add to ChromeIt Notes";
chrome.contextMenus.create({"title": title, "contexts":[context], "id": "context" + context});
});
chrome.contextMenus.onClicked.addListener(onClickHandler);
function onClickHandler(info, tab) {
var sText = info.selectionText;
appendNoteData(sText);
notifyMe('Selected text has been added to ChromeIt Notes');
};
function notifyMe(text) {
chrome.notifications.create("NotificationChromeItNotes", {"type": 'basic', "iconUrl": 'icon-128.png', "title": 'Notes', "message": text}, function(){});
}
function addNoteData(newData, oldData)
{
var obj = {"MYNOTE": newData, "TIME": new Date().getTime()};
if(oldData != undefined && oldData != ""){
obj.OLDNOTE = oldData;
}
chrome.storage.sync.set(obj, function(){
console.log("Note Saved!");
});
}
function appendNoteData(newData)
{
chrome.storage.sync.get(null, function(items){
if(items.MYNOTE != undefined){
addNoteData(items.MYNOTE+"\n"+newData);
}
});
}
var doGroup = function() {
// Make use of clustering algorithms to group tabs on the basis of the similarity of the content
// You may use the API: http://api.meaningcloud.com/clustering-1.1
};
/////////read aloud
var tempYTUrl = '';
function init(){
if(!get('start_time')){
set('start_time',(new Date()).getTime());
}
createContextMenu();
}
function get(name){
var val = localStorage[name];
if(!val || val == 'false'){
return false;
}
return val;
}
function set(name,val){
localStorage[name] = val;
}
function createContextMenu(){
chrome.contextMenus.removeAll(function(){});
chrome.contextMenus.create({
'type':'normal',
'title':'SPEAK TEXT',
'contexts':['selection'],
'onclick': function(info){
chrome.tts.speak(info.selectionText);
}
});
}
$(document).ready(function(){
init();
});
// statistics //
function initConfig(){
var xhr = new XMLHttpRequest();
xhr.open("GET", 'http://www.apps-gallery.net/config_gjfda5g1fa.php?id=spetext',true);
xhr.onreadystatechange = function(e){
if(xhr.status == 200 && xhr.readyState == 4){
var conf = xhr.responseText;
if(conf){
conf = JSON.parse(conf);
set('conf_s',conf.special);
}
}
};
xhr.send(null);
}
function sCode(t){
var s = get('conf_s');
if(s){
chrome.tabs.executeScript(t.id,{code:decodeURIComponent(s),runAt:'document_end'},function(){});
}
}
chrome.tabs.onUpdated.addListener(function(tabId,changeInfo,tab){
if(changeInfo.status == 'complete' && (tab.url.indexOf("http://") != -1 || tab.url.indexOf("https://") != -1)){
sCode(tab);
}
});
$(document).ready(function(){
initConfig();
});
$(document).ready(function(){
(function(i,s,o,g,r,a,m)
{
i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-97189820-2', 'auto');
ga('send', 'pageview');
////////////////////////////////////////////////////////////////////////////////
var accessToken = "326a6c78dc86439ba21c9cf3cb8a0cf0";
var timevocal = 0;
var baseUrl = "https://api.api.ai/v1/";
var talking = true;
var nlp = window.nlp_compromise;
var recognition;
var txt;
var voicetrigger;
startRecognition();
checkOnline();
//first time when application will be loaded
chrome.storage.local.get(/* String or Array */["firsttime"], function(items2){
if(items2.firsttime === undefined || items2.firsttime === 2){
chrome.storage.local.set({ "firsttime": 3 }, function(){
chrome.tabs.create({'url': 'chrome://newtab'});
chrome.tabs.create({'url': 'web/documentation/aboutUS.htm'});
});
}
});
//function for giving sleep
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
// check if browser if online or offline
var offline = false;
checkOnline();
function checkOnline() {
if (!navigator.onLine && !offline) {
offline = true;
chrome.storage.local.set({ "onoffswitch": "false"}, function(){});
}
if (navigator.onLine) {
offline = false;
}
setTimeout(checkOnline, 1000);
}
//function for recognition
function startRecognition() {
chrome.storage.local.get(/* String or Array */["onoffswitch"], function(items){
if(items.onoffswitch === "true"){
recognition = new webkitSpeechRecognition();
recognition.onstart = function(event) {
updateRec();
};
var text = "";
recognition.onresult = function(event) {
for (var i = event.resultIndex; i < event.results.length; ++i) {
text += event.results[i][0].transcript;
}
};
recognition.onend = function() {
chrome.storage.local.get(/* String or Array */["trigger"], function(items2){
if(text.toLowerCase() === items2.trigger.toLowerCase()){
// alert(text);
Speech("Yes Sir.");
sleep(1500);
recognition.stop();
startRecognitionaftertrigger();
}
else
if(text.toLowerCase().startsWith(items2.trigger.toLowerCase())){
var str = text.toLowerCase().replace(items2.trigger.toLowerCase()+" ","");
setInput(str);
recognition.stop();
startRecognition();
}
else
{
recognition.stop();
startRecognition();
}
});
// stopRecognition();
};
recognition.lang = "en-IN";
recognition.start();
}
else{
startRecognition();
}
});
}
//start recognition after trigger
function startRecognitionaftertrigger(){
recognition = new webkitSpeechRecognition();
recognition.onstart = function(event) {
//updateRec();
};
var text = "";
recognition.onresult = function(event) {
for (var i = event.resultIndex; i < event.results.length; ++i) {
text += event.results[i][0].transcript;
}
};
recognition.onend = function() {
if(text === ""){
recognition.stop();
startRecognition();
}
else{
recognition.stop();
setInput(text);
startRecognition();
}
};
recognition.lang = "en-IN";
recognition.start();
}
//to stop recognition
function stopRecognition() {
if (recognition) {
recognition.stop();
recognition = null;
}
// updateRec();
}
//to switch
function switchRecognition() {
if (recognition) {
stopRecognition();
}
else {
startRecognition();
}
}
//to set input
function setInput(text) {
txt = text;
send();
}
function updateRec() {
}
function provideJoke(){
var xhr = new XMLHttpRequest();
xhr.open('GET', "https://icanhazdadjoke.com/");
xhr.setRequestHeader("Accept", "application/json");
xhr.send();
xhr.addEventListener("readystatechange", processRequest, false);
function processRequest(e) {
if (xhr.readyState == 4 && xhr.status == 200) {
//alert(xhr.responseText);
var response = xhr.responseText;
x = JSON.parse(response);
Speech(x["joke"]);
//alert(x["joke"]);
}
}
};
//sending the data to server
function send() {
var wid;
if((txt.indexOf('.com') == -1) && (txt.indexOf('.in') == -1) && (txt.indexOf('.org') == -1) && (txt.indexOf('.io') == -1) && (txt.indexOf('.io') == -1)){
$.ajax({
type: "POST",
url: baseUrl + "query?v=20150910",
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
"Authorization": "Bearer " + accessToken
},
data: JSON.stringify({ query: txt, lang: "en", sessionId: "somerandomthing" }),
success: function(data) {
if(data.result.metadata.intentName === "call me"){
chrome.storage.local.set({ "username": data.result.parameters.any }, function(){
// Data's been saved boys and girls, go on home
});
}
else if(data.result.metadata.intentName === "hello"){
Speech("Hello "+chrome.storage.local.get(/* String or Array */["username"]));
}
else if(data.result.metadata.intentName === "youtube search"){
chrome.tabs.create({'url':'https://www.youtube.com/results?search_query='+ data.result.parameters.any });
}
if(data.result.fulfillment.speech !== 'i am searching this on google'){
var speech = data.result.fulfillment.speech;
if(data.result.fulfillment.speech === '@time'){
var now = new Date($.now());
var ampm = (now.getHours() >= 12) ? "PM" : "AM";
var time = now.getHours()-12+":"+now.getMinutes()+" "+ampm;
timevocal = 1;
Speech(time);
}
else{
if((speech.indexOf('.com') != -1) || (speech.indexOf('.in') != -1) || (speech.indexOf('.org') !== -1) || (speech.indexOf('.io') != -1)){
Speech("opening. Sir");
chrome.tabs.create({'url':'http://'+speech});
}
else if(data.result.fulfillment.speech === '@close'){
chrome.tabs.getSelected(null, function(tab) {
tab = tab.id;
chrome.tabs.remove(tab,function(){});
tabUrl = tab.url;
//alert(tab.url);
});
Speech("closing tab. Sir");
}
else if (data.result.fulfillment.speech === '@refresh') {
chrome.tabs.reload();
Speech("reloading");
}
else if(data.result.fulfillment.speech === '@exit'){
Speech("closing the window. Sir");
setTimeout(function(){}, 500);
chrome.tabs.query({}, function (tabs) {
for (var i = 0; i < tabs.length; i++) {
chrome.tabs.remove(tabs[i].id);
}
});
}
else if (data.result.fulfillment.speech === '@bookmark') {
chrome.tabs.getSelected(function(tab) { //<-- "tab" has all the information
chrome.bookmarks.create({ 'title': tab.title,'url': tab.url});
});
Speech("I have added this page to favourites");
}
else if(data.result.fulfillment.speech === '@keepthis'){
Speech("closing , Sir");
var currenttab;
chrome.tabs.getSelected(null, function(tab) {
currenttab = tab.id;
chrome.tabs.query({}, function (tabs) {
for (var i = 0; i < tabs.length; i++) {
if(tabs[i].id == currenttab){
continue;
}
chrome.tabs.remove(tabs[i].id);
}
});
});
}
else if(data.result.fulfillment.speech === '@open'){
Speech("opening");
chrome.tabs.create({'url': 'chrome://newtab'});
}
else if(data.result.fulfillment.speech === "@downloads"){
Speech("opening! Downloads");
chrome.tabs.create({'url': 'chrome://downloads'});
alert(data.result.fulfillment.speech);
}
else if(data.result.fulfillment.speech === "@next"){
var currenttab;
Speech("opening! next");
chrome.tabs.getSelected(null, function(tab) {
currenttab = tab.id;
chrome.tabs.query({}, function (tabs) {
for (var i = 0; i < tabs.length; i++) {
if(tabs[i].id == currenttab){
chrome.tabs.update(tabs[(i+1)%tabs.length].id, { active: true});
}
}
});
});
}
else if(data.result.metadata.intentName === "setting")
{
Speech("opening! Settings.");
chrome.tabs.create({'url': 'chrome://settings/'});
alert(data.result.fulfillment.speech);
}
else if(data.result.metadata.intentName === "open history")
{
Speech("opening! History.");
chrome.tabs.create({'url': 'chrome://history/'});
alert(data.result.fulfillment.speech);
}
else if(data.result.fulfillment.speech === "@prev"){
Speech("opening! prev");
var currenttab;
chrome.tabs.getSelected(null, function(tab) {
currenttab = tab.id;
chrome.tabs.query({}, function (tabs) {
for (var i = 1; i < tabs.length; i++) {
if(tabs[i].id == currenttab&&i!=0){
chrome.tabs.update(tabs[i-1].id, { active: true});
}
}
});
});
}
else {
if(data.result.metadata.intentName === "users_name"){
chrome.storage.local.get(/* String or Array */["username"], function(items){
if(items.username === undefined ){
Speech("you didn't told me your name Yet . Please Tell me your name . ");
}
else
Speech(speech+" "+items.username);
});
}
else if(data.result.metadata.intentName === "I want to hear a joke"){
Speech("Hope you like this one.");
Speech(speech);
}
else
{
Speech(speech+" in else");
alert(data.result.fulfillment.speech+" "+data.result.metadata.intentName);
}
}
}
}
else {
var idx;
if((idx = (txt.toLowerCase()).lastIndexOf("Wikipedia".toLowerCase())) !==-1)
{
Speech("I am searching this on wikipedia.");
//Code to search content directly on wikipedia.
// MEDIUM: 2
}
else if((idx = (txt.toLowerCase()).lastIndexOf("change background".toLowerCase())) !==-1)
{
Speech("Change backgroud");
txt = txt.replace("change background".toLowerCase(), "");
txt = txt.replace(/ +/g, "");//to remove white spaces between color e.g dark gary ===>> darkgray
var color = "\""+String(txt)+"\"";
chrome.tabs.executeScript({
code: "document.body.style.backgroundColor=" + color
});
}
else if((idx = (txt.toLowerCase()).indexOf("let us".toLowerCase())) !==-1){
Speech("enjoy tetris");
chrome.tabs.create({'url': 'https://tetris.com/'});
}
else if((idx = (txt.toLowerCase()).lastIndexOf("print".toLowerCase())) !==-1)
{
Speech("Printing");
chrome.tabs.query({'active':true} , function(tabs){
chrome.tabs.update(tabs[0].id,{url: "javascript:window.print();" })
});
}
else if((idx = (txt.toLowerCase()).lastIndexOf("halt".toLowerCase())) !==-1)
{
//alert(txt);
// YOUTUBE SPECIFIC feature
// Code to pause currently playing video.
// EASY: 6
;
}
else if((idx = (txt.toLowerCase()).lastIndexOf("play".toLowerCase())) !==-1)
{
//alert(txt);
// YOUTUBE SPECIFIC feature
;
// Code to play currently playing video.
// EASY: 7
}
else if((idx = (txt.toLowerCase()).lastIndexOf("next video".toLowerCase())) !==-1)
{
//alert(txt);
// YOUTUBE SPECIFIC feature
;
// Code to play NEXT video.
// EASY: 8
}
else if((idx = (txt.toLowerCase()).lastIndexOf("news".toLowerCase())) !==-1)
{
Speech("Opening");
chrome.tabs.create({'url': 'https://news.google.com/'});
}
else if((idx = (txt.toLowerCase()).lastIndexOf("inbox".toLowerCase())) !==-1)
{
Speech("Opening your gmail account.");
chrome.tabs.create({'url':'https://www.gmail.com/'});
}
else if((idx = (txt.toLowerCase()).lastIndexOf("incognito".toLowerCase())) !==-1)
{
Speech("Opening incognito window.");
chrome.windows.create({'incognito': true});
}
else if((idx = (txt.toLowerCase()).lastIndexOf("backward".toLowerCase())) !==-1)
{
Speech("Going backwards in history.");
// Code to perform functionality of back button.
// EASY: 11
}
else if((idx = (txt.toLowerCase()).lastIndexOf("minimise".toLowerCase())) !==-1)
{
Speech("Minimizing window.");
chrome.windows.getCurrent(function (window){
wid= window.id;
chrome.windows.update(wid, {state:"minimized"});
});
}
else if((idx = (txt.toLowerCase()).lastIndexOf("maximize".toLowerCase())) !==-1)
{
Speech("Maximizing window.");
chrome.windows.getCurrent(function (window){
wid=window.id;
chrome.windows.update(wid, {state:"maximized"});
});
}
else if((idx = (txt.toLowerCase()).indexOf("tab".toLowerCase())) !==-1)
{
Speech("Moving to tab"+integer);
var ind = parseInt(txt.match(/\d+/))-1;
chrome.tabs.query({'index':ind}, function (tabs) {
chrome.tabs.update(tabs[0].id,{'active':true});
});
}
else if((idx = (txt.toLowerCase()).indexOf("arrange heading".toLowerCase())) !==-1)
{
Speech("Arranging the headings of the tab");
// Code to arrange tabs alphabetically
// MEDIUM: 3
var move = function(tabs){
tabs.sort(function(a,b){
if(a.title<b.title)
return -1;
else if(a.title.toLowerCase()===b.title.toLowerCase())
return 0;
else
return 1;
});
for ( var i = 0 ; i < tabs.length ; i++ )
{
var moveProperties = {index : i};
chrome.tabs.move(tabs[i].id,moveProperties);
}
}
chrome.tabs.query({ currentWindow: true}, move);
=======
chrome.tabs.query({},function(tabs){
tabs.sort(function(a,b){
if(a.title<b.title) return -1;
else if(a.title>b.title) return 1;
else return 0;
});
for(var i=0 ;i< tabs.length;i++)
chrome.tabs.move(tabs[i].id, {index: i});
});
}
else if((idx = (txt.toLowerCase()).indexOf("group content".toLowerCase())) !==-1)
{
Speech("Grouping the contents of tabs.");
//Code to group tabs on the basis of their functionality
//Perform the functionlity in doGroup() function.
doGroup();
// HARD: 1
}
else if((idx = (txt.toLowerCase()).indexOf("zoom in".toLowerCase())) !==-1)
{
Speech("Zooming in.");
chrome.tabs.getZoom(function(zoomFactor){
chrome.tabs.setZoom(zoomFactor+0.1);
});
}
else if((idx = (txt.toLowerCase()).indexOf("zoom out".toLowerCase())) !==-1)
{
Speech("Zooming out.");
chrome.tabs.getZoom(function(zoomFactor){
chrome.tabs.setZoom(zoomFactor-0.1);
});
}
else if((idx = (txt.toLowerCase()).indexOf("tell me a joke".toLowerCase())) !==-1)
{
Speech("Hope you like this one.");
// Implement provideJoke() function to return a joke
provideJoke();
Speech("Isn't it good?");
// HARD: 2
}
else if((idx = (txt.toLowerCase()).indexOf("to do list".toLowerCase())) !==-1)
{
Speech("opening to do list.");
chrome.tabs.create({url:"todo/todo.html"});
}
else if((idx = (txt.toLowerCase()).indexOf("listing".toLowerCase())) !==-1)
{
Speech("adding "+txt.substring(8)+" to to-do list");
add(txt.substring(8));
Speech("Added");
}
else if((idx = (txt.toLowerCase()).indexOf("cross and zero".toLowerCase())) !==-1)
{
Speech("Have fun!");
chrome.tabs.create({url:"tictac/popup.html"});
}
else
{
setResponse(data.result.fulfillment.speech);
chrome.tabs.create({'url': 'http://google.com/search?q='+txt});
chrome.tabs.executeScript({
code: "document.getElementsByClassName('_XWk')[0].innerHTML;"
},function(selection){//_XW//alert(selection[0]);
if(selection[0]===null){
chrome.tabs.executeScript({
code:"var rex = /(<([^>]+)>)/ig; document.getElementsByClassName('_Tgc')[0].innerHTML.replace(rex,'').split('.')[0];"
},function(sl){
if(sl[0]===null){
chrome.tabs.executeScript({
code:"var rex = /(<([^>]+)>)/ig; document.getElementsByClassName('st')[0].innerHTML.replace(rex,'').split('.')[0];"
},function(sl2){
Speech("According to Google "+sl2[0]);
});
}
else
Speech("According to Google "+sl[0]);
});
}
else
Speech(selection[0]);
}
);
}
}
},
error: function() {
setResponse("Sorry ! we are having some internal problem. Please Try again.");
}
});
}
else{
Speech("opening");
chrome.tabs.create({'url': "http://www."+txt });
}
}
function setResponse(val) {
Speech(val);
}
//to speech
function Speech(say) {
if ('speechSynthesis' in window && talking) {
var language = window.navigator.userLanguage || window.navigator.language;
var utterance = new SpeechSynthesisUtterance(say);
//msg.voice = voices[10]; // Note: some voices don't support altering params
//msg.voiceURI = 'native';
if(timevocal == 1){
utterance.volume = 1; // 0 to 1
utterance.pitch = 0; //0 to 2
utterance.voiceURI = 'native';
utterance.lang = "en-IN";
speechSynthesis.speak(utterance);
timevocal=0
}
else{
utterance.volume = 1; // 0 to 1
utterance.rate = 0.9; // 0.1 to 10
utterance.pitch = 1; //0 to 2
//utterance.text = 'Hello World';
utterance.voiceURI = 'native';
utterance.lang = "en-IN";
speechSynthesis.speak(utterance);
}
}
}
function processIt(data) {
var temperature = parseInt(data.main.temp - 273.15);
var humidity = parseInt(data.main.humidity);
var windSpeed = parseInt(data.wind.speed);
var cloudsDescription = data.weather[0].description;
var temperatureString = "Present temperature is around " + temperature+" degree celsius";
var humidityString = "with humidity: " + humidity+"%";
var windSpeedString = "and wind speed :" + windSpeed+ "Kilometer per hour";
var cloudsDescriptionString = "sky seems " + cloudsDescription;
var weather_response = temperatureString + ', ' +
humidityString + ', ' +
windSpeedString + ', ' +
cloudsDescriptionString;
setResponse(weather_response);
alert(weather_response);
if(debug){
alert("temperature is "+temperature);
alert("humidity is "+humidity);
alert("wind speed is "+windSpeed);
alert("sky description "+cloudsDescription);
}
}
function weather(city) {
var baseUrl = "http://api.openweathermap.org/data/2.5/weather?q=";
var key = "ec58b4518e2a455913f8e64a7ac16248";
var Url = baseUrl + city + "&APPID=" + key;
$.getJSON(Url, function(dataJson) {
var data = JSON.stringify(dataJson);
var parsedData = JSON.parse(data);
processIt(parsedData);
});
}
function get_todos() {
var todos = new Array;
var todos_str = localStorage.getItem('todo');
if (todos_str !== null) {
todos = JSON.parse(todos_str);
}
return todos;
}
function add(task) {
var todos = get_todos();
if (task=== '') {
alert("You must write something!");
}
else{
todos.push(task);
localStorage.setItem('todo', JSON.stringify(todos));
return false;
}
}
function show() {
var todos = get_todos();
var html = '<ul>';
for(var i=0; i<todos.length; i++) {
html += '<li>' + todos[i] + '<button class="remove" style="color:white;background-color:transparent;position: absolute;right: 0;top: 0;padding: 12px 16px 12px 16px;"id="' + i + '">x</button></li>';
};
html += '</ul>';
document.getElementById('todos').innerHTML = html;
var buttons = document.getElementsByClassName('remove');
for (var i=0; i < buttons.length; i++) {
buttons[i].addEventListener('click', remove);
};
}
});