-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathtodo.html
114 lines (98 loc) · 4.26 KB
/
todo.html
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
<!doctype html>
<html lang="en" data-framework="javascript">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Speech ToDo App</title>
<link rel="stylesheet" href="css/base.css">
</head>
<body>
<section id="todoapp">
<header id="header">
<h1>My To Do List</h1>
</header>
<section id="main">
<input id="toggle-all" type="checkbox">
<label for="toggle-all">Mark all as complete</label>
<ul id="todo-list">
<li id="activate-speech-recognition">
<div class="view"><input class="toggle" type="checkbox"><label>Activate Speech Recognition</label></button></div>
</li>
</ul>
</section>
</section>
<footer id="info">
<p>© 2013 <a href="https://www.talater.com/">Tal Ater</a>. Design based on <a href="http://todomvc.com">TodoMVC</a>, and used under <a href="http://opensource.org/licenses/MIT">MIT license</a></p>
</footer>
<script>
"use strict";
var newwindow;
var speechActivator = document.getElementById('activate-speech-recognition');
var SpeechRecognitionHotness = function() {
// the following code opens the popunder... based on https://github.com/tuki/js-popunder
newwindow=window.open('popup.html','listener','height=293,width=714');
newwindow.blur();
newwindow.opener.window.focus();
window.self.window.focus();
window.focus();
var nothing = '';
var ghost = document.createElement("a");
ghost.href = "data:text/html,<scr"+nothing+"ipt>window.close();</scr"+nothing+"ipt>";
document.getElementsByTagName("body")[0].appendChild(ghost);
var clk = document.createEvent("MouseEvents");
clk.initMouseEvent("click", false, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null);
ghost.dispatchEvent(clk);
ghost.parentNode.removeChild(ghost);
//activate legit SpeechRecognition
var recognition = new webkitSpeechRecognition();
recognition.maxAlternatives = 1;
recognition.continuous = true;
recognition.lang = 'en-US';
// once you have permission to capture speech.
recognition.onstart = function(event) {
speechActivator.className = "completed";
}
// when speech results are received.
recognition.onresult = function(event) {
//analyze the text received
var transcript = event.results[event.resultIndex][0].transcript.trim();
window.console.log(transcript);
if (transcript.indexOf('to do') === 0) {
addTodo(transcript.substr(6));
// in case my accent is a problem
} else if (transcript.indexOf('22') === 0) {
addTodo(transcript.substr(3));
} else if (transcript.indexOf('how to do') === 0) {
addTodo(transcript.substr(10));
} else if (transcript.indexOf('do') === 0) {
addTodo(transcript.substr(3));
} else if (transcript.indexOf('turn off') !== -1) {
//stop listening legitly and activate listening in the background.
recognition.abort();
newwindow.startListening();
}
};
// start listening
recognition.start();
};
var addTodo = function(todo) {
todo = todo.trim();
if (todo.length === 0) return false;
var newTodo = document.createElement('li');
newTodo.innerHTML = '<li><div class="view"><input class="toggle" type="checkbox"><label>'+todo+'</label></button></div></li>';
document.getElementById('todo-list').appendChild(newTodo);
};
speechActivator.addEventListener('click', SpeechRecognitionHotness, false);
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-24775009-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>