LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code
{{ tooltipText }}
Your browser doesn't support speech synthesis.
{{ time.value }}
wave2
wave2
wave2
wave2
{{ percentsLeft }}
%
CSS
@import url("https://fonts.googleapis.com/css?family=Roboto:100,400");
*, *::after, *::before {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  min-height: 100%;
}

body {
  margin: 0;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  font-family: 'Roboto', sans-serif;
  background: -webkit-linear-gradient(top left, #c8c897, #6590A2);
  background: linear-gradient(to bottom right, #c8c897, #6590A2);
}

[v-cloak] {
  display: none;
}

a {
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
}

::-webkit-scrollbar {
  display: none;
}

.stage {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
  background: #fff;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
  background: #1E384C;
  -webkit-transition: background-color .3s;
  transition: background-color .3s;
}
@media (min-width: 500px) {
  .stage {
    border-radius: 5px;
    max-height: 550px;
    max-width: 350px;
  }
}
.stage.menu-open .microphone {
  -webkit-transform: translate3d(-1em, 0, 0);
          transform: translate3d(-1em, 0, 0);
  opacity: 0;
}
.stage.menu-open .voices-menu__button {
  z-index: 40;
  -webkit-transform: translate3d(0, 0, 0);
          transform: translate3d(0, 0, 0);
  opacity: 1;
}
.stage.menu-open .menu {
  z-index: 25;
}
.stage.menu-open .time {
  -webkit-transform: translate3d(0, -200%, 0);
          transform: translate3d(0, -200%, 0);
  -webkit-transition: .5s opacity, .5s transform;
  transition: .5s opacity, .5s transform;
  opacity: 0;
}
.stage.menu-open button {
  -webkit-transform: translate3d(0, 200%, 0);
          transform: translate3d(0, 200%, 0);
  -webkit-transition-delay: 0s;
          transition-delay: 0s;
  opacity: 0;
}
.stage.menu-open .percent {
  -webkit-transition: .4s opacity, .4s transform;
  transition: .4s opacity, .4s transform;
  -webkit-transform: translate3d(0, 50%, 0);
          transform: translate3d(0, 50%, 0);
  opacity: 0;
}
.stage.menu-open .menu__item {
  opacity: 1;
  -webkit-transform: translate3d(0, 0, 0);
          transform: translate3d(0, 0, 0);
}
.stage.menu-open .menu__item:nth-child(1) {
  -webkit-transition-delay: .2s;
          transition-delay: .2s;
}
.stage.menu-open .menu__item:nth-child(2) {
  -webkit-transition-delay: .3s;
          transition-delay: .3s;
}
.stage.menu-open .menu__item:nth-child(3) {
  -webkit-transition-delay: .4s;
          transition-delay: .4s;
}
.stage.menu-open .menu__item:nth-child(4) {
  -webkit-transition-delay: .5s;
          transition-delay: .5s;
}
.stage.voices-open .voices-menu {
  z-index: 35;
}
.stage.voices-open .voices-menu__bg {
  -webkit-transform: scale(6);
          transform: scale(6);
}
.stage.voices-open .voices-menu__close {
  opacity: 1;
  -webkit-transform: translate3d(0, 0, 0) rotate(0);
          transform: translate3d(0, 0, 0) rotate(0);
}
.stage.voices-open .voices-list-wrapper {
  opacity: 1;
}
.stage.voices-open .voices-list__item {
  opacity: 1;
  -webkit-transform: translate(0, 0);
          transform: translate(0, 0);
  -webkit-transition: opacity .15s, -webkit-transform .2s;
  transition: opacity .15s, -webkit-transform .2s;
  transition: opacity .15s, transform .2s;
  transition: opacity .15s, transform .2s, -webkit-transform .2s;
}
.stage.voices-open .voices-list__item:nth-child(1) {
  -webkit-transition-delay: 75ms;
          transition-delay: 75ms;
}
.stage.voices-open .voices-list__item:nth-child(2) {
  -webkit-transition-delay: 150ms;
          transition-delay: 150ms;
}
.stage.voices-open .voices-list__item:nth-child(3) {
  -webkit-transition-delay: 225ms;
          transition-delay: 225ms;
}
.stage.voices-open .voices-list__item:nth-child(4) {
  -webkit-transition-delay: 300ms;
          transition-delay: 300ms;
}
.stage.voices-open .voices-list__item:nth-child(5) {
  -webkit-transition-delay: 375ms;
          transition-delay: 375ms;
}
.stage.voices-open .voices-list__item:nth-child(6) {
  -webkit-transition-delay: 450ms;
          transition-delay: 450ms;
}
.stage.voices-open .voices-list__item:nth-child(7) {
  -webkit-transition-delay: 525ms;
          transition-delay: 525ms;
}
.stage.voices-open .voices-list__item:nth-child(8) {
  -webkit-transition-delay: 600ms;
          transition-delay: 600ms;
}
.stage.voices-open .voices-list__item:nth-child(9) {
  -webkit-transition-delay: 675ms;
          transition-delay: 675ms;
}
.stage.voices-open .voices-list__item:nth-child(10) {
  -webkit-transition-delay: 750ms;
          transition-delay: 750ms;
}

.microphone {
  z-index: 30;
  position: absolute;
  top: -.5em;
  left: -.8em;
  width: 70px;
  height: 70px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.5);
  -webkit-transition: opacity .3s, color .2s, -webkit-transform .3s;
  transition: opacity .3s, color .2s, -webkit-transform .3s;
  transition: opacity .3s, transform .3s, color .2s;
  transition: opacity .3s, transform .3s, color .2s, -webkit-transform .3s;
}
.microphone:hover {
  color: rgba(255, 255, 255, 0.8);
}
.microphone svg {
  z-index: 2;
  position: relative;
  font-size: 2em;
  width: 1em;
  height: 1em;
}
.microphone:before, .microphone:after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  opacity: 0;
}
.microphone:after {
  z-index: 1;
  background: rgba(255, 255, 255, 0.1);
  -webkit-transition: opacity .3s;
  transition: opacity .3s;
}
.microphone:before {
  z-index: 2;
  border: 3px solid rgba(255, 255, 255, 0.1);
  opacity: 0;
}
.microphone.is-listening {
  color: #d82e2e;
}
.microphone.is-listening:before {
  -webkit-animation: pulseAway 1s infinite;
          animation: pulseAway 1s infinite;
}
.microphone.is-listening:after {
  opacity: 1;
  -webkit-animation: pulse 1.5s linear infinite;
          animation: pulse 1.5s linear infinite;
}
.microphone .voice-tooltip {
  position: absolute;
  top: 110%;
  left: 25px;
  padding: .4em .6em;
  color: rgba(255, 255, 255, 0.8);
  font-size: .8em;
  font-weight: 300;
  text-transform: uppercase;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}
