-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_script.js
55 lines (43 loc) · 2.19 KB
/
main_script.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
52
53
54
55
loadPythonAndSources();
document.addEventListener('DOMContentLoaded', function() {
const outputDiv = document.getElementById('output');
const inputDiv = document.getElementById('input');
const copyButton = document.getElementById('copyButton');
// Store the original button HTML
const originalButtonHTML = copyButton.innerHTML;
let isScrolling = false;
const toggleDetails = document.querySelector('.toggle-details');
const detailsContent = document.querySelector('.details-content');
const toggleIcon = document.querySelector('.toggle-icon');
// Create a debounced version of updateOutput
const debouncedUpdateOutput = debounce(() => {
updateOutput(inputDiv, outputDiv).catch(error => {
console.error('Debounced update error:', error);
});
}, 300);
copyButton.addEventListener('click', function() {
const textToCopy = outputDiv.innerText;
navigator.clipboard.writeText(textToCopy).then(function() {
// Visual feedback
copyButton.innerHTML = `<img src="img/done_icon.png" alt="Copy" class="copy-icon">Скапіравана`;
setTimeout(() => {
// Reset to the original HTML
copyButton.innerHTML = originalButtonHTML;
}, 2000);
}).catch(function(err) {
console.error('Failed to copy text: ', err);
// Ensure the button resets even if copying fails
copyButton.innerHTML = originalButtonHTML;
});
});
toggleDetails.addEventListener('click', () => {
detailsContent.style.display = detailsContent.style.display === 'none' ? 'block' : 'none';
toggleIcon.style.transform = detailsContent.style.display === 'none' ? 'rotate(0deg)' : 'rotate(180deg)';
});
inputDiv.addEventListener('paste', handlePaste);
outputDiv.addEventListener('copy', handleCopy);
inputDiv.addEventListener('input', debouncedUpdateOutput);
// Add scroll event listeners to both textareas
inputDiv.addEventListener('scroll', () => synchronizeScroll(inputDiv, outputDiv, isScrolling));
outputDiv.addEventListener('scroll', () => synchronizeScroll(outputDiv, inputDiv, isScrolling));
});