-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
84 lines (68 loc) · 2.41 KB
/
script.js
File metadata and controls
84 lines (68 loc) · 2.41 KB
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
const headerCriptage = document.querySelector('.header-criptage');
const crypte = document.querySelector('.crypte');
const uncrypte = document.querySelector('.uncrypte');
const cripte = document.querySelector('.cripte');
const uncripte = document.querySelector('.uncripte');
const copyMessageCripter = document.querySelector('#copyMessageCripter');
const copyMessageDécripter = document.querySelector('#copyMessageDécripter');
const textInfo = document.querySelectorAll('.textInfo');
textInfo.forEach(copies => {
copies.classList.add('disappear');
});
function cripteMessage() {
headerCriptage.style.display = "none";
crypte.style.display = "flex";
uncrypte.style.display = "none";
cripte.value = "";
copyMessageCripter.textContent = "";
}
function uncripteMessage() {
headerCriptage.style.display = "none";
crypte.style.display = "none";
uncrypte.style.display = "flex";
uncripte.value = "";
copyMessageDécripter.textContent = "";
}
function textToBinary(text) {
return text.split('').map(char => {
return char.charCodeAt(0).toString(2).padStart(8, '0');
}).join(' ');
}
function binaryToText(binary) {
return binary.split(' ').map(bin => {
return String.fromCharCode(parseInt(bin, 2));
}).join('');
}
cripte.addEventListener('input', () => {
copyMessageCripter.textContent = textToBinary(cripte.value);
});
uncripte.addEventListener('input', () => {
copyMessageDécripter.textContent = binaryToText(uncripte.value);
});
function copyText(elementId) {
const text = document.getElementById(elementId).textContent;
if (text.trim() !== '') {
navigator.clipboard.writeText(text);
const icons = document.querySelectorAll('.copied');
icons.forEach(icon => {
icon.classList.remove('bi-copy');
icon.classList.add('bi-check2-square');
});
textInfo.forEach(copies => {
copies.classList.remove('disappear');
copies.classList.add('appear');
});
setTimeout(() => {
icons.forEach(icon => {
icon.classList.add('bi-copy');
icon.classList.remove('bi-check2-square');
});
textInfo.forEach(copies => {
copies.classList.remove('appear');
copies.classList.add('disappear');
});
}, 2000);
} else {
alert('Entrez quelque chose');
}
}