-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
51 lines (46 loc) · 1.42 KB
/
scripts.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
function sortLines() {
const textArea = document.getElementById('textArea');
let lines = textArea.value.trim().split('\n').filter(line => line.trim() !== '');
const sortMethod = document.getElementById('sortMethod').value;
switch (sortMethod) {
case 'alphabetic':
lines.sort((a, b) => a.localeCompare(b));
break;
case 'alphabeticReverse':
lines.sort((a, b) => b.localeCompare(a));
break;
case 'length':
lines.sort((a, b) => a.length - b.length);
break;
case 'lengthReverse':
lines.sort((a, b) => b.length - a.length);
break;
case 'reverse':
lines.reverse();
break;
case 'shuffle':
lines = shuffleArray(lines);
break;
default:
break;
}
textArea.value = lines.join('\n');
}
function shuffleArray(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;
}
function copyText() {
const textArea = document.getElementById('textArea');
textArea.select();
textArea.setSelectionRange(0, 99999); // For mobile devices
try {
document.execCommand('copy');
alert('Text copied to clipboard');
} catch (err) {
alert('Failed to copy text');
}
}