-
Notifications
You must be signed in to change notification settings - Fork 0
/
url-encode-decode.html
102 lines (93 loc) · 3.51 KB
/
url-encode-decode.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bower/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="bower/font-awesome/css/font-awesome.min.css" />
<title>URL Encode / Decode</title>
</head>
<body>
<div class="container">
<h2>
<i class="fa fa-globe" aria-hidden="true"></i> URL Encode / Decode
<a href="index.html" class="btn btn-default">
<i class="fa fa-fa-reply" aria-hidden="true"></i> Back to Menu
</a>
</h2>
<div class="row">
<div class="col-xs-12" style="margin-bottom:10px;">
<label>
<input type="radio" name="convType" id="encodeURI" value="encodeURI" checked> encodeURI
</label>
<label>
<input type="radio" name="convType" id="encodeURIComponent" value="encodeURIComponent"> encodeURIComponent
</label>
<label>
<input type="radio" name="convType" id="decodeURI" value="decodeURI"> decodeURI
</label>
<label>
<input type="radio" name="convType" id="decodeURIComponent" value="decodeURIComponent"> decodeURIComponent
</label>
<button id="reset" class="btn btn-warning">
<i class="fa fa-eraser" aria-hidden="true"></i> Reset
</button>
</div>
</div>
<div class="row">
<div class="col-xs-6">
<textarea class="form-control" rows="13" id="text" placeholder="Input Text"></textarea>
</div>
<div class="col-xs-6">
<textarea class="form-control" rows="13" id="result" readonly placeholder="Convert Result"></textarea>
</div>
</div>
</div>
<script src="bower/jquery/dist/jquery.min.js"></script>
<script src="bower/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="bower/json5/lib/json5.js"></script>
<script>
var convert = function () {
var text = $('#text').val();
if (!text) {
$('#result').val('');
return;
}
try {
var type = $('input[name=convType]:checked').val();
console.log(type);
var result = '';
if (type === 'encodeURI') {
result = encodeURI(text);
} else if (type === 'encodeURIComponent') {
result = encodeURIComponent(text);
} else if (type === 'decodeURI') {
result = decodeURI(text);
} else if (type === 'decodeURIComponent') {
result = decodeURIComponent(text);
} else {
result = '';
}
$('#result').val(result);
} catch (e) {
$('#result').val(e);
}
};
$(document).ready(function () {
$('#text').keyup(function (e) {
convert();
});
$('#text').change(function () {
convert();
});
$('input[name=convType]').change(function () {
convert();
});
$('#reset').click(function() {
$('#text').val('');
convert();
});
});
</script>
</body>
</html>