.microphone .voice-tooltip:before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 5px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 5px 5px 5px;
  border-color: transparent transparent rgba(255, 255, 255, 0.1) transparent;
}

.fade-enter-active,
.fade-leave-active {
  -webkit-transition: all .15s ease;
  transition: all .15s ease;
}

.fade-enter, .fade-leave-to {
  opacity: 0;
}

.voices-menu {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}
@media (min-width: 500px) {
  .voices-menu {
    border-radius: 5px;
    overflow: hidden;
  }
}
.voices-menu__bg {
  position: absolute;
  top: -15em;
  left: -15em;
  -webkit-transform-origin: 50% 50%;
          transform-origin: 50% 50%;
  width: 20em;
  height: 20em;
  color: #222;
  -webkit-transform: scale(0.2);
          transform: scale(0.2);
  -webkit-transition: -webkit-transform .3s;
  transition: -webkit-transform .3s;
  transition: transform .3s;
  transition: transform .3s, -webkit-transform .3s;
}
.voices-menu__button {
  position: absolute;
  top: 0;
  left: 0;
  padding: .8em .6em;
  color: rgba(255, 255, 255, 0.5);
  opacity: 0;
  cursor: pointer;
  -webkit-transform: translate3d(1em, 0, 0);
          transform: translate3d(1em, 0, 0);
  -webkit-transition: opacity .3s, color .2s, -webkit-transform .3s;
  transition: opacity .3s, color .2s, -webkit-transform .3s;
  transition: opacity .3s, transform .3s, color .2s;
  transition: opacity .3s, transform .3s, color .2s, -webkit-transform .3s;
}
.voices-menu__button:hover {
  color: rgba(255, 255, 255, 0.8);
}
.voices-menu__button > * {
  vertical-align: middle;
  font-weight: 300;
  letter-spacing: 1px;
}
.voices-menu__button svg {
  width: 1.8em;
  height: 1.8em;
}
.voices-menu__close {
  position: absolute;
  top: 0;
  right: 0;
  padding: 10px 10px;
  font-size: 2em;
  font-weight: 300;
  color: rgba(255, 255, 255, 0.5);
  opacity: 0;
  cursor: pointer;
  -webkit-transform: translate3d(1em, 0, 0) rotate(45deg);
          transform: translate3d(1em, 0, 0) rotate(45deg);
  -webkit-transition: opacity .3s, color .2s, -webkit-transform .3s;
  transition: opacity .3s, color .2s, -webkit-transform .3s;
  transition: opacity .3s, transform .3s, color .2s;
  transition: opacity .3s, transform .3s, color .2s, -webkit-transform .3s;
}
.voices-menu__close svg {
  width: 1em;
  height: 1em;
}
.voices-menu__close:hover {
  color: rgba(255, 255, 255, 0.8);
}

