-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathttt.html
More file actions
100 lines (100 loc) · 5.09 KB
/
ttt.html
File metadata and controls
100 lines (100 loc) · 5.09 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
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
<!DOCTYPE html>
<html>
<head>
<title>GMod TTT Damage Log Reader</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap-combined.min.css" rel="stylesheet">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
</head>
<body>
<div class="container">
<br>
<textarea rows="3" class="input-xxlarge" id="text"></textarea>
<hr>
<h3>Data</h3>
<p id="error"></p>
<table class="table table-striped table-hover" id="table">
</table>
</div>
<script type="text/javascript">
$("#text").bind('input propertychange', function() {
var lines = $('#text').val().split('\n');
var table = "<tr><th>Perpetrator</th><th>Info</th><th>Subject</th></tr>";
$.each(lines, function(i, item) {
if (i == 0 && item != " *** Damage log:") {
$("#error").html("Supply a valid damage log!");
$("#table").html("");
return;
} else {
if (item == " *** Damage log end.") {
$("#error").html("");
return;
}
var line = item.replace(/ [0-9][0-9]:[0-9][0-9]\.[0-9][0-9] - /g, '');
if (startsWith("DMG:", line)) {
var dmgRX = /DMG: (.*) damaged (.*) for (.*) dmg/g;
var dmg = dmgRX.exec(line);
var u1 = dmg[1];
var u1_split = getUser(u1);
var u1_type = getColoredType(u1_split);
var u2 = dmg[2];
var u2_split = getUser(u2);
var u2_type = getColoredType(u2_split);
var dealt = dmg[3];
if (!isTraitor(u1_split) && !isTraitor(u2_split)) {
u1_type = "<span class='badge badge-important'>!!</span> " + u1_type;
u2_type = u2_type + " <span class='badge badge-important'>!!</span>";
}
table += '<tr class="warning"><td>' + u1_type + '</td><td>' + '<span class="label label-important">' + dealt + '</span></td><td>' + u2_type + '</td>';
}
if (startsWith("KILL:", line)) {
var killRX = /KILL: (.*) killed (.*)/g;
var kill = killRX.exec(line);
var u1 = kill[1];
var u1_split = getUser(u1);
var u1_type = getColoredType(u1_split);
var u2 = kill[2];
var u2_split = getUser(u2);
var u2_type = getColoredType(u2_split);
if (!isTraitor(u1_split) && !isTraitor(u2_split)) {
u1_type = "<span class='badge badge-important'>!!</span> " + u1_type;
u2_type = u2_type + " <span class='badge badge-important'>!!</span>";
}
table += '<tr class="error"><td>' + u1_type + '</td><td></td><td>' + u2_type + '</td>';
}
if (startsWith("SAMPLE:", line)) {
var samRX = /SAMPLE: (.*) retrieved DNA of (.*) from corpse of (.*)/g;
var sam = samRX.exec(line);
var u1 = sam[1];
var u2 = sam[2];
var u3 = sam[3];
table += '<tr class="info"><td><span class="label label-info">' + u1 + '</span></td><td><span class="label">' + u2 + '</span></td><td><span class="label">' + u3 + '</span></td></tr>';
}
}
});
$("#table").html(table);
});
function isTraitor(a) {
return a[2] == "traitor";
}
function startsWith(a, b) {
return b.indexOf(a) == 0;
}
function getUser(a) {
var typeRX = /(.*) \[(.*)\]/g;
return typeRX.exec(a);
}
function getColoredType(a) {
var name = a[1];
var type = a[2];
if (type == "innocent")
return "<span class='label label-success'>" + name + "</span>";
if (type == "detective")
return "<span class='label label-info'>" + name + "</span>";
if (type == "traitor")
return "<span class='label label-important'>" + name + "</span>";
return a;
}
</script>
</body>
</html>