-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
244 lines (214 loc) · 7.06 KB
/
index.html
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<!doctype html>
<html lang="en">
<head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-JCW9ZHMLY0"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-JCW9ZHMLY0');
</script>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script type="text/javascript" src="./lib/jquery-3.6.1.min.js"></script>
<script type="text/javascript" src="./lib/js-yaml.min.js"></script>
<link rel="stylesheet" href="./css/reset.css">
<title>k8s config merger</title>
<style>
/*
* Custom styles
*/
body {
margin: 0 auto;
text-align: center;
}
h1 {
margin-top: 20px;
font-style: italic;
font-size: 60px;
font-weight: bolder;
}
.main-wrap {
border: 1px solid black;
width: 1180px;
height: 1000px;
margin: 0 auto;
}
.tool-wrap {
width: 1180px;
text-align: right;
margin: 0 auto;
margin-bottom: 5px;
}
.dropzone-wrap {
width: 49%;
/*border-right: 1px solid black;*/
display: inline-block;
height: 100%;
float: left;
}
.result-wrap {
float: right;
display: inline-block;
width: 51%;
height: 100%;
}
#result {
width: 100%;
height: 100%;
resize: none;
}
.dropzone-description {
margin-top: 420px;
font-size: 30px;
}
ol {
text-align: left;
display: inline-block;
margin-bottom: 30px;
font-size: 17px;
}
</style>
</head>
<body>
<h1>K8S CONFIG MERGER</h1>
<div class="description-wrap">
<div class="description">
<ol>
<li>1. This script works only your browser, so It saves nothing. Don't worry about leak of config.</li>
<li>2. You can read every revealed code at <a href="https://github.com/jujumilk3/k8s-config-merger" target="_blank">@Github Repository</a>.</li>
</ol>
</div>
</div>
<div class="tool-wrap">
<button id="button-check">Check</button>
<button id="button-reset">Reset</button>
<button id="button-copy">Copy</button>
<button id="button-download">Download</button>
</div>
<div class="main-wrap">
<div class="dropzone-wrap"
id="drop_zone"
ondrop="dropHandler(event);"
ondragover="dragOverHandler(event);">
<div class="dropzone-description">
<p>Drag and Drop<br>one or more files to here.</p>
</div>
</div>
<div class="result-wrap">
<textarea readonly name="" id="result"></textarea>
</div>
</div>
</body>
<script>
let asJson = {};
let asYaml = '';
$(document).ready(function () {
console.log("ready");
});
$('#button-check').click(function () {
console.log(asJson);
console.log(asYaml);
});
$('#button-copy').click(function () {
copyTextToClipboard(asYaml);
});
$('#button-reset').click(function () {
$('#result').text('');
asJson = {};
asYaml = '';
});
$('#button-download').click(function () {
download('config', asYaml);
});
function download(filename, text) {
let element = document.createElement('a');
element.setAttribute('href', 'data:application/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function copyTextToClipboard(text) {
if (!navigator.clipboard) {
fallbackCopyTextToClipboard(text);
return;
}
navigator.clipboard.writeText(text).then(function() {
console.log('Async: Copying to clipboard was successful!');
}, function(err) {
console.error('Async: Could not copy text: ', err);
});
}
function getJsonLength(json) {
return Object.keys(json).length;
}
function addEachElementsAtAsJson(json) {
const keys = Object.keys(json);
keys.forEach((key) => {
if (asJson[key]) {
if (Array.isArray(asJson[key])) {
let currentKeyNames = []
asJson[key].forEach((element) => {
currentKeyNames.push(element["name"]);
});
let collected_names = [];
json[key].forEach((element) => {
collected_names.push(element["name"]);
if (currentKeyNames.includes(element["name"])) {
} else {
asJson[key].push(element);
}
});
} else {
asJson[key] = json[key];
}
} else {
asJson[key] = json[key];
}
});
}
function dragOverHandler(ev) {
ev.preventDefault();
}
function dropHandler(ev) {
// console.log('File(s) dropped');
// Prevent default behavior (Prevent file from being opened)
ev.preventDefault();
if (ev.dataTransfer.items) {
// Use DataTransferItemList interface to access the file(s)
[...ev.dataTransfer.items].forEach((item, i) => {
// If dropped items aren't files, reject them
if (item.kind === 'file') {
const file = item.getAsFile();
console.log(`… file[${i}].name = ${file.name}`);
file.text().then((text) => {
let asJsonLength = getJsonLength(asJson);
let jsonedYaml = jsyaml.load(text);
if (asJsonLength === 0) {
asJson = jsonedYaml;
} else {
addEachElementsAtAsJson(jsonedYaml);
}
asYaml = jsyaml.dump(asJson);
// console.log(asJson);
// console.log(asYaml);
$("#result").text(asYaml);
// console.log(asYaml)
// console.log(jsyaml.load(asYaml))
});
}
});
} else {
// Use DataTransfer interface to access the file(s)
[...ev.dataTransfer.files].forEach((file, i) => {
console.log(`… file[${i}].name = ${file.name}`);
});
}
}
</script>
</html>