-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtrans.html
82 lines (80 loc) · 3.47 KB
/
trans.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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<script>
function trans(){
var source = document.getElementById("src"),
destination = document.getElementById("dst"),
text = source.value,
// 数字
text = text.replace(/t\>/g,"</span>");
text = text.replace(/\<t/g,"<span class='text'>");
text = text.replace(/\%n/g,"<span class='number'>");
text = text.replace(/n\%/g,"</span>");
text = text.replace(/\[/g,"<span class='functionWord'>");
text = text.replace(/\]/g,"</span>");
text = text.replace(/\$v/g,"<span class='var'>");
text = text.replace(/v\$/g,"</span>");
text = text.replace(/\@l/g,"<span class='label'>");
text = text.replace(/l\@/g,"</span>");
text = text.replace(/\{c/g,"<span class='textctrl'>");
text = text.replace(/c\}/g,"</span>");
text = text.replace(/\#c/g,"<span class='color'>");
text = text.replace(/c\#/g,"</span>");
text = text.replace(/\*r/g,"<span class='reverseWord'>");
text = text.replace(/r\*/g,"</span>");
destination.value = text;
}
function add(type){
var source = document.getElementById("src"),
text = source.value,
start = source.selectionStart,
end = source.selectionEnd;
source.focus();
var before = text.substring(0,start),
selection = text.substring(start, end),
after = text.substring(end, text.length);
if (selection != ""){
if(type == "number"){
text = before + "%n" + selection + "n%" + after;
} else if (type == "functionname"){
text = before + "[" + selection + "]" + after;
} else if (type == "var") {
text = before + "$v" + selection + "v$" + after;
} else if (type == "string") {
text = before + "<t" + selection + "t>" + after;
} else if (type == "label") {
text = before + "@l" + selection + "l@" + after;
} else if (type == "controlstring") {
text = before + "{c" + selection + "c}" + after;
} else if (type == "color") {
text = before + "#c" + selection + "c#" + after;
} else if (type == "reverseword") {
text = before + "*r" + selection + "r*" + after;
}
}
source.value = text;
//alert(source.value.substring(before,after));
//alert(selection);
}
</script>
<body>
<table><tr><td>
<textarea style="height:300px;width:800px" id="src"></textarea><br />
<textarea style="height:300px;width:800px" id="dst"></textarea>
</td><td>
<div style="height:200px; width:200px">
<input style="height:25px;width:200px" value="%n...n% 数字" type="button" onclick="javascript:add('number')"/><br />
<input style="height:25px;width:200px" value="[...] 函数保留字" type="button" onclick="javascript:add('functionname')"/><br />
<input style="height:25px;width:200px" value="<t...t> 字符串" type="button" onclick="javascript:add('string')"/><br />
<input style="height:25px;width:200px" value="$v...v$ 变量" type="button" onclick="javascript:add('var')"/><br />
<input style="height:25px;width:200px" value="@l...l@ 标签" type="button" onclick="javascript:add('label')"/><br />
<input style="height:25px;width:200px" value="{c...c} 控制字符串" type="button" onclick="javascript:add('controlstring')"/><br />
<input style="height:25px;width:200px" value="#c...c# 颜色" type="button" onclick="javascript:add('color')"/><br />
<input style="height:25px;width:200px" value="*r...r* 保留字" type="button" onclick="javascript:add('reverseword')"/><br />
</div>
<input style="height:400px;width:200px"type="button" name="" value="转换" onclick="javascript:trans()"/></td></tr>
<tr><td>某功能简陋的格式转换器 by yyd</td></tr></table>
<body>
</html>