-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
50 lines (45 loc) · 1.43 KB
/
main.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
const hpArray = [] // add text from data/hp41.txt
const submitBtn = document.getElementById("submit");
const ipsumText = document.getElementById("ipsumText");
const copyBtn = document.getElementById("copyBtn");
const textContainer = document.getElementById("textContainer");
let loremText = "";
function hpIpsum(length) {
let max = hpArray.length - length;
let randomNum = Math.floor(Math.random() * Math.floor(max));
var i = 0;
while (i < length) {
loremText += hpArray[randomNum] + " \n";
randomNum++;
i++;
console.log(i, randomNum);
}
return loremText;
}
function getText(event) {
event.preventDefault();
loremText = "";
const sentenceNum = document.getElementById("sentenceNum").value;
if (!sentenceNum) {
alert('Please enter number of sentences to proceed!');
return;
}
hpIpsum(sentenceNum);
ipsumText.textContent = loremText;
copyBtn.style.display = "block";
textContainer.style.display = "block";
}
function copyText() {
const el = document.createElement('textarea');
el.value = loremText;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
alert('Text Copied!');
}
submitBtn.addEventListener('click', getText);
copyBtn.addEventListener('click', copyText);