.voices-list-wrapper {
  position: absolute;
  top: 60px;
  left: 0;
  bottom: 0;
  right: 0;
  overflow-y: auto;
  opacity: 0;
}

.voices-list {
  margin: 0;
  padding: 0;
}
.voices-list__item {
  display: block;
  opacity: 0;
  -webkit-transform: translate(0, 1em);
          transform: translate(0, 1em);
}
.voices-list__item.is-selected .voices-list__icon {
  opacity: 1;
  -webkit-transform: translate3d(0, 0, 0) rotate(0);
          transform: translate3d(0, 0, 0) rotate(0);
}
.voices-list__icon {
  position: relative;
  margin-right: 20px;
  color: #02C39A;
  opacity: 0;
  -webkit-transform: translate3d(-1em, 0, 0) rotate(-30deg);
          transform: translate3d(-1em, 0, 0) rotate(-30deg);
  -webkit-transition: opacity .2s, -webkit-transform .2s;
  transition: opacity .2s, -webkit-transform .2s;
  transition: opacity .2s, transform .2s;
  transition: opacity .2s, transform .2s, -webkit-transform .2s;
}
.voices-list__icon svg {
  width: 1.2em;
  height: 1.2em;
}
.voices-list__link {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  padding: .5em 1.1em;
  font-size: 1.3em;
  font-weight: 300;
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
}
.voices-list__link:hover {
  background: rgba(255, 255, 255, 0.05);
}
.voices-list__link span {
  display: inline-block;
  vertical-align: middle;
}
.voices-list__content {
  line-height: 1;
}
.voices-list__content span {
  font-size: .5em;
}
.voices-list__default {
  color: #02C39A;
}

