-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforward.html
131 lines (123 loc) · 4.78 KB
/
forward.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>转换工具</title>
<link rel="stylesheet" href="./src/bootstrap/css/bootstrap.min.css">
<style>
textarea { min-height: 400px; }
pre { padding: 6px 12px; min-height:400px; }
.string { color: #92278f; }
.number { color: #25aae2; }
.boolean { color: #f0ad4e; }
.null { color: #d9534f; }
.key { color: #4cae4c; }
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="exampleInputEmail1">JSON缩进</label>
<div class="form-group">
<select name="padding" class="form-control">
<option value="2">2个缩进</option>
<option value="4">4个缩进</option>
<option value="6">6个缩进</option>
<option value="8">8个缩进</option>
</select>
</div>
</div>
</div>
<div class="col-md-6">
</div>
<div class="col-md-12">
</div>
<div class="col-md-6">
<form method="POST" onsubmit="return false;">
<div class="form-group">
<label for="exampleInputEmail1">Array | JSON | Urldecode</label>
<textarea name="data" class="form-control" id="input"></textarea>
</div>
<button type="submit" class="btn btn-success" onclick="parseData('formatJson')">JSON</button>
<button type="submit" class="btn btn-info" onclick="parseData('urldecode')">Urldecode</button>
<button type="submit" class="btn btn-success" onclick="parseData('toArray')">toArray</button>
<button type="submit" class="btn btn-info" onclick="parseData('base64Encode')">base64Encode</button>
<button type="submit" class="btn btn-success" onclick="parseData('base64Decode')">base64Decode</button>
<button type="submit" class="btn btn-info" onclick="parseData('strtotime')">strtotime</button>
<button type="submit" class="btn btn-success" onclick="parseData('date')">date</button>
</form>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="exampleInputEmail1">JSON | Array</label>
<div class="form-group">
<pre id="show_box" contenteditable="true">
</pre>
</div>
</div>
</div>
</div>
</div>
</body>
<script src="./src/axios.min.js"></script>
<script src="./src/config.js"></script>
<script>
var AppApi = window.AppApi;
function parseData ( type ) {
var input = document.getElementById('input').value;
const api_domain = localStorage.getItem('api_domain');
var config = {
method: 'post',
url: api_domain + AppApi.forward,
data: {
data: input,
type: type
},
withCredentials: true,
crossDomain: true,
// headers: window.AppHeader, // 跨域需要关掉自定义header
}
curl(config, function ( dd ){
var content = dd.data;
console.log(content);
console.log(typeof(content));
if (typeof(content) === 'object') {
content = syntaxHighlight(content);
}
document.getElementById('show_box').innerHTML = content;
});
}
// 发送 CURL 请求
function curl ( config , callback ) {
axios(config).then(callback).catch(function (error) {
console.log(error);
});
}
// json 语法高亮
function syntaxHighlight( json ) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 4);
}
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function(match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '<span class="' + cls + '">' + match + '</span>';
});
}
</script>
</html>