Create menu_json.html
Browse files- menu_json.html +129 -0
menu_json.html
ADDED
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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>Menu Editor</title>
|
7 |
+
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css">
|
8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/9.9.2/jsoneditor.min.css" />
|
9 |
+
<style>
|
10 |
+
body {
|
11 |
+
font-family: Arial, sans-serif;
|
12 |
+
text-align: center;
|
13 |
+
background-color: #f0f0f0;
|
14 |
+
margin: 0;
|
15 |
+
padding: 0;
|
16 |
+
max-height: 250px; /* Устанавливаем максимальную высоту страницы */
|
17 |
+
}
|
18 |
+
h1 {
|
19 |
+
background-color: #4CAF50;
|
20 |
+
color: white;
|
21 |
+
padding: 20px;
|
22 |
+
margin: 0;
|
23 |
+
border-bottom: 2px solid #388E3C;
|
24 |
+
}
|
25 |
+
.input-row {
|
26 |
+
display: flex;
|
27 |
+
justify-content: center;
|
28 |
+
gap: 10px;
|
29 |
+
margin-top: 20px;
|
30 |
+
}
|
31 |
+
.input-row input, .input-row textarea {
|
32 |
+
padding: 10px;
|
33 |
+
font-size: 16px;
|
34 |
+
border: 1px solid #ccc;
|
35 |
+
border-radius: 5px;
|
36 |
+
}
|
37 |
+
#jsoneditor {
|
38 |
+
width: 50%;
|
39 |
+
height: 300px;
|
40 |
+
margin: 20px auto;
|
41 |
+
}
|
42 |
+
#addButton, #saveToClipboard {
|
43 |
+
color: white;
|
44 |
+
background-color: #4CAF50;
|
45 |
+
border: none;
|
46 |
+
cursor: pointer;
|
47 |
+
padding: 10px 20px;
|
48 |
+
font-size: 16px;
|
49 |
+
border-radius: 5px;
|
50 |
+
margin-top: 20px;
|
51 |
+
}
|
52 |
+
#addButton:hover, #saveToClipboard:hover {
|
53 |
+
background-color: #388E3C;
|
54 |
+
}
|
55 |
+
.jsoneditor-menu {
|
56 |
+
background-color: #4CAF50 !important;
|
57 |
+
border-bottom: 1px solid #388E3C !important;
|
58 |
+
}
|
59 |
+
.jsoneditor{
|
60 |
+
border: 1px #4CAF50 !important;
|
61 |
+
border-bottom: 2px solid #388E3C !important;
|
62 |
+
}
|
63 |
+
</style>
|
64 |
+
</head>
|
65 |
+
<body>
|
66 |
+
<h1>Редактор меню</h1>
|
67 |
+
<div>
|
68 |
+
<div class="input-row">
|
69 |
+
<label for="buttonId">id кнопки:</label>
|
70 |
+
<input type="text" id="buttonId" placeholder="Введите id кнопки">
|
71 |
+
<label for="pageLink">Ссылка на страницу:</label>
|
72 |
+
<input type="text" id="pageLink" placeholder="Введите ссылку">
|
73 |
+
</div>
|
74 |
+
<button id="addButton">Добавить кнопку</button>
|
75 |
+
<button id="saveToClipboard">Сохранить в буфер обмена</button>
|
76 |
+
</div>
|
77 |
+
<div id="jsoneditor"></div>
|
78 |
+
|
79 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/9.9.2/jsoneditor.min.js"></script>
|
80 |
+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/toastify-js"></script>
|
81 |
+
<script>
|
82 |
+
document.addEventListener('DOMContentLoaded', function() {
|
83 |
+
const container = document.getElementById('jsoneditor');
|
84 |
+
const options = {
|
85 |
+
mode: 'code',
|
86 |
+
modes: ['code', 'tree'],
|
87 |
+
onError: function(err) {
|
88 |
+
alert(err.toString());
|
89 |
+
}
|
90 |
+
};
|
91 |
+
const editor = new JSONEditor(container, options);
|
92 |
+
let menuItems = [];
|
93 |
+
editor.set(menuItems);
|
94 |
+
|
95 |
+
document.getElementById('addButton').addEventListener('click', function() {
|
96 |
+
const buttonId = document.getElementById('buttonId').value;
|
97 |
+
const pageLink = document.getElementById('pageLink').value;
|
98 |
+
if (buttonId && pageLink) {
|
99 |
+
menuItems.push({ id: buttonId, link: pageLink });
|
100 |
+
editor.set(menuItems);
|
101 |
+
document.getElementById('buttonId').value = '';
|
102 |
+
document.getElementById('pageLink').value = '';
|
103 |
+
} else {
|
104 |
+
alert('Пожалуйста, заполните оба поля: id кнопки и ссылку на страницу.');
|
105 |
+
}
|
106 |
+
});
|
107 |
+
|
108 |
+
document.getElementById('saveToClipboard').addEventListener('click', function() {
|
109 |
+
const json = editor.get();
|
110 |
+
const jsonString = JSON.stringify(json, null, 0); // Добавляем в одну строку без отступов
|
111 |
+
navigator.clipboard.writeText(jsonString).then(function() {
|
112 |
+
Toastify({
|
113 |
+
text: "Меню скопировано!",
|
114 |
+
duration: 3000, // Показывать 3 секунды
|
115 |
+
newWindow: true,
|
116 |
+
close: true,
|
117 |
+
gravity: "top", // Показывать сверху
|
118 |
+
position: "center", // Позиционировать по центру
|
119 |
+
backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)",
|
120 |
+
stopOnFocus: true // Останавливать таймер при фокусе на сообщении
|
121 |
+
}).showToast();
|
122 |
+
}, function(err) {
|
123 |
+
console.error('Не удалось скопировать текст: ', err);
|
124 |
+
});
|
125 |
+
});
|
126 |
+
});
|
127 |
+
</script>
|
128 |
+
</body>
|
129 |
+
</html>
|