.menu {
  z-index: 10;
  position: absolute;
  width: 100%;
  height: 100%;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
}
.menu__button {
  z-index: 30;
  position: absolute;
  top: 0;
  right: 0;
  display: inline-block;
  padding: 1.5em 1em;
  cursor: pointer;
}
.menu__button:hover .menu__dot,
.menu__button:hover .menu__dot:before,
.menu__button:hover .menu__dot:after {
  background: rgba(255, 255, 255, 0.8);
}
.menu__dot {
  position: relative;
  border-radius: 50%;
  width: 6px;
  height: 6px;
  background: rgba(255, 255, 255, 0.5);
  -webkit-transition: background .2s;
  transition: background .2s;
}
.menu__dot:before, .menu__dot:after {
  position: absolute;
  content: '';
  border-radius: 50%;
  width: 6px;
  height: 6px;
  background: rgba(255, 255, 255, 0.5);
  -webkit-transition: background .2s;
  transition: background .2s;
}
.menu__dot:before {
  top: 10px;
}
.menu__dot:after {
  bottom: 10px;
}
.menu__list {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100%;
}
.menu__item {
  overflow: hidden;
  opacity: 0;
  -webkit-transform: translate3d(0, 100%, 0);
          transform: translate3d(0, 100%, 0);
  -webkit-transition: .4s transform, .4s opacity;
  transition: .4s transform, .4s opacity;
}
.menu__item a {
  font-size: 1.8em;
  font-weight: 300;
  display: block;
  color: rgba(255, 255, 255, 0.5);
  text-transform: uppercase;
  text-decoration: none;
  padding: .5em 1.5em;
}
.menu__item a span {
  display: inline-block;
  vertical-align: middle;
  -webkit-transition: -webkit-transform .3s;
  transition: -webkit-transform .3s;
  transition: transform .3s;
  transition: transform .3s, -webkit-transform .3s;
}
.menu__item a:hover svg, .menu__item a:focus svg {
  -webkit-transform: scale(1.2);
          transform: scale(1.2);
}
.menu__item a:hover .water-glass__water, .menu__item a:focus .water-glass__water {
  fill: #32BAFA;
  -webkit-transform: scale(1, 0.8);
          transform: scale(1, 0.8);
}
.menu__item a:hover .coffee-cup__coffee, .menu__item a:focus .coffee-cup__coffee {
  fill: #BF9E87;
  -webkit-transform: scale(1, 0.8);
          transform: scale(1, 0.8);
}
.menu__item a:hover .beer-glass__beer, .menu__item a:focus .beer-glass__beer {
  fill: #E18E02;
  -webkit-transform: scale(1, 0.8);
          transform: scale(1, 0.8);
}
.menu__item a:hover .clock__short, .menu__item a:focus .clock__short {
  fill: #02C39A;
  -webkit-transform-origin: 0% 50%;
          transform-origin: 0% 50%;
  -webkit-transform: rotate(20deg);
          transform: rotate(20deg);
  -webkit-transition: color .2s, -webkit-transform 1s;
  transition: color .2s, -webkit-transform 1s;
  transition: transform 1s, color .2s;
  transition: transform 1s, color .2s, -webkit-transform 1s;
}
.menu__item a:hover .clock__long, .menu__item a:focus .clock__long {
  fill: #02C39A;
  -webkit-transition: color .2s, -webkit-transform 1s;
  transition: color .2s, -webkit-transform 1s;
  transition: transform 1s, color .2s;
  transition: transform 1s, color .2s, -webkit-transform 1s;
  -webkit-transform-origin: 50% 95%;
          transform-origin: 50% 95%;
  -webkit-transform: rotate(360deg);
          transform: rotate(360deg);
}
.menu__item svg {
  display: inline-block;
  vertical-align: middle;
  width: 1em;
  height: 1em;
  margin-right: 1em;
  -webkit-transition: -webkit-transform .3s;
  transition: -webkit-transform .3s;
  transition: transform .3s;
  transition: transform .3s, -webkit-transform .3s;
}
.menu__item svg path {
  fill: #fff;
  -webkit-transition: all .3s;
  transition: all .3s;
  -webkit-transform-origin: 100% 100%;
          transform-origin: 100% 100%;
}

.browser-support {
  color: #fff;
  font-size: .8rem;
  text-align: center;
  padding: .5rem;
}

.content {
  z-index: 20;
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
}

.time {
  overflow: hidden;
  padding: 1em;
  font-size: 1.1em;
  text-align: center;
  -webkit-transition: .5s .2s opacity, .5s transform .2s;
  transition: .5s .2s opacity, .5s transform .2s;
}

.timer__item {
  -webkit-transition: all 1s;
  transition: all 1s;
  margin-right: 10px;
  color: rgba(255, 255, 255, 0.8);
}
.timer__item:first-child, .timer__item:nth-child(3) {
  color: rgba(255, 255, 255, 0.2);
}

.timer-enter, .timer-leave-to {
  opacity: 0;
  -webkit-transform: translate3d(0, -100%, 0);
          transform: translate3d(0, -100%, 0);
}

.timer-leave-to {
  -webkit-transition-duration: .5s;
          transition-duration: .5s;
}

.timer-leave-active {
  -webkit-transform: translate3d(0, 0, 0);
          transform: translate3d(0, 0, 0);
}

.percent {
  z-index: 2;
  position: relative;
  font-size: 7em;
  font-weight: 100;
  color: rgba(255, 255, 255, 0.7);
  -webkit-transition: .4s .2s opacity, .4s .2s transform;
  transition: .4s .2s opacity, .4s .2s transform;
}
.percent > div {
  display: inline-block;
}
.percent > span {
  margin-left: -.4em;
  font-size: .5em;
}

