Skip to content

Commit 898398c

Browse files
committed
Add navigation links to Config Editor and JSON Visual Editor pages
1 parent f0acd72 commit 898398c

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

ui/chrome/config/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<header>
22
<h1>Config Editor</h1>
33
<nav>
4+
<a href="../index.html">Back</a>
45
<a href="launcherconfig.html">Launcher Config</a>
56
<a href="userconfig.html">User Config</a>
67
</nav>

ui/chrome/config/launcherconfig.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
</style>
2525
</head>
2626
<body>
27+
<a href="index.html">Back</a>
2728
<h1>JSON Visual Editor</h1>
2829
<div id="json-editor" class="json-editor"></div>
2930
<button onclick="addEntry()">Add Entry</button>

ui/chrome/config/userconfig.html

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>JSON Visual Editor</title>
7+
<style>
8+
body {
9+
font-family: Arial, sans-serif;
10+
padding: 20px;
11+
}
12+
.json-editor {
13+
margin-top: 20px;
14+
}
15+
.json-entry {
16+
display: flex;
17+
align-items: center;
18+
margin-bottom: 10px;
19+
}
20+
.json-entry input {
21+
margin-left: 10px;
22+
padding: 5px;
23+
}
24+
</style>
25+
</head>
26+
<body>
27+
<a href="index.html">Back</a>
28+
<h1>JSON Visual Editor</h1>
29+
<div id="json-editor" class="json-editor"></div>
30+
<button onclick="addEntry()">Add Entry</button>
31+
<button onclick="saveJson()">Save JSON</button>
32+
33+
<script type="module">
34+
const jsonEditor = document.getElementById('json-editor');
35+
const jsonData = await mcAPI.getConfig('client') || {};
36+
37+
window.addEntry = function(key = '', value = '') {
38+
const entryDiv = document.createElement('div');
39+
entryDiv.className = 'json-entry';
40+
41+
const inputType = typeof value === 'boolean' ? 'checkbox'
42+
: typeof value === 'number' ? 'number'
43+
: 'text';
44+
45+
const isCheckbox = inputType === 'checkbox';
46+
const valueAttr = isCheckbox ? '' : `value="${value}"`;
47+
const checkedAttr = isCheckbox && value ? 'checked' : '';
48+
49+
entryDiv.innerHTML = `
50+
<input type="text" placeholder="Key" value="${key}" oninput="updateJson(this, 'key')">
51+
<input type="${inputType}" ${valueAttr} ${checkedAttr} oninput="updateJson(this, 'value')">
52+
<button onclick="removeEntry(this)">Remove</button>
53+
`;
54+
jsonEditor.appendChild(entryDiv);
55+
}
56+
57+
window.updateJson = function (input, type) {
58+
const entryDiv = input.parentElement;
59+
const keyInput = entryDiv.children[0];
60+
const valueInput = entryDiv.children[1];
61+
62+
const oldKey = keyInput.dataset.oldKey || keyInput.value;
63+
const key = keyInput.value;
64+
65+
if (type === 'key') {
66+
if (oldKey && oldKey !== key) {
67+
delete jsonData[oldKey];
68+
}
69+
keyInput.dataset.oldKey = key;
70+
}
71+
72+
if (key) {
73+
let value;
74+
if (valueInput.type === 'checkbox') {
75+
value = valueInput.checked;
76+
} else if (valueInput.type === 'number') {
77+
value = parseFloat(valueInput.value);
78+
} else {
79+
value = valueInput.value;
80+
}
81+
82+
jsonData[key] = value;
83+
}
84+
}
85+
86+
window.removeEntry = function (button) {
87+
const entryDiv = button.parentElement;
88+
const keyInput = entryDiv.children[0];
89+
delete jsonData[keyInput.value];
90+
jsonEditor.removeChild(entryDiv);
91+
}
92+
93+
window.saveJson = function saveJson() {
94+
const jsonString = JSON.stringify(jsonData, null, 4);
95+
console.log(jsonString);
96+
mcAPI.saveConfig('client', jsonString)
97+
.then(() => {
98+
alert('JSON saved successfully!');
99+
})
100+
.catch((error) => {
101+
console.error('Error saving JSON:', error);
102+
alert('Failed to save JSON.');
103+
});
104+
}
105+
106+
// Populate the editor with existing JSON data
107+
for (const [key, value] of Object.entries(jsonData)) {
108+
addEntry(key, value);
109+
}
110+
</script>
111+
</body>
112+
</html>

0 commit comments

Comments
 (0)