-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
64 lines (50 loc) · 1.92 KB
/
main.js
File metadata and controls
64 lines (50 loc) · 1.92 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
document.addEventListener('DOMContentLoaded', () => {
hljs.highlightAll();
const functionSelect = document.getElementById('function-select');
const inputArea = document.getElementById('input-area');
const convertBtn = document.getElementById('convert-btn');
const outputArea = document.getElementById('output-area');
const copyBtn = document.getElementById('copy-btn');
const availableFunctions = [
'jsonToSQLUnion',
'paramsToSQLSet'
];
availableFunctions.forEach(funcName => {
const option = document.createElement('option');
option.value = funcName;
const displayName = funcName.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase());
option.textContent = displayName.replace(/SQL/g, 'SQL');
functionSelect.appendChild(option);
});
convertBtn.addEventListener('click', () => {
const selectedFunctionName = functionSelect.value;
const inputData = inputArea.value;
copyBtn.classList.remove('hidden');
if (!selectedFunctionName || !inputData) {
outputArea.textContent = 'Please select a function and provide input.';
return;
}
try {
const parsedInput = JSON.parse(inputData);
const selectedFunction = window[selectedFunctionName];
if (typeof selectedFunction === 'function') {
const result = selectedFunction(parsedInput);
resultHTML = hljs.highlight(result, { language: 'sql' }).value;
outputArea.innerHTML = resultHTML;
} else {
outputArea.textContent = `Error: Function '${selectedFunctionName}' not found.`;
}
} catch (error) {
outputArea.textContent = `Error: ${error.message}`;
}
});
copyBtn.addEventListener('click', () => {
const outputText = outputArea.textContent;
navigator.clipboard.writeText(outputText).then(() => {
copyBtn.textContent = 'Copied!';
setTimeout(() => {
copyBtn.textContent = 'Copy';
}, 2000);
});
})
});