|
33 | 33 | if (jsonMsg.Ports) {
|
34 | 34 | const validKeys = ['Name', 'SerialNumber', 'IsOpen', 'VendorID', 'ProductID'];
|
35 | 35 | if (jsonMsg.Network) {
|
36 |
| - printMsg = "<b>Network Ports</b>:<br>"+JSON.stringify(jsonMsg.Ports, validKeys, 2); |
| 36 | + printMsg = "Network Ports:\n"+JSON.stringify(jsonMsg.Ports, validKeys, 2); |
37 | 37 | } else {
|
38 |
| - printMsg = "<b>Serial Ports</b>:<br>"+JSON.stringify(jsonMsg.Ports, validKeys, 2); |
| 38 | + printMsg = "Serial Ports:\n"+JSON.stringify(jsonMsg.Ports, validKeys, 2); |
39 | 39 | }
|
40 | 40 | } else if (Object.keys(jsonMsg).length !== 0) {
|
41 | 41 | printMsg = JSON.stringify(jsonMsg, undefined, 2);
|
42 | 42 | }
|
| 43 | + |
| 44 | + // when parsing JSON we're escaping some html charaters like "&:<>, we want to show their |
| 45 | + // original value in the log |
| 46 | + function decode(str) { |
| 47 | + let txt = new DOMParser().parseFromString(str, "text/html"); |
| 48 | + return txt.documentElement.textContent; |
| 49 | + } |
| 50 | + printMsg = decode(printMsg); |
| 51 | + |
43 | 52 | messages.push(printMsg);
|
44 | 53 | if (messages.length > MESSAGES_MAX_COUNT) {
|
45 | 54 | messages.shift();
|
46 | 55 | }
|
47 |
| - log.textContent = messages.join('<br><br>'); |
| 56 | + log.textContent = messages.join('\n\n'); |
48 | 57 | if (autoscroll.checked) {
|
49 | 58 | log.scrollTop = log.scrollHeight - log.clientHeight;
|
50 | 59 | }
|
|
65 | 74 | $('#export').click(function() {
|
66 | 75 | var link = document.createElement('a');
|
67 | 76 | link.setAttribute('download', 'agent-log.txt');
|
68 |
| - var text = log.innerHTML.replace(/<br>/g, '\n'); |
69 |
| - text = text.replace(/<b>|<\/b>/g, ''); |
| 77 | + var text = log.textContent; |
70 | 78 | link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
|
71 | 79 | link.click();
|
72 | 80 | });
|
|
83 | 91 | socket = io('http://{{$}}');
|
84 | 92 | }
|
85 | 93 | socket.on('disconnect', function(evt) {
|
86 |
| - appendLog($('<div><b>Connection closed.</b></div>')) |
| 94 | + appendLog('Connection closed.') |
87 | 95 | });
|
88 | 96 | socket.on('message', function(evt) {
|
89 | 97 | appendLog(evt);
|
90 | 98 | });
|
91 | 99 | } else {
|
92 |
| - appendLog($('<div><b>Your browser does not support WebSockets.</b></div>')) |
| 100 | + appendLog('Your browser does not support WebSockets.') |
93 | 101 | }
|
94 | 102 |
|
95 | 103 | $("#input").focus();
|
|
0 commit comments