.percent-left-enter-active, .percent-left-leave-active {
  -webkit-transition: -webkit-transform .1s ease;
  transition: -webkit-transform .1s ease;
  transition: transform .1s ease;
  transition: transform .1s ease, -webkit-transform .1s ease;
}

.percent-left-enter, .percent-left-leave-to {
  -webkit-transform: scale(1.05);
          transform: scale(1.05);
}

button {
  z-index: 20;
  position: absolute;
  display: block;
  width: 70%;
  margin: auto;
  left: 0;
  right: 0;
  bottom: 1.5em;
  padding: .6em;
  color: rgba(255, 255, 255, 0.8);
  font-size: 1.1em;
  font-weight: 300;
  letter-spacing: 1px;
  text-transform: uppercase;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 2em;
  outline: none;
  -webkit-transition: .2s background, .4s .3s transform, .4s .3s opacity;
  transition: .2s background, .4s .3s transform, .4s .3s opacity;
  cursor: pointer;
}
button:hover {
  background: #fff;
  color: currentColor;
}

.waves {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  -webkit-transition: .4s transform ease;
  transition: .4s transform ease;
  -webkit-transform-origin: bottom center;
          transform-origin: bottom center;
}
@media (min-width: 500px) {
  .waves {
    border-radius: 5px;
  }
}

.wave {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  -webkit-animation: wave 1s linear infinite;
          animation: wave 1s linear infinite;
}
.wave--front {
  z-index: 2;
  color: #32BAFA;
}
.wave--back {
  z-index: 1;
  color: #2C7FBE;
  -webkit-animation-direction: reverse;
          animation-direction: reverse;
}

.water {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 80%;
  background: currentColor;
}
.water svg {
  position: absolute;
  width: 100%;
  left: 0;
  right: 0;
  bottom: 99.9%;
}

.water:first-of-type {
  -webkit-transform: translate(-100%, 0);
          transform: translate(-100%, 0);
}

svg {
  fill: currentColor;
}

@-webkit-keyframes wave {
  0% {
    -webkit-transform: translate3d(0, 0, 0);
            transform: translate3d(0, 0, 0);
  }
  50% {
    -webkit-transform: translate3d(50%, 0.5em, 0);
            transform: translate3d(50%, 0.5em, 0);
  }
  100% {
    -webkit-transform: translate3d(100%, 0, 0);
            transform: translate3d(100%, 0, 0);
  }
}

@keyframes wave {
  0% {
    -webkit-transform: translate3d(0, 0, 0);
            transform: translate3d(0, 0, 0);
  }
  50% {
    -webkit-transform: translate3d(50%, 0.5em, 0);
            transform: translate3d(50%, 0.5em, 0);
  }
  100% {
    -webkit-transform: translate3d(100%, 0, 0);
            transform: translate3d(100%, 0, 0);
  }
}
@-webkit-keyframes pulse {
  0% {
    -webkit-transform: scale(1);
            transform: scale(1);
  }
  50% {
    -webkit-transform: scale(1.1);
            transform: scale(1.1);
  }
  100% {
    -webkit-transform: scale(1);
            transform: scale(1);
  }
}
@keyframes pulse {
  0% {
    -webkit-transform: scale(1);
            transform: scale(1);
  }
  50% {
    -webkit-transform: scale(1.1);
            transform: scale(1.1);
  }
  100% {
    -webkit-transform: scale(1);
            transform: scale(1);
  }
}
@-webkit-keyframes pulseAway {
  0% {
    opacity: 0;
    -webkit-transform: scale(0.5);
            transform: scale(0.5);
  }
  50% {
    opacity: 1;
  }
  100% {
    -webkit-transform: scale(1.4);
            transform: scale(1.4);
  }
}
@keyframes pulseAway {
  0% {
    opacity: 0;
    -webkit-transform: scale(0.5);
            transform: scale(0.5);
  }
  50% {
    opacity: 1;
  }
  100% {
    -webkit-transform: scale(1.4);
            transform: scale(1.4);
  }
}
JS
var SpeechRecognition = SpeechRecognition || window.webkitSpeechRecognition || undefined;
var numbers = Array.apply(null, Array(101)).map(function (_, i) {return i;});

