@@ -24,9 +24,9 @@ waitForElm('.buttons > div:last-child > button:last-child').then((elm) => {
24
24
addRand . addEventListener ( 'click' , function ( ) {
25
25
while ( i != 0 ) {
26
26
if ( ! multiMode ) {
27
- textArea . value += characters [ Math . floor ( Math . random ( ) * 163 ) ] . innerText ;
27
+ textArea . value += characters [ getRandomChar ( ) ] . innerText ;
28
28
} else {
29
- multiArea . value += characters [ Math . floor ( Math . random ( ) * 163 ) ] . innerText ;
29
+ multiArea . value += characters [ getRandomChar ( ) ] . innerText ;
30
30
}
31
31
i --
32
32
} ;
@@ -50,7 +50,7 @@ waitForElm('.buttons > div:last-child > button:last-child').then((elm) => {
50
50
} )
51
51
52
52
53
- function waitForElm ( selector ) {
53
+ function waitForElm ( selector ) { // https://stackoverflow.com/a/61511955
54
54
return new Promise ( resolve => {
55
55
if ( document . querySelector ( selector ) ) {
56
56
return resolve ( document . querySelector ( selector ) ) ;
@@ -69,4 +69,40 @@ function waitForElm(selector) {
69
69
subtree : true
70
70
} ) ;
71
71
} ) ;
72
+ }
73
+
74
+ function getRandomChar ( ) { // TODO: Impove this
75
+ let uprng = document . getElementById ( 'uprng' ) . checked
76
+ let downrng = document . getElementById ( 'downrng' ) . checked
77
+ let overlaprng = document . getElementById ( 'overlaprng' ) . checked
78
+ let joinrng = document . getElementById ( 'joinrng' ) . checked
79
+ let upchars = 52 //lineCount('./chars/up.txt')
80
+ let downchars = 40 //lineCount('./chars/down.txt')
81
+ let overlapchars = 67 //lineCount('./chars/overlap.txt')
82
+ let joinchars = 4 //lineCount('./chars/join.txt')
83
+ let char = Math . floor ( Math . random ( ) * ( upchars + downchars + overlapchars + joinchars + 1 ) )
84
+ console . log ( char + ' ' + upchars )
85
+ if ( char <= upchars && uprng ) { // TODO: I hate this must fix
86
+ return char
87
+ } else if ( char <= upchars + downchars && char >= upchars && downrng ) {
88
+ return char
89
+ } else if ( char <= upchars + downchars + overlapchars
90
+ && char >= upchars + downchars && overlaprng ) {
91
+ return char
92
+ } else if ( char <= upchars + downchars + overlapchars + joinchars
93
+ && char >= upchars + downchars + overlapchars && joinrng ) { // Fails if only join selected, too much recursion
94
+ return char
95
+ } else {
96
+ return getRandomChar ( )
97
+ }
98
+ }
99
+
100
+ function lineCount ( file ) {
101
+ return fetch ( file )
102
+ . then ( response => response . text ( ) )
103
+ . then ( fileContent => {
104
+ const lines = fileContent . split ( '\n' ) ;
105
+ console . log ( lines . length )
106
+ return lines . length ;
107
+ } )
72
108
}
0 commit comments