-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.mjs
235 lines (173 loc) · 5.57 KB
/
app.mjs
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
function startApp() {
// Your entire app should not necessarily be coded inside this
// single function (though there's no penalty for that),
// so create and use/call additional functions from here
// pls remove the below and make some magic in here!
/////////////////////////////////////////////
//DECLARATIONS
//////////////////////////////////////////////
const mainTexts = document.querySelector('#main-texts');
const redactTexts = document.querySelector('#redact-texts');
const sign = document.querySelector('#sign');
const redactBtn = document.querySelector('#redact-btn');
const returnBtn = document.querySelector('#return-btn');
const clearBtn = document.querySelector('#clear-btn');
const copyBtn = document.querySelector('#copy-btn');
const shareBtn = document.querySelector('#share-btn');
const scanned = document.querySelector('#scanned');
const matched = document.querySelector('#matched');
const scrambled = document.querySelector('#scrambled');
const timed = document.querySelector('#timed');
const questNavButton = document.querySelector('.quest');
const closeNav = document.querySelector('.close');
const nav = document.querySelector("nav");
const mainPage = document.querySelector("main");
let main, redact, returnText, dont, redactStatus;
/////////////////////////////////////////////
/////////////////////////////////////////////
// EVENT LISTENER
/////////////////////////////////////////////
// OUESTION AND CLOSE MARK BUTTON
questNavButton.addEventListener("click", () => {
nav.classList.toggle("hide");
closeNav.classList.toggle("hide");
mainPage.classList.toggle("show");
});
closeNav.addEventListener("click", () => {
nav.classList.toggle("hide");
closeNav.classList.toggle("hide");
mainPage.classList.toggle("show");
});
//REDACT BUTT0N
redactBtn.addEventListener("click", (e) => {
const startTime = Date.now();
if (returnText) {
returnBtn.click();
}
let main = mainTexts.value.split(" ");
let redact = redactTexts.value.split(" ");
if (!returnText) {
returnText = mainTexts.value.split(" ");
}
if ((main.length == 1) && (main[0] == '')) {
return;
}
let [scan, match, scramble] = redacting(main, redact);
mainTexts.value = main.join(" ");
const endTime = Date.now();
let timeCompleted = `${endTime - startTime}`;
stats(scan, match, scramble, timeCompleted);
});
//RETURN BUTTON
returnBtn.addEventListener("click", (e) => {
if (returnText) {
returnTexts(returnText);
returnText = "";
}
});
//CLEAR BUTTON
clearBtn.addEventListener("click", (e) => {
mainTexts.value = "";
redactTexts.value = "";
returnText = "";
sign.value = "";
scanned.innerText = `${0}`;
matched.innerText = `${0}`;
scrambled.innerText = `${0}`;
timed.innerText = `${0}`;
});
//COPY BUTTON
copyBtn.addEventListener("click", (e) => {
dont = false;
mainTexts.select();
mainTexts.setSelectionRange(0, 99999);
copyBtn.innerText = "Copied";
copyBtn.classList.toggle("pinned");
navigator.clipboard.writeText(mainTexts.value).then(function() {
console.log('Async: Copying to clipboard was successful!');
}, function(err) {
console.error('Async: Could not copy text: ', err);
});
setTimeout(() => {
copyBtn.innerText = "Copy";
copyBtn.classList.toggle("pinned");
}, 2000);
setTimeout(() => {
dont = true;
mainTexts.blur();
}, 1000);
});
// SHARE BUTTON
shareBtn.addEventListener("click", async (e) => {
let data = {
title: "",
text: `${mainTexts.value}`
}
try {
await navigator.share(data);
} catch (err) {
console.log(err);
}
});
//SIGN INPUT
sign.addEventListener('change', (e) => {
returnBtn.click();
});
//MAIN INPUT
mainTexts.addEventListener('focus', (e) => {
// mainTexts.select();
// mainTexts.setSelectionRange(0, 99999);
if (dont) {
returnBtn.click();
}
});
mainTexts.addEventListener('keyup', (e) => {
});
// });
//REDACT INPUT
redactTexts.addEventListener('keydown', (e) => {
returnBtn.click();
});
/////////////////////////////////////////////
/////////////////////////////////////////////
//FUNCTIONS
/////////////////////////////////////////////
//REDACTING FUNCTION
const redacting = (main, redact) => {
let scanned = main.length, matched = 0, scrambled = 0;
for (let i = 0; i < redact.length; i++) {
for (let j = 0; j < main.length; j++) {
if (redact[i].toUpperCase() == main[j].toUpperCase()) {
let count = main[j].length;
matched += 1;
scrambled += count;
main[j] = "";
for (let v = 0; v < count; v++) {
main[j] += (sign.value || "*");
}
}
}
}
return ([scanned, matched, scrambled]);
}
//RETURN FUNCTION
const returnTexts = (texts) => {
mainTexts.value = texts.join(" ");
scanned.innerText = `${0}`;
matched.innerText = `${0}`;
timed.innerText = `${0}`;
scrambled.innerText = `${0}`;
}
//STATS FUNCTION
const stats = (scan, match, scramble, timeCompleted) => {
scanned.innerText = `${scan}`;
matched.innerText = `${match}`;
scrambled.innerText = `${scramble}`;
timed.innerText = `${timeCompleted}`;
}
/////////////////////////////////////////////
/////////////////////////////////////////////
};
// ======= DO NOT EDIT ============== //
export default startApp;
// ======= EEND DO NOT EDIT ========= //