Created
March 26, 2014 08:43
-
-
Save timothyclemans/9778985 to your computer and use it in GitHub Desktop.
[wearscript] Drug lookup
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
<!-- drug lookup --> | |
<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://raw.github.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'> | |
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.0/zepto.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>--> | |
<style> | |
/* recover from old-browser styling */ | |
.oldbl {display: block !important;} | |
.oldin {display: inline !important;} | |
img.pic {display: block !important;} | |
.ahem, .skipper, #aboutsite, #aboutsite * {display: none !important;} | |
/* NS6.x-specific fix(es) */ | |
*|*:-moz-list-bullet, *|*:-moz-list-number {font-size: 1em;} | |
/* IE image scaling fix */ | |
img {-ms-interpolation-mode: bicubic;} | |
/* misc */ | |
#present {z-index: 100000 !important;} | |
/* | |
http://meyerweb.com/eric/tools/css/reset/ | |
v2.0 | 20110126 | |
License: none (public domain) | |
*/ | |
html, body, div, span, applet, object, iframe, | |
h1, h2, h3, h4, h5, h6, p, blockquote, pre, | |
a, abbr, acronym, address, big, code, | |
del, dfn, img, ins, kbd, q, s, samp, | |
small, strike, sub, sup, tt, var, | |
b, u, i, center, | |
dl, dt, dd, ol, ul, li, | |
fieldset, form, label, legend, | |
table, caption, tbody, tfoot, thead, tr, th, td, | |
article, aside, canvas, details, embed, | |
figure, figcaption, footer, header, hgroup, | |
menu, nav, output, ruby, section, summary, | |
time, mark, audio, video { | |
margin: 0; | |
padding: 0; | |
border: 0; | |
font-size: 100%; | |
font: inherit; | |
vertical-align: baseline; | |
} | |
/* HTML5 display-role reset for older browsers */ | |
article, aside, details, figcaption, figure, | |
footer, header, hgroup, menu, nav, section { | |
display: block; | |
} | |
body { | |
line-height: 1; | |
font-family:roboto; | |
font-weight:100; | |
color:#FFF; | |
font-size:40px; | |
margin:40px; | |
} | |
ol, ul { | |
list-style: none; | |
} | |
blockquote, q { | |
quotes: none; | |
} | |
blockquote:before, blockquote:after, | |
q:before, q:after { | |
content: ''; | |
content: none; | |
} | |
table { | |
border-collapse: collapse; | |
border-spacing: 0; | |
} | |
div {margin-bottom:40px;} | |
</style> | |
</head> | |
<body style="background:#000; color:#FFF; overflow:hidden;"> | |
<div id="drug_name"></div> | |
<div id="info_type">dosage | |
</div> | |
<div id="info">fake dosage KJK</div> | |
<script> | |
var i = 0; | |
var drugs = {"Adderall": {"dosage": "fake dosage", "indications": ["fake indication 1", "fake indication 2"]}}; | |
var info_type = ['dosage', 'indications']; | |
var drug_name = 'Adderall'; | |
function onGesture(name) { | |
if (name == 'SWIPE_RIGHT' || name == 'WINK' || name == 'TAP') { | |
i += 1; | |
$("#info_type").text(info_type[i]); | |
console.log($("info_type").text()); | |
$("#info").text(drugs[drug_name][info_type[i]]); | |
} else if (name == 'SWIPE_LEFT' || name == 'DOUBLE_BLINK') { | |
i -= 1; | |
$("#info_type").text(info_type[i]); | |
$("#info").text(drugs[drug_name][info_type[i]]); | |
} | |
} | |
function onEyeGesture(name){ | |
onGesture(name); | |
} | |
function server() { | |
WS.log('connected'); | |
WS.speechRecognize("What drug do you want information about?", 'getDrugName'); | |
} | |
function getDrugName(data) { | |
WS.say('hi'); | |
console.log(data); | |
var fuzzy_names = FuzzySet(Object.keys(drugs)); | |
console.log(JSON.stringify(Object.keys(drugs))); | |
var fuzzy_match = fuzzy_names.get(data)[0][1]; | |
console.log(fuzzy_match); | |
drug_name = fuzzy_match; | |
showDrugInfo(); | |
} | |
function showDrugInfo() { | |
console.log('show drug info'); | |
$("#drug_name").text(drug_name); | |
$("#info_type").text(info_type[i]); | |
$("#info").text(drugs[drug_name][info_type[i]]); | |
} | |
function main() { | |
WS.serverConnect('{{WSUrl}}', server); | |
$.ajaxSetup({ | |
error: function(jqXHR, exception) { | |
if (jqXHR.status === 0) { | |
WS.log('Not connect.\n Verify Network.'); | |
} else if (jqXHR.status == 404) { | |
WS.log('Requested page not found. [404]'); | |
} else if (jqXHR.status == 500) { | |
WS.log('Internal Server Error [500].'); | |
} else if (exception === 'parsererror') { | |
WS.log('Requested JSON parse failed.'); | |
} else if (exception === 'timeout') { | |
WS.log('Time out error.'); | |
} else if (exception === 'abort') { | |
WS.log('Ajax request aborted.'); | |
} else { | |
WS.log('Uncaught Error.\n' + jqXHR.responseText); | |
} | |
} | |
}); | |
WS.gestureCallback('onGesture', 'onGesture'); | |
WS.gestureCallback('onEyeGesture', 'onGesture'); | |
WS.liveCardCreate(false, .2); | |
WS.activityCreate(); | |
} | |
window.onload = main; | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment