-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
127 lines (119 loc) · 2.85 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>mc2tja</title>
<style type="text/css">
html, body {
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
}
.container {
padding: 8px;
width: auto;
height: calc(100% - 16px);
}
.bordered {
border: solid black 2px;
}
.details {
position: relative;
width: 100%;
height: calc(100% - 35px);
}
.origin,
.converted {
float: left;
width: calc(50% - 20px);
height: 100%;
padding: 10px;
}
.scroll {
overflow-y: scroll;
height: calc(100% - 50px);
}
.code {
margin: 0px;
border-left: solid #999999 6px;
font-family: Courier New, Courier, monospace;
font-size: 15px;
line-height: 18px;
}
</style>
</head>
<body>
<div class="container">
<form action="" method="post" enctype="multipart/form-data">
<span>Paste online url:</span>
<input type="text" name="urlField" class="text" id="form-url" size="28" value="chart/KappaSays.mc" />
<input type="button" name="load" class="btn" value="Load" onclick="onUrl()" />
<span>or select local file:</span>
<input type="file" name="fileField" class="file" id="form-file" accept=".mc" onchange="onFile()" size="28" />
<input type="button" name="convert" class="btn" id="btn-convert" value="Convert!" onclick="onConvert()" disabled />
</form>
<div class="details">
<div class="info">
</div>
<div class="origin">
<span>Original (MC Chart)</span>
<div class="scroll bordered">
<pre class="origin-text code" id="origin-text"></pre>
</div>
</div>
<div class="converted">
<span>Converted (TJA Chart)</span>
<span><a id="btn-save" hidden>Save this file</a></span>
<div class="scroll bordered">
<pre class="converted-text code" id="converted-text"></pre>
</div>
</div>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/fraction.js"></script>
<script src="js/mcreader.js"></script>
<script src="js/tjawriter.js"></script>
<script src="js/mc2tja.js"></script>
<script>
var mc = null;
function onFile() {
var url = $('#form-file').prop('files')[0];
if (!url) {
$('#origin-text').html('');
} else {
mc = new MCReader();
mc.readLocal(url, function() {
$('#origin-text').html(mc.text);
$('#btn-convert').removeAttr('disabled');
});
}
}
function onUrl() {
var url = $('#form-url').prop('value');
if (!url) {
$('#origin-text').html('');
} else {
mc = new MCReader();
mc.read(url, function() {
$('#origin-text').html(mc.text);
// TODO: mc syntax check
$('#btn-convert').removeAttr('disabled');
});
}
}
function onConvert() {
conv = new mc2tja();
conv.convert(mc, function() {
$('#converted-text').html(conv.generated);
var url = 'data:text/plain;charset=gbk,' + encodeURIComponent(conv.generated);
var filename = mc.filename.replace(/.mc$/i, '.tja');
$('#btn-save').attr('download', filename);
$('#btn-save').attr('href', url);
$('#btn-save').removeAttr('hidden');
});
}
</script>
</div>
</body>
</html>