if(SpeechRecognition) {
  var SpeechGrammarList = SpeechGrammarList || window.webkitSpeechGrammarList || undefined;
  var SpeechRecognitionEvent = SpeechRecognitionEvent || window.webkitSpeechRecognitionEvent || undefined;
  
  var commands = ['reset', 'timer', ...numbers];
  var grammar = '#JSGF V1.0; grammar colors; public  = ' + commands.join(' | ') + ' ;'

  var speechRecognitionList = new SpeechGrammarList();
      speechRecognitionList.addFromString(grammar, 1);
      
  var recognition = new SpeechRecognition();
      recognition.grammars = speechRecognitionList;
      //recognition.continuous = false;
      recognition.lang = 'en-US';
      recognition.interimResults = true;
      recognition.maxAlternatives = 1;
}

var speechSynth = new SpeechSynthesisUtterance();

const padDigits = (number, digits) => {
    return Array(Math.max(digits - String(number).length + 1, 0)).join(0) + number;
}

const calculatePercentsLeft = (value, from) => {
    return Math.floor(Math.ceil(value/1000) / (from * 60) * 100)
}

const calculateScaleFactor = (percent) => {
    return 1-(100-percent)/100;
}

function guid() {
  function s4() {
    return Math.floor((1 + Math.random()) * 0x10000)
      .toString(16)
      .substring(1);
  }
  return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
    s4() + '-' + s4() + s4() + s4();
}

const settings = {
  water: {
    warningMsg: 'Remember to drink',
    timeIsUpMsg: 'Time\'s up. You really need to drink now',
    buttonTxt: 'Drink',
    waveFrontColor: '#32BAFA',
    waveBackColor: '#2C7FBE',
    stageBg: '#1E384C',
    durationInMinutes: 1
  },
  coffee: {
    warningMsg: `It's almost coffee time.`,
    timeIsUpMsg: 'Time\'s up. Let\'s take a coffee break!',
    buttonTxt: 'Drink coffee',
    waveFrontColor: '#b39374',
    waveBackColor: '#7a6057',
    stageBg: '#392a2c',
    durationInMinutes: 1
  },
  break: {
    warningMsg: 'It is time to rest your eyes soon!',
    timeIsUpMsg: 'Time\'s up. Now, it\'s really time to rest your eyes!',
    buttonTxt: 'Take a break',
    waveFrontColor: '#02C39A',
    waveBackColor: '#028090',
    stageBg: '#012F35',
    durationInMinutes: 1
  },
  beer: {
    warningMsg: `I know this sounds scary, but it's almost time for another beer`,
    timeIsUpMsg: `It's been while since the last beer!`,
    buttonTxt: 'Have a beer',
    waveFrontColor: '#F1B10F',
    waveBackColor: '#FFFFFF',
    stageBg: '#5A3900',
    durationInMinutes: 60
  }
};

