-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
25 lines (20 loc) · 750 Bytes
/
Copy pathscripts.js
File metadata and controls
25 lines (20 loc) · 750 Bytes
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
document.addEventListener('DOMContentLoaded', function()
{
const textarea = document.getElementById('textArea');
// Écoutez les modifications de la textarea
var btn = document.getElementById('button');
btn.addEventListener('click', function()
{
const originalText = textarea.value;
hashString(originalText).then(hash => textarea.value = hash);
});
});
async function hashString(str)
{
const encoder = new TextEncoder();
const data = encoder.encode(str);
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
return hashHex;
}