-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
71 lines (57 loc) · 1.75 KB
/
script.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
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
// Variables
const range = document.querySelector("#paragraphsRange");
const field = document.querySelector("#paragraphsNumber");
const result = document.querySelector(".result");
const send = document.querySelector(".send");
// Range and Number Input linking
range.addEventListener('input', function (e) {
field.value = e.target.value;
})
field.addEventListener('input', function (e) {
range.value = e.target.value;
})
/* Generate a phrase built by picking an item from each array (which I call text collections). Then, repeats the process a few times, randomly defined, to create a paragraph.*/
function generateParagraph() {
const tempPhrase = [];
for (let i = 0; i < calcParagraphLength(); i++) {
tempPhrase.push(
text.forEach((textCollection, i) => {
tempPhrase.push(shuffleArrays(textCollection)[0])
})
)
}
return tempPhrase.join(" ");
}
function generateText() {
let resultString = [];
for (let i = 0; i < parseInt(field.value); i++) {
resultString.push(
`${generateParagraph()} <br> <br>`
)
result.innerHTML = resultString.join("");
}
return result.textContent;
}
// array sort randomizing function
function shuffleArrays(array) {
for (let i = array.length - 1; i >= 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]]
}
return array;
}
// length of paragraph calculating function
function calcParagraphLength() {
return Math.ceil(Math.random() * 2);
}
send.addEventListener('click', generateText)
result.addEventListener('click', function(event){
document.execCommand("copy");
})
result.addEventListener("copy", function(event){
if(event.clipboardData) {
event.clipboardData.setData('text/plain', result.textContent);
alert("Textão copiado.")
}
event.preventDefault();
})