-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
38 lines (35 loc) · 1.4 KB
/
script.js
File metadata and controls
38 lines (35 loc) · 1.4 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
document.getElementById('createLink').addEventListener('click', function() {
const message = document.getElementById('message').value;
if (message.trim() === '') {
alert('Prosím, napište zprávu.');
return;
}
fetch('save_message.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'message=' + encodeURIComponent(message)
})
.then(response => response.json())
.then(data => {
const link = `${window.location.origin}${window.location.pathname.replace('index.html', '')}view.php?id=${data.id}#${data.password}`;
const resultDiv = document.getElementById('result');
resultDiv.innerHTML = `
<p>Váš odkaz je:</p>
<input type="text" id="linkInput" value="${link}" readonly>
<button onclick="copyToClipboard()">Kopírovat odkaz</button>
`;
});
});
function copyToClipboard() {
const linkInput = document.getElementById('linkInput');
linkInput.select();
linkInput.setSelectionRange(0, 99999); // Pro mobilní zařízení
navigator.clipboard.writeText(linkInput.value).then(() => {
alert('Odkaz byl zkopírován do schránky.');
}, (err) => {
console.error('Nepodařilo se zkopírovat text: ', err);
alert('Nepodařilo se zkopírovat odkaz. Prosím, zkopírujte ho ručně.');
});
}