new Vue({
  el: '#stage',
  data() {
    return {
        color: '',
        percents: [100],
        percentsLeft: 100,
        secondsLeft: 0,
        waveStyles: '',
        duration: 1,
        timer: [],
        voicesOpen: false,
        voices: [],
        selectedVoice: {},
        countdownObj: {},
        activeReminder: settings.water,
        menuOpen: false,
        isListening: false,
        tooltipText: 'Say eg. "reset"',
        stageBg: settings.water.stageBg
    }
  },
  mounted() {
    this.resetTimer();
    this.voices = speechSynthesis.getVoices();

    if(this.voices.length === 0) {
      speechSynthesis.onvoiceschanged = () => {
        this.voices = speechSynthesis.getVoices();
      };
    }
  },
  computed: {
    supportSpeechSynth() {
      return 'speechSynthesis' in window; 
    },
    supportSpeechRecognition() {
      return SpeechRecognition;
    }
  },
  watch: {
    percentsLeft: function(val, oldVal) {
      if (val === oldVal) {
        return;
      }
      this.percents.splice(0, 1);
      this.percents.push(val);
    }
  },
  methods: {
    setActiveReminder(reminder) {
      this.activeReminder = settings[reminder];
      this.stageBg = this.activeReminder.stageBg;
    },
    toggleMenu() {
      this.menuOpen = !this.menuOpen;
      if(this.menuOpen) {
        this.pauseTimer();
        this.waveStyles = `transform: translate3d(0,100%,0); transition-delay: .25s;`;
      }else {
        this.continueTimer();
      }
    },
    toggleVoicesMenu() {
      this.voicesOpen = !this.voicesOpen;
    },
    voiceSelected(voice) {
      this.selectedVoice = voice;
      speechSynth.voice = voice;
    },
    start(reminder) {
      this.setActiveReminder(reminder);
      this.percents = [100];
      this.timer = [];
      this.menuOpen = false;
      this.resetTimer();
    },
    resetTimer() {
      let durationInSeconds = 60 * this.activeReminder.durationInMinutes;
      this.startTimer(durationInSeconds);
    },
    startTimer(secondsLeft) {
      let now = new Date();

      // later on, this timer may be stopped
      if(this.countdown) {
        window.clearInterval(this.countdown);
      }
      
      this.countdown = countdown(ts => {
        this.secondsLeft= Math.ceil(ts.value/1000);
        this.percentsLeft = calculatePercentsLeft(ts.value,this.activeReminder.durationInMinutes);
        this.waveStyles = `transform: scale(1,${calculateScaleFactor(this.percentsLeft)})`;
        this.updateCountdown(ts);
        if(this.percentsLeft == 10) {
          this.giveWarning();
        }
        if(this.percentsLeft <= 0){
          this.timeIsUpMessage();
          this.pauseTimer();
          this.timer = [];
          setTimeout(() => {
            this.startListenVoiceCommands();
          }, 1500);
          
        }
      }, now.getTime() + (secondsLeft * 1000));
    },
    updateCountdown(ts) {
      if(this.timer.length > 2) {
        this.timer.splice(2);
      }

      const newTime = {
        id: guid(),
        value: `${padDigits(ts.minutes, 2)}:${padDigits(ts.seconds, 2)}`
      };

      this.timer.unshift(newTime);
    },
    pauseTimer() {
      window.clearInterval(this.countdown);
    },
    continueTimer() {
      if(this.secondsLeft > 0) {
        this.startTimer(this.secondsLeft-1);
      }
    },
    giveWarning() {
      speechSynth.text = this.activeReminder.warningMsg;
      window.speechSynthesis.speak(speechSynth);
    },
    timeIsUpMessage() {
      speechSynth.text = this.activeReminder.timeIsUpMsg;
      window.speechSynthesis.speak(speechSynth);
    },
    timerResetMessage() {
      speechSynth.text = `Timer reset. Time left ${this.activeReminder.durationInMinutes} ${this.activeReminder.durationInMinutes > 1 ? 'minutes': 'minute'}`;
      window.speechSynthesis.speak(speechSynth);
    },
    reset() {
      this.resetTimer();
      this.timerResetMessage();
    },
    startListenVoiceCommands() {
      if(this.isListening || !this.supportSpeechRecognition) return;

      this.isListening = true;
      recognition.start();
      recognition.onresult = (event) => {
        let last = event.results.length - 1;
        let transcript = event.results[last][0].transcript;
        let splittedTranscript = transcript.split(' ');
        let isFinal = event.results[last].isFinal;

        this.tooltipText = transcript;

        if(transcript == "reset") {
          this.resetTimer();
          this.timerResetMessage();
        }
        if(
          splittedTranscript.length >= 3 &&
          splittedTranscript[0] == 'timer' &&
          isFinal &&
          numbers.includes(Number(splittedTranscript[1])) && 
          (splittedTranscript[2] == 'minute' || splittedTranscript[2] == 'minutes')
        ) {
          this.activeReminder.durationInMinutes = numbers[splittedTranscript[1]];
          this.resetTimer();
          this.timerResetMessage();
        }
        

      }
      recognition.onend = () => {
        this.isListening = false;
        this.tooltipText == '';
        recognition.stop();
      }
      recognition.onsoundend = () => {
        this.isListening = false;
        recognition.stop();
      }
    },
    mouseOver(type) {
      this.stageBg = settings[type].stageBg;
    },
    mouseOut() {
      this.stageBg = this.activeReminder.stageBg;
    }
  }
});

Description

Little reminder app prototype I created. All the animations/transitions you see on the app are made with CSS which shows what you can do with it. This is also a Vue.js app.
Term
Mon, 11/27/2017 - 21:30

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv