JSFiddle - React, Tailwind, and code Playground
Compare to Dodow Sleep Aid Device
by skibulk
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/nosleep/0.6.0/NoSleep.min.js"></script>
CSS
body {
transition-property: background-color;
transition-timing-function: ease-in;
background-color: black;
}
JavaScript
console.clear();
var target = 3500;
var max = 6000;
var increment = 15;
target -= (max - target) % increment;
var body = document.getElementsByTagName("body")[0];
var total = 0;
for(var i=target; i <= max; i+=increment){
total += i;
}
console.log("Minutes to max: " + (total / 60 / 1000));
function run(){
console.log(target);
body.style.transitionDuration = target + "ms";
if( body.style.backgroundColor == "white"){
body.style.backgroundColor = "black";
}else{
body.style.backgroundColor = "white";
}
setTimeout(run, target);
if( target < max ) target += increment;
}
run();
var noSleep = new NoSleep();
function enableNoSleep() {
console.log("NoSleep Enabled");
noSleep.enable();
document.removeEventListener('touchstart', enableNoSleep, false);
}
// Enable wake lock.
// (must be wrapped in a user input event handler e.g. a mouse or touch handler)
document.addEventListener('click', enableNoSleep, false);
/*
function run(){
current += increment;
if( current >= max ){
current = 0;
console.log(target);
}else if( current >= target){
current = 0;
console.log(target);
target += increment;
}
color = Math.round((current / target) * 255);
body.style = "background: rgb(" + color + "," + color + "," + color + ");";
}
setInterval(run, increment);
*/
/*
var start_breath_time = 4000;
var end_breath_time = 8000;
var end_session_time = 12 * 60 * 1000; // 12 minutes
var average_breath_time = (start_breath_time + end_breath_time) / 2;
var number_of_breaths = end_session_time / average_breath_time;
var breath_increment = (end_breath_time - start_breath_time) / number_of_breaths;
var current_breath_time = start_breath_time;
var current_session_time = 0;
for (var i = 0; i < number_of_breaths; i++) {
current_session_time += current_breath_time;
current_breath_time += breath_increment;
}
console.log(
current_breath_time,
current_session_time,
end_session_time
);
*/