Skip to content
Browse files

Restart with hitting 'R'

  • Loading branch information...
1 parent dea6960 commit a5c3a208486e6812a2de6f2862b85cf9302588af @nonowarn committed
Showing with 43 additions and 7 deletions.
  1. +10 −0 functionator/app.css
  2. +30 −7 functionator/app.js
  3. +3 −0 functionator/index.html
View
10 functionator/app.css
@@ -68,6 +68,16 @@ body > script {
left: 0px;
}
+#tip {
+ display: none;
+ font-size: 16px;
+ margin-top: 12px;
+}
+
+#tip.visible {
+ display: block;
+}
+
#result {
opacity: 0.3;
View
37 functionator/app.js
@@ -4,6 +4,7 @@
var target = doc.getElementById("target"),
result = doc.getElementById("result"),
menu = doc.getElementById("menu"),
+ tip = doc.getElementById("tip"),
startTime = null,
gameEnded = false;
@@ -18,6 +19,16 @@
+ text + "&url=" + url + "&size=l";
}
+ function retryWith(clear) {
+ result.className = "";
+ menu.className = "";
+ tip.className = "";
+ startTime = null;
+ gameEnded = false;
+ clear();
+ return false;
+ }
+
function clearTarget() {
var removeChar = function () {
setTimeout(function () {
@@ -33,6 +44,12 @@
removeChar();
}
+ function clearTargetImmediately() {
+ target.value = "";
+ target.disabled = false;
+ target.focus();
+ }
+
target.addEventListener("keydown", function (e) {
if (startTime === null) {
startTime = Date.now();
@@ -53,19 +70,25 @@
var tweetButtonFrame = menu.querySelector(".tweet-button");
tweetButtonFrame.onload = function () {
- setTimeout(function () { menu.className = "visible"; }, 500);
+ setTimeout(function () {
+ menu.className = "visible";
+ tip.className = "visible";
+ }, 500);
};
tweetButtonFrame.src = tweetScore(formattedRecord);
}
}, false);
retry.addEventListener("click", function (e) {
- result.className = "";
- menu.className = "";
- startTime = null;
- gameEnded = false;
- clearTarget();
- return false;
+ return retryWith(clearTarget);
+ }, false);
+
+ // On game was ended and pressed 'r' w/o modifiers, restart game immediately
+ win.addEventListener("keydown", function (e) {
+ if (gameEnded && e.which === 82 && !e.metaKey && !e.ctrlKey) {
+ e.preventDefault();
+ retryWith(clearTargetImmediately);
+ }
}, false);
}(this, document));
View
3 functionator/index.html
@@ -23,6 +23,9 @@ <h1 class=title>Type "function" as fast as you can</h1>
allowtransparency="true" frameborder="0" scrolling="no"
style="width:130px; height:28px;"></iframe>
</div>
+ <div id="tip">
+ Hit <kbd>R</kbd> to retry without cursor.
+ </div>
</div>
<script src="app.js"></script>

0 comments on commit a5c3a20

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