forked from KieronDowie/TestingGrounds
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathscript.js
More file actions
121 lines (120 loc) · 2.72 KB
/
script.js
File metadata and controls
121 lines (120 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var time = 0;
var units = ['day','hour','min','sec'];
$(document).ready(function()
{
$('#entername').keyup(function()
{
checkName($('#entername').val());
});
reqTime();
$(".tgsig input").focus(function() { $(this).select(); } );
$(".tgsig input").mouseup(function() { return false; } );
});
function reqTime()
{
$.ajax({url:'/time', success:function(result)
{
if (result == 'now')
{
$('#clock').html('<span class="nowtesting">NOW TESTING</span>');
}
else
{
time = parseInt(result);
tick();
}
}, error:function()
{
console.log('ERROR! Unable to make AJAX request.');
}});
}
function checkName(name)
{
$.ajax({url:'/namecheck', data:name,success:function(result)
{
if (result=='taken')
{
$('#error').html('That name is taken. Please choose a different name.');
$('#error').css('display','block');
$('#send').attr('disabled','disabled');
}
else if (result=='invalid')
{
$('#error').html('Names may only contain letters, numbers, underscores and dashes.');
$('#error').css('display','block');
$('#send').attr('disabled','disabled');
}
else if (result=='empty')
{
$('#error').html('Your name cannot be empty.');
$('#error').css('display','block');
$('#send').attr('disabled','disabled');
}
else if (result=='noletters')
{
$('#error').html('Your name must contain at least one letter.');
$('#error').css('display','block');
$('#send').attr('disabled','disabled');
}
else if (result=='toolong')
{
$('#error').html('Your name cannot be more than 20 characters.');
$('#error').css('display','block');
$('#send').attr('disabled','disabled');
}
else if (result=='lol')
{
$('#error').html('Very clever. Truly we are but peons in the shadow of your vast intellect.');
$('#error').css('display','block');
}
else
{
$('#error').html('');
$('#error').css('display','none');
$('#send').removeAttr('disabled');
}
}, error:function()
{
console.log('ERROR! Unable to make AJAX request.');
}});
}
function tick()
{
time--;
if (time != 0)
{
var current = getTime(time);
var clock = $('#clock');
for (i in current)
{
clock.children()[i].innerHTML = formatTime(current[i])+'<span class="unit">'+units[i]+'</span>';
}
setTimeout(tick,1000);
}
else
{
$('#clock').html('<span class="nowtesting">Welcome!~</span>');
}
}
function getTime(time)
{
var seconds = time % 60;
time-=seconds;
time = time / 60; //minutes
var minutes = time % 60;
time-=minutes;
time = time /60; //hours
var hours = time % 24;
time-=hours;
time = time / 24; //days
var days = time;
return [days,hours,minutes,seconds];
}
function formatTime(num)
{
if ((num+'').length == 1)
{
num = '0'+num;
}
return num;
}