forked from letterly/letterly.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi.html
293 lines (290 loc) · 12.9 KB
/
i.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<html dir="ltr"><head>
<style>
body, DOM{
background-color: #221a0f;
font-family: Verdana;
}
#content{
background-color: #fbebd4;
height: 54px;
width: 100%;
margin-bottom: 10px;
font-size: 44px;
font-weight: 700;
}
.number{
background-color: #f79a32;
}
.n{
color: #f79a32;
}
.operator{
background-color: #dc3958;
}
.system{
background-color: #d33682;
}
.o{
color: #dc3958;
}
.syntax{
background-color: #a57a4c;
}
.s{
color: #a57a4c;
}
.constant{
background-color: #889b4a;
}
.c{
color: #889b4a;
}
.equals{
background-color: #088649;
}
.input{
background-color: #8ab1b0;
}
h1{
text-align: center;
font-size: 48px;
color: #fbebd4;
}
button{
color: #fbebd4;
border: none;
font-size: 28px;
width: 50px;
height: 50px;
}
#writing-systems button{
width:260px;
height: 110px;
}
.o-:first-child, .o + .o-, .s + .o-{
color: #f79a32;
}
</style>
<script>
var script = "west-arabic"
var scripts = {
"west-arabic": "0123456789",
"east-arabic": "٠١٢٣٤٥٦٧٨٩",
"devanagari": "०१२३४५६७८९",
"bengali-assamese": "০১২৩৪৫৬৭৮৯",
"gujarati": "૦૧૨૩૪૫૬૭૮૯",
"tibetan": "༠༡༢༣༤༥༦༧༨༩",
"burmese": "၀၁၂၃၄၅၆၇၈၉",
"shan": "႐႑႒႓႔႕႖႗႘႙",
"thai": "๐๑๒๓๔๕๖๗๘๙",
"lao": "໐໑໒໓໔໕໖໗໘໙",
"khmer": "០១២៣៤៥៦៧៨៩",
"tamil": "௦௧௨௩௪௫௬௭௮௯",
"gurmukhi": "੦੧੨੩੪੫੬੭੮੯",
"kannada": "೦೧೨೩೪೫೬೭೮೯",
"mru": ["𖩠","𖩡","𖩢","𖩣","𖩤","𖩥","𖩦","𖩧","𖩨","𖩩"],
"chakma": ["𑄶", "𑄷", "𑄸", "𑄹", "𑄺", "𑄻", "𑄼", "𑄽", "𑄾", "𑄿"],
"rohingya": ["𐴰", "𐴱", "𐴲", "𐴳", "𐴴", "𐴵", "𐴶", "𐴷", "𐴸", "𐴹"],
"cham": "꩐꩑꩒꩓꩔꩕꩖꩗꩘꩙",
"sourashtra": "꣐꣑꣒꣓꣔꣕꣖꣗꣘꣙",
"nyiakeng-puachue-hmong": ["𞅀", "𞅁", "𞅂", "𞅃", "𞅄", "𞅅", "𞅆", "𞅇", "𞅈", "𞅉"],
}
function balancedParentheses(phrase){
if(phrase.includes("()")) return false
n = 0
for(x of phrase){
if(x == "(") n++
if(x == ")") n--
if(n < 0) return false
}
if(n == 0) return true
else return false
}
function render(id){
tp = id.charAt(0)
cn = id.charAt(1)
if(tp == "n" && cn != ".") cn = scripts[script][+cn]
document.getElementById("content").innerHTML += `<span class="${tp} ${id}">${cn}</span>`
}
function equals(){
if(!balancedParentheses(document.getElementById("content").textContent)){
alert("parentheses error")
return 0;
}
e = Array.from(document.getElementById("content").childNodes)
equation = []
// parses equation
console.log(e)
for(ex of e){
if(ex.nodeName == "SPAN"){
ex = ex.textContent
//
for(var p = 0; p <= 9; p++){
regex = new RegExp(scripts[script][p], "g");
ex = ex.replace(regex, p);
}
//
console.log(ex)
if((equation.length > 0) && (!isNaN(ex) || ex == ".")){
n = equation[equation.length-1]
if(!isNaN(n) || n == "." || (n == "-" && (equation.length == 1 ||"+-*/^".includes(equation[equation.length-2])))) equation[equation.length-1] += ex
else equation.push(ex)
}
else equation.push(ex)
}
}
console.log(equation)
newequation = []
// adds implicit multiplication sign x
for(second of equation){
first = newequation[newequation.length-1]
if(first == undefined) first = "+"
if(second == "(" && !("+-*/^".includes(first))) newequation.push("x")
else if("πe".includes(second) && !(isNaN(first))) newequation.push("x")
if(second == "π") second = "3.14159"
else if(second == "e") second = "2.71828"
newequation.push(second)
}
console.log(bruhmoment(newequation))
final = "" + bruhmoment(newequation)[0]
console.log(final)
for(var o = 0; o <= 9; o++){
regex = new RegExp(o, "g");
final = final.replace(regex, scripts[script][o]);
}
document.getElementById("content").innerHTML = `<span class="n">${final}</span>`
}
function del(){
d = document.getElementById("content")
if(d.hasChildNodes()) d.removeChild(d.lastChild)
}
//non button functions
function solvephrase(phrase){
newphrase = []
for(item of phrase.reverse()){
if(newphrase[newphrase.length-1] == "^"){
exp = Math.pow(item, newphrase[newphrase.length-2])
newphrase.pop()
newphrase.pop()
newphrase.push(exp)
}
else newphrase.push(item)
}
phrase = newphrase.reverse()
newphrase = []
for(item of phrase){
if(newphrase[newphrase.length-1] == "x"){
mult = newphrase[newphrase.length-2] * item
newphrase.pop()
newphrase.pop()
newphrase.push(mult)
}
else newphrase.push(item)
}
phrase = newphrase
newphrase = []
for(item of phrase){
if(newphrase[newphrase.length-1] == "*"){
mult = newphrase[newphrase.length-2] * item
newphrase.pop()
newphrase.pop()
newphrase.push(mult)
}
else if(newphrase[newphrase.length-1] == "/"){
div = newphrase[newphrase.length-2] / item
newphrase.pop()
newphrase.pop()
newphrase.push(div)
}
else newphrase.push(item)
}
phrase = newphrase
newphrase = []
for(item of phrase){
if(newphrase[newphrase.length-1] == "+"){
add = +newphrase[newphrase.length-2] + +item
newphrase.pop()
newphrase.pop()
newphrase.push(add)
}
else if(newphrase[newphrase.length-1] == "-"){
sub = newphrase[newphrase.length-2] - item
newphrase.pop()
newphrase.pop()
newphrase.push(sub)
}
else newphrase.push(item)
}
return newphrase
}
function bruhmoment(phrase){
phrase.unshift("(")
phrase.push(")")
while(phrase.includes(")")){
x = phrase.slice(0, phrase.indexOf(")"))
n = x.lastIndexOf("(")
g = phrase.slice(n+1, phrase.indexOf(")"))
phrase = phrase.slice(0, n).concat(solvephrase(g), phrase.slice(phrase.indexOf(")")+1))
}
return phrase
}
function system(id){
document.getElementById("content").innerHTML = ""
script = id
for(var x = 0; x <= 9; x++){
document.getElementById("n" + x).textContent = scripts[script][x]
}
}
</script>
</head>
<body>
<h1>HarrisCalc</h1>
<div id="content"><span class="o o-">-</span><span class="n n3">3</span><span class="n n4">4</span><span class="o o-">-</span><span class="o o-">-</span><span class="n n5">5</span></div>
<div id="buttons">
<button id="n0" class="number" onclick="render(this.id)">0</button>
<button id="n1" class="number" onclick="render(this.id)">1</button>
<button id="n2" class="number" onclick="render(this.id)">2</button>
<button id="n3" class="number" onclick="render(this.id)">3</button>
<button id="n4" class="number" onclick="render(this.id)">4</button>
<button id="n5" class="number" onclick="render(this.id)">5</button>
<button id="n6" class="number" onclick="render(this.id)">6</button>
<button id="n7" class="number" onclick="render(this.id)">7</button>
<button id="n8" class="number" onclick="render(this.id)">8</button>
<button id="n9" class="number" onclick="render(this.id)">9</button>
<button id="n." class="number" onclick="render(this.id)">.</button>
<button id="s(" class="syntax" onclick="render(this.id)">(</button>
<button id="s)" class="syntax" onclick="render(this.id)">)</button>
<button id="o+" class="operator" onclick="render(this.id)">+</button>
<button id="o-" class="operator" onclick="render(this.id)">-</button>
<button id="o*" class="operator" onclick="render(this.id)">*</button>
<button id="o/" class="operator" onclick="render(this.id)">/</button>
<button id="o^" class="operator" onclick="render(this.id)">^</button>
<button id="cπ" class="constant" onclick="render(this.id)">π</button>
<button id="ce" class="constant" onclick="render(this.id)">e</button>
<button id="e=" class="equals" onclick="equals()">=</button>
<button id="iDEL" class="input" onclick="del()">del</button>
</div>
<br>
<div id="writing-systems">
<button id="west-arabic" class="system" onclick="system(this.id)">West Arabic<br>0123456789</button>
<button id="east-arabic" class="system" onclick="system(this.id)">East Arabic<br>٠١٢٣٤٥٦٧٨٩</button>
<button id="devanagari" class="system" onclick="system(this.id)">Devanagari<br>०१२३४५६७८९</button>
<button id="bengali-assamese" class="system" onclick="system(this.id)">Bengali-Assamese<br>০১২৩৪৫৬৭৮৯</button>
<button id="gujarati" class="system" onclick="system(this.id)">Gujarati<br>૦૧૨૩૪૫૬૭૮૯</button>
<button id="tibetan" class="system" onclick="system(this.id)">Tibetan<br>༠༡༢༣༤༥༦༧༨༩</button>
<button id="burmese" class="system" onclick="system(this.id)">Burmese<br>၀၁၂၃၄၅၆၇၈၉</button>
<button id="shan" class="system" onclick="system(this.id)">Shan<br>႐႑႒႓႔႕႖႗႘႙</button>
<button id="thai" class="system" onclick="system(this.id)">Thai<br>๐๑๒๓๔๕๖๗๘๙</button>
<button id="lao" class="system" onclick="system(this.id)">Lao<br>໐໑໒໓໔໕໖໗໘໙</button>
<button id="khmer" class="system" onclick="system(this.id)">Khmer<br>០១២៣៤៥៦៧៨៩</button>
<button id="tamil" class="system" onclick="system(this.id)">Tamil<br>௦௧௨௩௪௫௬௭௮௯</button>
<button id="gurmukhi" class="system" onclick="system(this.id)">Gurmukhi<br>੦੧੨੩੪੫੬੭੮੯</button>
<button id="kannada" class="system" onclick="system(this.id)">Kannada<br>೦೧೨೩೪೫೬೭೮೯</button>
<button id="mru" class="system" onclick="system(this.id)">Mru<br>𖩠𖩡𖩢𖩣𖩤𖩥𖩦𖩧𖩨𖩩</button>
<button id="chakma" class="system" onclick="system(this.id)">Chakma<br>𑄶𑄷𑄸𑄹𑄺𑄻𑄼𑄽𑄾𑄿</button>
<button id="cham" class="system" onclick="system(this.id)">Cham<br>꩐꩑꩒꩓꩔꩕꩖꩗꩘꩙</button>
<button id="rohingya" class="system" onclick="system(this.id)">Rohingya<br>𐴰𐴱𐴲𐴳𐴴𐴵𐴶𐴷𐴸𐴹</button>
<button id="sourashtra" class="system" onclick="system(this.id)">Sourashtra<br>꣐꣑꣒꣓꣔꣕꣖꣗꣘꣙</button>
<button id="nyiakeng-puachue-hmong" class="system" onclick="system(this.id)">Nyiakeng Puachue<br>𞅀𞅁𞅂𞅃𞅄𞅅𞅆𞅇𞅈𞅉</button>
</div>
</body></html>