-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
29 lines (26 loc) · 932 Bytes
/
app.js
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
function bionicRead() {
let textarea = document.getElementById("textarea");
let paragraph = textarea.value;
// Check if the input is empty
if (paragraph.trim() === "") {
alert("Please enter some text.");
return;
}
let words = paragraph.split(/\s+/);
let formattedParagraph = "";
for (let i = 0; i < words.length; i++) {
let half = words[i].substr(0, Math.round(words[i].length / 2));
let remHalf = words[i].substr(Math.round(words[i].length / 2));
formattedParagraph += "<strong>" + half + "</strong>" + remHalf + " ";
}
document.getElementById("below").innerHTML = formattedParagraph;
}
// Add keyboard shortcut to trigger the function
document
.getElementById("textarea")
.addEventListener("keydown", function (event) {
if (event.key === "Enter" && !event.shiftKey) {
bionicRead();
event.preventDefault(); // Prevent the default behavior of the Enter key
}
});