-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.js
More file actions
66 lines (57 loc) · 2.16 KB
/
Copy pathparser.js
File metadata and controls
66 lines (57 loc) · 2.16 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
import { IPSParser } from './ips-parser-core.js';
// UI Controller
document.addEventListener('DOMContentLoaded', () => {
const ipsInput = document.getElementById('ipsInput');
const parseBtn = document.getElementById('parseBtn');
const clearBtn = document.getElementById('clearBtn');
const copyBtn = document.getElementById('copyBtn');
const errorMessage = document.getElementById('errorMessage');
const outputSection = document.getElementById('output');
const reportOutput = document.getElementById('reportOutput');
parseBtn.addEventListener('click', () => {
const content = ipsInput.value.trim();
if (!content) {
showError('Please paste IPS file contents first.');
return;
}
try {
const parser = new IPSParser(content);
parser.parse();
const formatted = parser.formatReport();
reportOutput.textContent = formatted;
outputSection.style.display = 'block';
errorMessage.style.display = 'none';
} catch (error) {
showError(error.message);
outputSection.style.display = 'none';
}
});
clearBtn.addEventListener('click', () => {
ipsInput.value = '';
outputSection.style.display = 'none';
errorMessage.style.display = 'none';
ipsInput.focus();
});
copyBtn.addEventListener('click', () => {
const text = reportOutput.textContent;
navigator.clipboard.writeText(text).then(() => {
const originalText = copyBtn.textContent;
copyBtn.textContent = 'Copied!';
setTimeout(() => {
copyBtn.textContent = originalText;
}, 2000);
}).catch(err => {
showError('Failed to copy to clipboard: ' + err.message);
});
});
function showError(message) {
errorMessage.textContent = message;
errorMessage.style.display = 'block';
}
// Allow parsing with Enter key (Ctrl/Cmd + Enter)
ipsInput.addEventListener('keydown', (e) => {
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
parseBtn.click();
}
});
});