-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhtml.js
59 lines (46 loc) · 1.05 KB
/
html.js
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
var fs = require("fs");
var json = JSON.parse(fs.readFileSync('export.json'));
var json = Object.values(json)[0];
var byConversation = {};
json.forEach(function(a)
{
a._serverMessages.forEach(function(b)
{
var id = b.conversationid || a.conversationId;
if(!byConversation[id])
{
byConversation[id] = [];
}
byConversation[id].push(b);
});
});
var getName = function(a)
{
return a.replace(/^(.+\/)?[0-9]+:(.+)$/, '$2')
};
var format = function(a)
{
return a.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/\n/g, '<br />');
};
for(var i in byConversation)
{
byConversation[i] = byConversation[i].sort(function(a, b)
{
return a.originalarrivaltime > b.originalarrivaltime ? 1 : -1;
});
var html = '<html><body>';
byConversation[i].forEach(function(a)
{
html += '<dl><dt>'
+a.originalarrivaltime.replace('T', ' ').substr(0, 19)
+' / '
+'<strong>'+format(getName(a.from))+'</strong>'
+'</dt><dd>'
+format(a.content)
+'</dd></dl>';
});
html += '</body></html>';
fs.writeFileSync(getName(i)+'.html', html);
}