Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

beta 2, included support for heading to bed now and knowing when to s…

…et the alarm
  • Loading branch information...
commit 0b9bc773e3187f73ab9793b543ad04ca90f19830 1 parent 6c2f514
David Shaw authored

Showing 1 changed file with 158 additions and 38 deletions. Show diff stats Hide diff stats

  1. +158 38 index.html
196 index.html
@@ -4,41 +4,47 @@
4 4 <script src="jquery.js"></script>
5 5 <script>
6 6 $(document).ready(function() {
7   - // render the page -- in case you're wondering,
8   - // nothing will work without javascript!
9   - $("#tit").html('<font face="Garamond"><h1>&nbsp;&nbsp;<i>sleepyti.me <font color="#33CC33">beta</font></i></h1></font>');
10   - var mrend = '';
11   - mrend = mrend +
12   - '<table><tr width="100%">' +
13   - '<td width="20%"></td>' +
14   - '<td><font face="Garamond" size=5>I have to wake up at <span class="waketime" style="display:none;"></span>&nbsp;</td>' +
15   - '<td>' +
16   - '<select id="hour">' +
17   - '<option>(hour)</option>';
18   -
19   - // populate our lists
20   - for(var h = 1; h <= 12; h++) {
21   - mrend = mrend + '<option>' + h + '</option>';
22   - }
23   -
24   - mrend = mrend + '</select></td><td><select id="minute"><option>(minute)</option>';
25   -
26   - for(var m = 0; m <= 55; m += 5) {
27   - if(m < 10) {
28   - mrend = mrend + '<option value="' + m + '">0' + m + '</option>';
  7 + function ren() {
  8 + // render the page -- in case you're wondering,
  9 + // nothing will work without javascript!
  10 + $("#tit").html('<font face="Garamond"><h1>&nbsp;&nbsp;<i>sleepyti.me <font color="#33CC33">beta 2</font></i></h1></font>');
  11 + var mrend = '';
  12 + mrend = mrend +
  13 + '<table><tr width="100%">' +
  14 + '<td width="20%"></td>' +
  15 + '<td><span class="intro"><font face="Garamond" size=5>I have to wake up at <span class="waketime" style="display:none;"></span>&nbsp;</td>' +
  16 + '<td>' +
  17 + '<select id="hour">' +
  18 + '<option>(hour)</option>';
  19 +
  20 + // populate our lists
  21 + for(var h = 1; h <= 12; h++) {
  22 + mrend = mrend + '<option>' + h + '</option>';
29 23 }
30   - else {
31   - mrend = mrend + '<option>' + m + '</option>';
  24 +
  25 + mrend = mrend + '</select></td><td><select id="minute"><option>(minute)</option>';
  26 +
  27 + for(var m = 0; m <= 55; m += 5) {
  28 + if(m < 10) {
  29 + mrend = mrend + '<option value="' + m + '">0' + m + '</option>';
  30 + }
  31 + else {
  32 + mrend = mrend + '<option>' + m + '</option>';
  33 + }
  34 +
32 35 }
33 36
  37 + mrend = mrend + '</select></td><td><select id="ampm">' +
  38 + '<option>AM</option><option>PM</option></select></td></tr>' +
  39 + '<tr><td><hr color="white"></td></tr>' +
  40 + '<tr valign=TOP><td></td><td align="center"><span id="nowtop"><hr color="white" width="25%"><big><font color="#666666"><i>or, find out when to wake up<br/>if you go to bed now</i></font></big></td><td align="center"><hr color="white" width="25%"><input type="button" value="zzz" id="sleepnow"/></span></td>' +
  41 + '<td></td></span>' +
  42 + '<td></tr><tr><span class="results" style="display:none;"></span></td>' +
  43 + '</tr></table>';
  44 +
  45 + $('#main').html(mrend);
34 46 }
35   -
36   - mrend = mrend + '</select></td><td><select id="ampm">' +
37   - '<option>AM</option><option>PM</option></select></td></tr><td></td>' +
38   - '<td><span class="results" style="display:none;"></span></td>' +
39   - '</tr></table>';
40   -
41   - $('#main').html(mrend);
  47 + ren();
42 48
43 49 // calculates an hour and a half back
44 50 function sleepback(hr, min, an) {
@@ -69,11 +75,124 @@
69 75 return r;
70 76 }
71 77
  78 + // knockout takes a date object and returns a
  79 + // string with wake times!
  80 + // time + :14 + (multiples of 90 mins)
  81 + function knockout(rightnow) {
  82 + var r = ''; // return string
  83 + var hr = rightnow.getHours();
  84 + var dhr = 0; // separate variable to display because (24 hr clock)
  85 + var ap = '';
  86 +
  87 +
  88 + // it takes 14 minutes to fall asleep
  89 + var min = rightnow.getMinutes() + 14;
  90 + if(min > 60) {
  91 + min = min - 60;
  92 + hr = hr + 1;
  93 +
  94 + if(hr >= 24) {
  95 + if(hr == 24) {
  96 + hr = 0; // midnight, must adjust!
  97 + }
  98 + else if(hr == 25) {
  99 + hr = 1;
  100 + }
  101 + }
  102 + }
  103 +
  104 + r = '<p>It takes the average human <b>fourteen minutes</b> to fall asleep.</p><p>If you head to bed right now, you should try to wake up at one of the following times:</p><p>&nbsp;&nbsp;<font size=6><font color="#666666">';
  105 + for(var ctr = 0; ctr < 6; ctr++) { // normal sleep scheedule
  106 + // add an hour and a half
  107 + if(min < 30) {
  108 + min = min + 30;
  109 + }
  110 + else {
  111 + min = min - 30;
  112 + hr = hr + 1
  113 + }
  114 + hr = hr + 1;
  115 +
  116 + if(hr == 24) {
  117 + hr = 0;
  118 + }
  119 + if(hr == 25) {
  120 + hr = 1;
  121 + }
  122 +
  123 + if(hr < 12) {
  124 + ap = ' AM';
  125 + dhr = hr;
  126 + if(hr == 0) {
  127 + dhr = "12";
  128 + }
  129 + }
  130 + else {
  131 + ap = ' PM';
  132 + dhr = hr - 12;
  133 + }
  134 + if(ctr == 0) {
  135 + if(min > 9) {
  136 + r = r + dhr + ':' + min + ap;
  137 + }
  138 + else {
  139 + r = r + dhr + ':0' + min + ap;
  140 + }
  141 + }
  142 + else if(ctr == 4 || ctr == 5) {
  143 + if(min > 9) {
  144 + r = r + ' <i>or</i> <font color="#00CC33">' + dhr + ':' + min + ap + '</font>';
  145 + }
  146 + else {
  147 + r = r + ' <i>or</i> <font color="#00CC33">' + dhr + ':0' + min + ap;
  148 + }
  149 + }
  150 + else if(ctr == 3) {
  151 + if(min > 9) {
  152 + r = r + ' <i>or</i> <font color="#99CC66">' + dhr + ':' + min + ap + '</font>';
  153 + }
  154 + else {
  155 + r = r + ' <i>or</i> <font color="#99CC66">' + dhr + ':0' + min + ap + '</font>';
  156 + }
  157 + }
  158 + else {
  159 + if(min > 9) {
  160 + r = r + ' <i>or</i> ' + hr + ':' + min + ap;
  161 + }
  162 + else {
  163 + r = r + ' <i>or</i> ' + hr + ':0' + min + ap;
  164 + }
  165 + }
  166 + }
  167 + r = r + '</font></font></p><p>A good night\'s sleep consists of 5-6 complete sleep cycles.</p>';
  168 + r = r + '<a href="index.html">back</a>';
  169 + return r;
  170 + }
  171 +
  172 +
  173 + // handle "sleep now" requests
  174 + // this currently fades out the #main id,
  175 + // and works in a totally separate div
  176 + $("#sleepnow").click(function() {
  177 + var st = '';
  178 + var answ = ''; // this is the text we return
  179 + var d = new Date();
  180 + answ = knockout(d); // knockout takes a Date() and returns a string of wake times
  181 + st = '<span id="bit" style=display:none><font face="Garamond" size=5>' +
  182 + answ +
  183 + '</font></span>';
  184 + $('#main').fadeOut(500);
  185 + $('#instant').html(st);
  186 + $('#bit').delay(500).show(500);
  187 + });
  188 +
72 189 // user changes the list, so we calculate times!
73 190 $("#main select").change(function () {
74 191 if($("#hour").val() == '(hour)' || $("#minute").val() == '(minute)') {
75 192 return false;
76 193 }
  194 +
  195 + $('#nowtop').fadeOut(500); // ???
77 196 var ampm = $("#ampm").val();
78 197 var hr = $("#hour").val();
79 198 var min = $("#minute").val();
@@ -120,13 +239,13 @@
120 239 }
121 240 }
122 241 else {
123   - if(first == true) {
124   - first = false;
125   - txt = txt + '<font color="#01DF74" size="7">' + nhr + ':0' + nmin + ' ' + ampmt + '</font>';
126   - }
127   - else {
128   - txt = txt + ' <i>or</i> ' + '<font color="#01DF74" size="7">' + nhr + ':0' + nmin + ' ' + ampmt + '</font>';
129   - }
  242 + if(first == true) {
  243 + first = false;
  244 + txt = txt + '<font color="#01DF74" size="7">' + nhr + ':0' + nmin + ' ' + ampmt + '</font>';
  245 + }
  246 + else {
  247 + txt = txt + ' <i>or</i> ' + '<font color="#01DF74" size="7">' + nhr + ':0' + nmin + ' ' + ampmt + '</font>';
  248 + }
130 249 }
131 250 }
132 251 hr = nhr;
@@ -165,5 +284,6 @@
165 284 <body>
166 285 <div id="tit"></div>
167 286 <div id="main"></div>
  287 +<div id="instant">
168 288 </body>
169 289 </html>

0 comments on commit 0b9bc77

Please sign in to comment.
Something went wrong with that request. Please try again.