Created
April 27, 2014 04:59
-
-
Save timothyclemans/11337898 to your computer and use it in GitHub Desktop.
[wearscript] adding to timeline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html style="width:100%; height:100%; overflow:hidden"> | |
<head> | |
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> | |
<script src="https://rawgit.com/Glench/fuzzyset.js/master/lib/fuzzyset.js"></script> | |
<link href='https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700' rel='stylesheet' type='text/css'> | |
<style> | |
body { | |
font-family:roboto; | |
font-weight:100; | |
background:#000; | |
font-size:40px; | |
color:#FFF; | |
width:360px; | |
height:640px; | |
} | |
img { | |
position:absolute; | |
width:640px; | |
height:360px; | |
top:0; | |
left:0; | |
z-index:1; | |
display:none; | |
} | |
p { | |
background-color:rgba(0,0,0,0.5); | |
position:absolute; | |
width:560px; | |
padding:40px; | |
height:280px; | |
top:-40px; | |
left:0; | |
z-index:2; | |
} | |
#datetime { | |
position:absolute; | |
font-size:30px; | |
bottom:40px; | |
right:40px; | |
z-index:3; | |
} | |
ul, li {padding:0;margin:0;} | |
li {display:inline; margin-right:20px;} | |
</style> | |
</head> | |
<body> | |
<img src="" /> | |
<p></p> | |
<div id="datetime"></div> | |
<script> | |
var timeline = {}; | |
function dateTime() { | |
var today = new Date(); | |
var dd = today.getDate(); | |
var mm = today.getMonth()+1; //January is 0! | |
var yyyy = today.getFullYear(); | |
if(dd<10) { | |
dd='0'+dd | |
} | |
if(mm<10) { | |
mm='0'+mm | |
} | |
today = mm+'/'+dd+'/'+yyyy+' '+today.getHours()+':'+today.getMinutes()+':'+today.getSeconds(); | |
return today; | |
} | |
function menu() { | |
$('img').css('display', 'none'); | |
var option_i = 0; | |
var options = ['add', 'view', 'search']; | |
options_html = '<ul>'; | |
for (var i =0;i<options.length;i++) { | |
options_html += '<li id="option_'+i+'">'+options[i]+'</li>'; | |
} | |
options_html += '</ul>'; | |
//WS.log(options_html); | |
$('p').html('Life DVR<br/><br/>'+options_html); | |
$('#option_0').css('background', 'yellow'); | |
$('#option_0').css('color', '#000'); | |
WS.gestureCallback('onGesture', function (name) { | |
if (name == 'TAP') { | |
timeline[options[option_i]](); | |
} else if (name == 'SWIPE_RIGHT') { | |
option_i += 1; | |
if (option_i == options.length) { | |
option_i = 0; | |
} | |
$('li').css('background', '#000'); | |
$('li').css('color', '#FFF'); | |
$('#option_'+option_i).css('background', 'yellow'); | |
$('#option_'+option_i).css('color', '#000'); | |
} else if (name == 'SWIPE_LEFT') { | |
option_i -= 1; | |
if (option_i == -1) { | |
option_i = options.length - 1; | |
} | |
$('li').css('background', '#000'); | |
$('li').css('color', '#FFF'); | |
$('#option_'+option_i).css('background', 'yellow'); | |
$('#option_'+option_i).css('color', '#000'); | |
} | |
}); | |
} | |
timeline.add = function() { | |
WS.speechRecognize('What is happening?', function (speechData) { | |
WS.cameraOn(.15, 180, 320, function (imageData) { | |
WS.cameraOff(); | |
var item = [speechData, imageData, dateTime()]; | |
eval('var arr = '+localStorage['timeline']); | |
arr.unshift(item); | |
localStorage['timeline'] = JSON.stringify(arr); | |
menu(); | |
WS.log(JSON.stringify(localStorage['timeline'])); | |
}); | |
}); | |
} | |
timeline.view = function() { | |
var i = 0; | |
//WS.log('var arr = '+localStorage['timeline']); | |
eval('var arr = '+localStorage['timeline']); | |
var item = arr[i]; | |
$('p').text(item[0]); | |
$('img').attr('src', 'data:image/jpg;base64,' + item[1]); | |
$('img').show(); | |
$('#datetime').text(item[2]); | |
WS.gestureCallback('onGesture', function (name) { | |
if (name == 'SWIPE_RIGHT') { | |
i += 1; | |
eval('var timelinearr = '+localStorage['timeline']); | |
if (i == timelinearr.length) { | |
i = 0; | |
} | |
eval('var item = '+localStorage['timeline']+'[i]'); | |
$('p').text(item[0]); | |
$('img').attr('src', 'data:image/jpg;base64,' + item[1]); | |
$('img').show(); | |
$('#datetime').text(item[2]); | |
} else if (name == 'SWIPE_LEFT') { | |
i -= 1; | |
eval('var timelinearr = '+localStorage['timeline']); | |
if (i == -1) { | |
i = timelinearr.length - 1; | |
} | |
eval('var item = '+localStorage['timeline']+'[i]'); | |
$('p').text(item[0]); | |
$('img').attr('src', 'data:image/jpg;base64,' + item[1]); | |
$('img').show(); | |
} else if (name == 'TWO_TAP') { | |
menu(); | |
} | |
}); | |
} | |
timeline.search = function() { | |
WS.speechRecognize('What are you searching for?', function(data) { | |
var i = 0; | |
//WS.log('var arr = '+localStorage['timeline']); | |
eval('var arr = '+localStorage['timeline']); | |
var k = {}; | |
for (var j=0;j<arr.length;j++) { | |
k[arr[j][0]] = arr[j]; | |
} | |
var fuzzy_names = FuzzySet(Object.keys(k)); | |
WS.log(JSON.stringify(Object.keys(k))); | |
// var fuzzy_match = fuzzy_names.get(data); | |
WS.log('fuzzy names: '+fuzzy_names.get(data)); | |
if (fuzzy_names.get(data) == null) { | |
WS.say('No results'); | |
menu(); | |
} | |
arr2 = []; | |
for (var m=0;m<fuzzy_names.get(data).length;m++) { | |
arr2.push(k[fuzzy_names.get(data)[m][1]]); | |
} | |
var item = arr2[i]; | |
$('p').text(item[0]); | |
$('img').attr('src', 'data:image/jpg;base64,' + item[1]); | |
$('img').show(); | |
$('#datetime').text(item[2]); | |
WS.gestureCallback('onGesture', function (name) { | |
if (name == 'SWIPE_RIGHT') { | |
i += 1; | |
if (i == arr2.length) { | |
i = 0; | |
} | |
item = arr2[i]; | |
$('p').text(item[0]); | |
$('img').attr('src', 'data:image/jpg;base64,' + item[1]); | |
$('img').show(); | |
$('#datetime').text(item[2]); | |
} else if (name == 'SWIPE_LEFT') { | |
i -= 1; | |
eval('var timelinearr = '+localStorage['timeline']); | |
if (i == -1) { | |
i = arr2.length - 1; | |
} | |
item = arr2[i]; | |
$('p').text(item[0]); | |
$('img').attr('src', 'data:image/jpg;base64,' + item[1]); | |
$('img').show(); | |
} else if (name == 'TWO_TAP') { | |
menu(); | |
} | |
}); | |
}); | |
} | |
function server() { | |
WS.log('connected to server'); | |
} | |
function main() { | |
//localStorage['timeline'] = '[]'; | |
if (localStorage["timeline"] == undefined) { | |
localStorage['timeline'] = '[]'; | |
} | |
//WS.log(JSON.stringify(localStorage)); | |
if (WS.scriptVersion(1)) return; | |
WS.serverConnect('{{WSUrl}}', server); | |
WS.liveCardCreate(false, 0.5); | |
menu(); | |
} | |
window.onload = main; | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"name":"Example"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment