diff options
author | Thomas Voss <57815710+Mango0x45@users.noreply.github.com> | 2021-05-16 20:56:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-16 20:56:34 +0200 |
commit | 8f0de5e1c983753ebf443fb2e5c7c1cad0a5f708 (patch) | |
tree | b7ef94b421fe71e4931912fbb8bc85908d6fe73a /main.js | |
parent | 4c3ce1073bd01688613db0b92139c044b2e97ced (diff) | |
parent | 48cedc78c549561912b69076e316962c2c64bfa1 (diff) |
Merge pull request #1 from NoobJsPerson/master
replaceAll chain's gone for good
Diffstat (limited to 'main.js')
-rw-r--r-- | main.js | 54 |
1 files changed, 28 insertions, 26 deletions
@@ -1,3 +1,10 @@ +/* Define the interpolate function */ +function interpolate(template, variables) { + return template.replace(/\${[^{]+}/g, (match) => { + const path = match.slice(2, -1).trim(); + return variables[path]; + }); +} /* Compute the total duration of the run. */ function compute() { @@ -51,30 +58,25 @@ function generate_mod_message( const one_prec_millis = milliseconds.toFixed(1).replace("0.", ""); const two_prec_millis = milliseconds.toFixed(2).replace("0.", ""); const three_prec_millis = milliseconds.toFixed(3).replace("0.", ""); - - mod_message = mod_message.replaceAll("${FPS}", fps) - .replaceAll("${H}", hours) - .replaceAll("${M}", minutes) - .replaceAll("${S}", seconds) - .replaceAll("${MS}", milliseconds) - - .replaceAll("${PM}", padded_minutes) - .replaceAll("${PS}", padded_seconds) - - .replaceAll("${1MS}", one_prec_millis) - .replaceAll("${2MS}", two_prec_millis) - .replaceAll("${3MS}", three_prec_millis) - - .replaceAll("${TS}", total_seconds) - - .replaceAll("${ST}", start_time) - .replaceAll("${ET}", end_time) - .replaceAll("${TT}", total_time) - - .replaceAll("${SF}", start_frame) - .replaceAll("${EF}", end_frame) - .replaceAll("${TF}", total_frames) - + const params = { + H: hours, + M: minutes, + S: seconds, + MS: milliseconds, + PM: padded_minutes, + PS: padded_seconds, + "1MS": one_prec_millis, + "2MS": two_prec_millis, + "3MS": three_prec_millis, + ST: start_time, + ET: end_time, + TT: total_time, + SF: start_frame, + EF: end_frame, + TF: total_frames, + FPS: fps + }; + mod_message = interpolate(mod_message, params); return mod_message; } @@ -133,7 +135,7 @@ function parse_time(event) } /* If cmt isn't available fallback to lct, also allow raw numbers */ - if (!(input = dinfo.cmt) && !(input = dinfo.lct) && typeof ((input = dinfo)) !== "number") { + if (!(input = dinfo.cmt) && !(input = dinfo.lct) && typeof((input = dinfo)) !== "number") { document.getElementById(event.target.id).value = ""; return; } @@ -146,4 +148,4 @@ function parse_time(event) /* If all fields are filled the compute */ if (document.getElementById("startobj").value && document.getElementById("endobj").value) compute(); -} +}
\ No newline at end of file |