-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
71 lines (55 loc) · 2.79 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function addFindReplaceOption() {
const findReplaceOptions = document.getElementById('findReplaceOptions');
const newOption = document.createElement('div');
newOption.classList.add('mb-4', 'find-replace-option');
newOption.innerHTML = `
<label for="findText" class="block text-sm font-medium text-gray-300">Find:</label>
<input type="text" class="w-full p-2 border rounded-md find-input" placeholder="Text to find...">
<label for="replaceText" class="block text-sm font-medium text-gray-300 mt-2">Replace with:</label>
<input type="text" class="w-full p-2 border rounded-md" placeholder="Replacement text...">
<button onclick="removeFindReplaceOption(this)" class="bg-red-500 text-white px-4 py-2 rounded-md ml-2">Remove</button>
`;
findReplaceOptions.appendChild(newOption);
}
function removeFindReplaceOption(button) {
const optionToRemove = button.parentElement;
optionToRemove.remove();
}
function downloadText() {
const modifiedText = document.getElementById('inputText').value;
const blob = new Blob([modifiedText], { type: 'text/plain' });
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = 'modified_text.txt';
link.click();
}
function copyToClipboard() {
const modifiedText = document.getElementById('inputText').value;
navigator.clipboard.writeText(modifiedText)
.then(() => alert('Text copied to clipboard'))
.catch(err => console.error('Unable to copy text', err));
}
function addFindReplaceOption() {
const findReplaceOptions = document.getElementById('findReplaceOptions');
const newOption = document.createElement('div');
newOption.classList.add('mb-4', 'find-replace-option');
newOption.innerHTML = `
<label for="findText" class="block text-sm font-medium text-gray-300">Find:</label>
<input type="text" class="w-full p-2 border rounded-md find-input" placeholder="Text to find...">
<label for="replaceText" class="block text-sm font-medium text-gray-300 mt-2">Replace with:</label>
<input type="text" class="w-full p-2 border rounded-md" placeholder="Replacement text...">
<button onclick="removeFindReplaceOption(this)" class="bg-red-500 text-white px-2 py-1 rounded-md mt-2">Remove</button>
`;
findReplaceOptions.appendChild(newOption);
}
function removeFindReplaceOption(button) {
const findReplaceOption = button.closest('.find-replace-option');
findReplaceOption.remove();
}
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js').then(registration => {
console.log('Service Worker registered with scope:', registration.scope);
}).catch(error => {
console.error('Service Worker registration failed:', error);
});
}