-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbinary.html
More file actions
153 lines (152 loc) · 4.43 KB
/
binary.html
File metadata and controls
153 lines (152 loc) · 4.43 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<html>
<head>
<link rel="icon" href="pelement.png">
<title>binary.</title>
<link href="https://fonts.googleapis.com/css?family=Roboto:300" rel="stylesheet" type="text/css">
<style>
body{
background-color:#eee;
margin:0;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#content{
display:block;
position:fixed;
width:100vh;
height:100vh;
top:50%;
left:50%;
margin-top:-50vh;
margin-left:-50vh;
font-family:Roboto,Arial,sans-serif;
font-size:7.5vh;
color:#333;
line-height:15vh;
}
#phonedecimal,#phonebinary,#thanks{
display:block;
position:absolute;
width:80%;
height:10%;
top:50%;
left:10%;
margin-top:-30%;
text-align:center;
font-family:inherit;
font-size:inherit;
color:inherit;
}
#phonebinary{
margin-top:-7%;
font-size:50%;
display:none;
}
#thanks{
margin-top:-5%;
line-height:10vh;
display:none;
}
.btn{
display:block;
position:absolute;
width:15%;
height:15%;
left:33.5%;
top:55%;
text-align:center;
font-family:inherit;
font-size:150%;
color:inherit;
line-height:inherit;
background-color:#ccc;
cursor:pointer;
}
@keyframes fade{
from{background-color:#999;}
to{background-color:#ccc;}
}
</style>
<script>
var sqSize,pressed;
var inString="";
function init(){
if (window.innerHeight>window.innerWidth){
var content=document.getElementById("content").style;
content.width="100vw";
content.height="100vw";
content.marginTop="-50vw";
content.marginLeft="-50vw";
content.fontSize="7.5vw";
content.lineHeight="15vw";
}
var url=""+window.location.href;
if (url.endsWith("noob")){
document.getElementById("phonebinary").style.display="block";
}
console.log("Selected numbers will be visible here:");
}
function insertChar(e){
var code=e.keyCode;
if (code==32||code==48||code==49){
inString+=String.fromCharCode(code);
document.getElementById("phonebinary").value=inString;
}
}
function pushDig(input){
if (input==0){
inString+="0";
}else if (input==1){
inString+="1";
}else if (input==2){
inString="";
}else{
var btns=document.getElementsByClassName("btn");
for (i=0;i<4;i++){
btns[i].style.display="none";
}
document.getElementById("phonedecimal").style.display="none";
document.getElementById("thanks").style.display="block";
document.getElementById("phonebinary").style.display="none";
}
document.getElementsByClassName("btn")[input].style.animation="fade 300ms forwards 1";
pressed=input;
setTimeout(resetBtn,300);
parseBinary();
}
function resetBtn(){
document.getElementsByClassName("btn")[pressed].style.animation="initial";
}
function parseBinary(){
var input=inString,pure="";
var decimal=0,pow=0;
for (i=0;i<input.length;i++){
if (input.charAt(i)=='0'){
pure+=input.charAt(i);
}else if(input.charAt(i)=='1'){
decimal+=Math.floor(Math.pow(2,input.length-i-1));
pure+=input.charAt(i);
}
}
document.getElementById("phonedecimal").innerHTML=decimal;
document.getElementById("phonebinary").innerHTML=pure;
console.log("input: "+inString);
}
</script>
</head>
<body onload=init() onkeyup=parseBinary()>
<div id="content">
<div id="phonedecimal">write.</div>
<div id="phonebinary"></div>
<div class="btn" onclick=pushDig(0)>0</div>
<div class="btn" style="left:51.5%" onclick=pushDig(1)>1</div>
<div class="btn" style="top:73%" onclick=pushDig(2)>C</div>
<div class="btn" style="top:73%; left:51.5%" onclick=pushDig(3)>S</div>
<div id="thanks">thanks.</div>
</div>
</body>
</html>