-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
92 lines (72 loc) · 2.22 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Calcy | @ksdme</title>
</head>
<body>
<style type="text/css">
.center {
width: 45%;
position: absolute;
left: 50%; top: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.expr {
width: 100%;
font-size: 80px;
text-align: center;
outline: none;
border: none;
}
.alert {
color: red;
font-size: medium;
text-align: center;
font-family: monospace;
}
</style>
<!-- where we accept input from -->
<div class="center">
<input type="text" class="expr" id="expr" placeholder="Talk Math to Me!" />
<br/><span class="alert" id="alert"> </span>
</div>
<!-- -->
<script type="text/javascript">
var ExprField, AlertMsg, Empty = " ";
window.onload = function() {
ExprField = document.getElementById("expr");
AlertMsg = document.getElementById("alert");
document.onkeydown = function(event) {
if (event.keyCode == 13)
solve(ExprField.value);
}
};
/* executed with the expr str*/
var solve = function(expr) {
/* preprcess expr text */
expr = expr.replace("+", "%2B");
fetch("/solve?e="+expr).then(function(response) {
response.json().then(function(data) {
reflectUI(data);
});
});
}
var reflectUI = function(data) {
console.log(data)
if (!data.ok) {
switch(data.msg) {
case "MissingExpr": AlertMsg.innerHTML = "dude, I need that shit mate, gimme an expr!"; break;
case "EmptyExpr": AlertMsg.innerHTML = "what are you a dummy?, I need an expr to solve!"; break;
case "NameErr": AlertMsg.innerHTML = "yeah, fuck you too, use vars with their true names!"; break;
case "SyntaxErr": AlertMsg.innerHTML = "the thing you are holding is a computer, if you can't use it ask someone for help!"; break;
}
} else {
AlertMsg.innerHTML = Empty;
ExprField.value = data.ans;
}
}
</script>
</body>
</html>