| 1 | const delta = 18; |
| 2 | |
| 3 | (function () { |
| 4 | var table = document.querySelector("table"); |
| 5 | var isTbody = table.children[0].nodeName == "TBODY"; |
| 6 | var trs = isTbody |
| 7 | ? table.children[0].querySelectorAll("tr") |
| 8 | : table.querySelectorAll("tr"); |
| 9 | trs.forEach(function (tr, idx) { |
| 10 | if (idx != 0 && idx + 1 < trs.length) { |
| 11 | var vc = 3, vv = 4, vf = 5, vh = 6; |
| 12 | var textContent = { |
| 13 | vc: tr.children[vc].textContent, |
| 14 | vv: tr.children[vv].textContent, |
| 15 | vf: tr.children[vf].textContent, |
| 16 | vh: tr.children[vh].textContent |
| 17 | }; |
| 18 | var currentData = { |
| 19 | vc: int(textContent.vc.slice(0, -2)), |
| 20 | vv: int(textContent.vv.slice(0, -2)), |
| 21 | vf: int(textContent.vf.slice(0, -2)), |
| 22 | vh: int(textContent.vh.slice(0, -2)) |
| 23 | }; |
| 24 | var prevData = { |
| 25 | vc: int(trs[idx + 1].children[vc].textContent.slice(0, -2)), |
| 26 | vv: int(trs[idx + 1].children[vv].textContent.slice(0, -2)), |
| 27 | vf: int(trs[idx + 1].children[vf].textContent.slice(0, -2)), |
| 28 | vh: int(trs[idx + 1].children[vh].textContent.slice(0, -2)) |
| 29 | }; |
| 30 | var result = { |
| 31 | vc: currentData.vc - prevData.vc, |
| 32 | vv: currentData.vv - prevData.vv, |
| 33 | vf: currentData.vf - prevData.vf, |
| 34 | vh: currentData.vh - prevData.vh |
| 35 | }; |
| 36 | if (Math.abs(result.vc) > delta) |
| 37 | tr.children[vc].appendChild(createElement(result.vc)); |
| 38 | if (Math.abs(result.vv) > delta * 2) |
| 39 | tr.children[vv].appendChild(createElement(result.vv)); |
| 40 | if (Math.abs(result.vf) > delta * 2) |
| 41 | tr.children[vf].appendChild(createElement(result.vf)); |
| 42 | if (Math.abs(result.vh) > delta * 2) |
| 43 | tr.children[vh].appendChild(createElement(result.vh)); |
| 44 | } |
| 45 | }); |
| 46 | function int(src) { |
| 47 | return src - 0; |
| 48 | } |
| 49 | function getClassName(x) { |
| 50 | if (x == 0) |
| 51 | return "equal"; |
| 52 | return x < 0 ? "plus" : "minus"; |
| 53 | } |
| 54 | function createElement(result) { |
| 55 | var el = document.createElement("span"); |
| 56 | var parsedResult = parseResult(result); |
| 57 | el.classList.add("diff"); |
| 58 | el.classList.add(getClassName(result)); |
| 59 | el.textContent = parsedResult; |
| 60 | return el; |
| 61 | } |
| 62 | function parseResult(x) { |
| 63 | if (x == 0) |
| 64 | return "0"; |
| 65 | return x > 0 ? "+" + x : x; |
| 66 | } |
| 67 | })(); |
| 68 | |