-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode_to_json.html
More file actions
66 lines (66 loc) · 2.2 KB
/
code_to_json.html
File metadata and controls
66 lines (66 loc) · 2.2 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
<div class="supertool">
<style>
.supertool textarea{
white-space: pre;
overflow: auto;
border: solid #ddd 2px;
width: 100%;
}
.supertool a, .supertool button {
background-color: #d0d0d0;
border: none;
color: #5b5b57 !important;
padding: 10px 8px;
text-align: center;
text-decoration: none;
display: inline-block;
cursor: pointer;
margin-top: 2px;
margin-bottom: 2px;
font-size: 14px;
}
.supertool a:hover, .supertool button:hover{
background-color: #757575;
color: #fff !important;
}
</style>
<div class="col-md-12">
<textarea autocomplete="off" id="code" cols="80" rows="10" name="code" placeholder="Enter your code..." spellcheck="false"></textarea><br>
<button type="button" id="convert" name="convert" value="convert">Convert</button>
<button type="button" name="reload" onclick="location.reload()" value="reload">Reload</button>
</div>
<div class="col-md-12">
<textarea autocomplete="off" id="result" cols="80" rows="10" name="code" placeholder="Result..." readonly></textarea><br>
<button type="button" id="copy" name="copy" value="Copy">Copy</button>
<a type="button" id="download" name="download" >Download</a>
<span id="status" ></span>
</div>
<script>
const converter = document.querySelector('#convert');
converter.addEventListener("click", function () {
var code = document.querySelector('#code'), result = document.querySelector('#result'), data = {};
data.code = code.value;
result.value = JSON.stringify(data);
});
const copy = document.querySelector('#copy');
copy.addEventListener("click", function() {
elm=document.querySelector("#result");
elm.select();
elm.setSelectionRange(0,99999);
document.execCommand('copy');
});
const download = document.querySelector('#download');
download.addEventListener("click", function () {
var code = document.querySelector('#code'), data, file;
data = { code: code.value };
this.download='code.json'; //download
file = JSON.stringify(data);
var blobData = new Blob([file], {type: 'application/json'});
var url = window.URL.createObjectURL(blobData);
this.href = url;
});
const superTools = {
title: "Code to JSON converter"
};
</script>
</div>