From 9a5b4f8f56593b56564865af854558818eab3a87 Mon Sep 17 00:00:00 2001 From: Amine El Baghdadi <75886237+NoobJsPerson@users.noreply.github.com> Date: Sat, 15 May 2021 17:53:08 +0000 Subject: add interpolate.js --- interpolate.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 interpolate.js diff --git a/interpolate.js b/interpolate.js new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From 381a3ab65b507ca18c2ad4c75fb7ad5897bd4dd5 Mon Sep 17 00:00:00 2001 From: Amine El Baghdadi <75886237+NoobJsPerson@users.noreply.github.com> Date: Sat, 15 May 2021 17:56:31 +0000 Subject: update interpolate.js --- interpolate.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/interpolate.js b/interpolate.js index e69de29..36cf2f8 100644 --- a/interpolate.js +++ b/interpolate.js @@ -0,0 +1,13 @@ +const regex = /\${[^{]+}/g; + +export default function interpolate(template, variables, fallback) { + return template.replace(regex, (match) => { + const path = match.slice(2, -1).trim(); + return getObjPath(path, variables, fallback); + }); +} + +//get the specified property or nested property of an object +function getObjPath(path, obj, fallback = '') { + return path.split('.').reduce((res, key) => res[key] || fallback, obj); +} \ No newline at end of file -- cgit v1.2.3 From 99f7ceddcd2ce99a8e2439b3a04e5a3ba236c64a Mon Sep 17 00:00:00 2001 From: Amine El Baghdadi <75886237+NoobJsPerson@users.noreply.github.com> Date: Sat, 15 May 2021 17:58:10 +0000 Subject: update interpolate.js --- interpolate.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interpolate.js b/interpolate.js index 36cf2f8..443450e 100644 --- a/interpolate.js +++ b/interpolate.js @@ -3,11 +3,11 @@ const regex = /\${[^{]+}/g; export default function interpolate(template, variables, fallback) { return template.replace(regex, (match) => { const path = match.slice(2, -1).trim(); - return getObjPath(path, variables, fallback); + return getObjPath(path, variables); }); } //get the specified property or nested property of an object -function getObjPath(path, obj, fallback = '') { - return path.split('.').reduce((res, key) => res[key] || fallback, obj); +function getObjPath(path, obj) { + return path.split('.').reduce((res, key) => res[key], obj); } \ No newline at end of file -- cgit v1.2.3 From ef7b821d2a5143db9c0660cffc1189cf6e63dc29 Mon Sep 17 00:00:00 2001 From: Amine El Baghdadi <75886237+NoobJsPerson@users.noreply.github.com> Date: Sat, 15 May 2021 18:12:56 +0000 Subject: update main.js --- main.js | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/main.js b/main.js index 2861b0b..789c316 100644 --- a/main.js +++ b/main.js @@ -1,3 +1,5 @@ +/* Import the interpolate function*/ +import interpolate from "interpolate.js"; /* Compute the total duration of the run. */ function compute() { @@ -51,30 +53,24 @@ 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 + }; + mod_message = interpolate (mod_message,params); return mod_message; } -- cgit v1.2.3 From 8c1853eb39ea4d251e00392f802df32233b83325 Mon Sep 17 00:00:00 2001 From: Amine El Baghdadi <75886237+NoobJsPerson@users.noreply.github.com> Date: Sat, 15 May 2021 18:13:47 +0000 Subject: update interpolate.js --- interpolate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interpolate.js b/interpolate.js index 443450e..70ac4eb 100644 --- a/interpolate.js +++ b/interpolate.js @@ -1,6 +1,6 @@ const regex = /\${[^{]+}/g; -export default function interpolate(template, variables, fallback) { +export default function interpolate(template, variables) { return template.replace(regex, (match) => { const path = match.slice(2, -1).trim(); return getObjPath(path, variables); -- cgit v1.2.3 From 3ff1e092aa759182c1e5f9335f0a8889ce373c68 Mon Sep 17 00:00:00 2001 From: Amine El Baghdadi <75886237+NoobJsPerson@users.noreply.github.com> Date: Sat, 15 May 2021 18:14:56 +0000 Subject: update interpolate.js --- interpolate.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/interpolate.js b/interpolate.js index 70ac4eb..0c20589 100644 --- a/interpolate.js +++ b/interpolate.js @@ -1,7 +1,5 @@ -const regex = /\${[^{]+}/g; - export default function interpolate(template, variables) { - return template.replace(regex, (match) => { + return template.replace(/\${[^{]+}/g, (match) => { const path = match.slice(2, -1).trim(); return getObjPath(path, variables); }); -- cgit v1.2.3 From 12b56ae0c3980eb786fc8a9f2ca44a9a72392dac Mon Sep 17 00:00:00 2001 From: Amine El Baghdadi <75886237+NoobJsPerson@users.noreply.github.com> Date: Sat, 15 May 2021 18:29:33 +0000 Subject: delete interpolate.js --- interpolate.js | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 interpolate.js diff --git a/interpolate.js b/interpolate.js deleted file mode 100644 index 0c20589..0000000 --- a/interpolate.js +++ /dev/null @@ -1,11 +0,0 @@ -export default function interpolate(template, variables) { - return template.replace(/\${[^{]+}/g, (match) => { - const path = match.slice(2, -1).trim(); - return getObjPath(path, variables); - }); -} - -//get the specified property or nested property of an object -function getObjPath(path, obj) { - return path.split('.').reduce((res, key) => res[key], obj); -} \ No newline at end of file -- cgit v1.2.3 From b817a19326b67668ee1026d7cc52781666ec44b7 Mon Sep 17 00:00:00 2001 From: Amine El Baghdadi <75886237+NoobJsPerson@users.noreply.github.com> Date: Sat, 15 May 2021 18:30:55 +0000 Subject: update main.js --- main.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 789c316..e4883d9 100644 --- a/main.js +++ b/main.js @@ -1,5 +1,15 @@ -/* Import the interpolate function*/ -import interpolate from "interpolate.js"; +/* Define the interpolate function */ +function interpolate(template, variables) { + return template.replace(/\${[^{]+}/g, (match) => { + const path = match.slice(2, -1).trim(); + return getObjPath(path, variables); + }); +} + +/* Get the specified property or nested property of an object */ +function getObjPath(path, obj) { + return path.split('.').reduce((res, key) => res[key], obj); +} /* Compute the total duration of the run. */ function compute() { -- cgit v1.2.3 From 45086c9f0ae666accd88b15ed9dd45a5ac7b7e48 Mon Sep 17 00:00:00 2001 From: Amine El Baghdadi <75886237+NoobJsPerson@users.noreply.github.com> Date: Sat, 15 May 2021 18:37:01 +0000 Subject: update main.js --- main.js | 235 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 118 insertions(+), 117 deletions(-) diff --git a/main.js b/main.js index e4883d9..7c7c783 100644 --- a/main.js +++ b/main.js @@ -1,155 +1,156 @@ /* Define the interpolate function */ function interpolate(template, variables) { - return template.replace(/\${[^{]+}/g, (match) => { - const path = match.slice(2, -1).trim(); - return getObjPath(path, variables); - }); + return template.replace(/\${[^{]+}/g, (match) => { + const path = match.slice(2, -1).trim(); + return getObjPath(path, variables); + }); } /* Get the specified property or nested property of an object */ function getObjPath(path, obj) { - return path.split('.').reduce((res, key) => res[key], obj); + return path.split('.').reduce((res, key) => res[key], obj); } /* Compute the total duration of the run. */ function compute() { - const fps = parseInt(document.getElementById("framerate").value); - const s_time = document.getElementById("startobj").value; - const e_time = document.getElementById("endobj").value; - - /* Return early if not all fields are filled */ - if (s_time === undefined || e_time === undefined || fps === undefined) - return; - - /* Return early on a negative time */ - const frames = (e_time - s_time) * fps; - if (frames < 0) { - document.getElementById("time").value = "Error: Negative time"; - return; - } - - const seconds = Math.round(frames / fps * 1000) / 1000; - - /* Show the time and mod message in the DOM. */ - const s_frame = ~~(s_time * fps); - const e_frame = ~~(e_time * fps); - const time = time_format(seconds); - - document.getElementById("time").value = time; - document.getElementById("mod_message").disabled = false; - document.getElementById("mod_message").innerText = generate_mod_message( - fps, s_time, e_time, time, s_frame, e_frame, frames, seconds); - document.getElementById("mod_message_button").disabled = false; + const fps = parseInt(document.getElementById("framerate").value); + const s_time = document.getElementById("startobj").value; + const e_time = document.getElementById("endobj").value; + + /* Return early if not all fields are filled */ + if (s_time === undefined || e_time === undefined || fps === undefined) + return; + + /* Return early on a negative time */ + const frames = (e_time - s_time) * fps; + if (frames < 0) { + document.getElementById("time").value = "Error: Negative time"; + return; + } + + const seconds = Math.round(frames / fps * 1000) / 1000; + + /* Show the time and mod message in the DOM. */ + const s_frame = ~~(s_time * fps); + const e_frame = ~~(e_time * fps); + const time = time_format(seconds); + + document.getElementById("time").value = time; + document.getElementById("mod_message").disabled = false; + document.getElementById("mod_message").innerText = generate_mod_message( + fps, s_time, e_time, time, s_frame, e_frame, frames, seconds); + document.getElementById("mod_message_button").disabled = false; } /* Support custom mod messages. Find a better way to do this, it is very cringe! */ function generate_mod_message( - fps, start_time, end_time, total_time, start_frame, end_frame, total_frames, total_seconds) + fps, start_time, end_time, total_time, start_frame, end_frame, total_frames, total_seconds) { - let mod_message = localStorage.getItem("custom_mod_message"); - - const hours = ~~(total_seconds / 3600) - const minutes = ~~((total_seconds % 3600) / 60); - const seconds = ~~(total_seconds % 60); - const milliseconds = total_seconds % 60 % 1; - - const padded_minutes = (minutes < 10) ? "0" + minutes : minutes; - const padded_seconds = (seconds < 10) ? "0" + seconds : seconds; - - /* - * TODO: THIS IS REALLY STUPID CODE!! - * In a language as bloated as JS surely there is a better way?? - */ - 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.", ""); - 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 - }; - mod_message = interpolate (mod_message,params); - return mod_message; + let mod_message = localStorage.getItem("custom_mod_message"); + + const hours = ~~(total_seconds / 3600) + const minutes = ~~((total_seconds % 3600) / 60); + const seconds = ~~(total_seconds % 60); + const milliseconds = total_seconds % 60 % 1; + + const padded_minutes = (minutes < 10) ? "0" + minutes : minutes; + const padded_seconds = (seconds < 10) ? "0" + seconds : seconds; + + /* + * TODO: THIS IS REALLY STUPID CODE!! + * In a language as bloated as JS surely there is a better way?? + */ + 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.", ""); + 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; } /* Convert seconds to human readable time. */ function time_format(t) { - const h = ~~(t / 3600); - const m = ~~((t % 3600) / 60); - const s = t % 60; - let ret = ""; + const h = ~~(t / 3600); + const m = ~~((t % 3600) / 60); + const s = t % 60; + let ret = ""; - if (h > 0) - ret += h + ":" + (m < 10 ? "0" : ""); + if (h > 0) + ret += h + ":" + (m < 10 ? "0" : ""); - ret += m + ":" + (s < 10 ? "0" : "") + s.toFixed(3); + ret += m + ":" + (s < 10 ? "0" : "") + s.toFixed(3); - return ret; + return ret; } /* Allow user to copy mod message to clipboard. */ function copy_mod_message() { - const mod_message = document.getElementById("mod_message"); - mod_message.focus(); - mod_message.select(); - document.execCommand("copy"); + const mod_message = document.getElementById("mod_message"); + mod_message.focus(); + mod_message.select(); + document.execCommand("copy"); } /* If framerate is invalid, show an error message and disable start and end frame fields. */ function check_fps(event) { - fps = event.target.value; - if (fps > 0 && fps % 1 == 0) { - document.getElementById("startobj").disabled = false; - document.getElementById("endobj").disabled = false; - } - else { - document.getElementById("framerate") - .setCustomValidity("Please enter a valid framerate."); - document.getElementById("framerate").reportValidity(); - document.getElementById("startobj").disabled = true; - document.getElementById("endobj").disabled = true; - } + fps = event.target.value; + if (fps > 0 && fps % 1 == 0) { + document.getElementById("startobj").disabled = false; + document.getElementById("endobj").disabled = false; + } + else { + document.getElementById("framerate") + .setCustomValidity("Please enter a valid framerate."); + document.getElementById("framerate").reportValidity(); + document.getElementById("startobj").disabled = true; + document.getElementById("endobj").disabled = true; + } } /* Get current frame from input field (either start time or end time). */ function parse_time(event) { - /* Return early if invalid JSON is passed (numbers are valid) */ - let input, dinfo; - try { - dinfo = JSON.parse(event.target.value); - } catch { - document.getElementById(event.target.id).value = ""; - return; - } - - /* If cmt isn't available fallback to lct, also allow raw numbers */ - if (!(input = dinfo.cmt) && !(input = dinfo.lct) && typeof ((input = dinfo)) !== "number") { - document.getElementById(event.target.id).value = ""; - return; - } - - /* Calculate the exact timestamp */ - const fps = parseInt(document.getElementById("framerate").value); - const frame = ~~(input * fps) / fps; - document.getElementById(event.target.id).value = `${frame}`; - - /* If all fields are filled the compute */ - if (document.getElementById("startobj").value && document.getElementById("endobj").value) - compute(); -} + /* Return early if invalid JSON is passed (numbers are valid) */ + let input, dinfo; + try { + dinfo = JSON.parse(event.target.value); + } catch { + document.getElementById(event.target.id).value = ""; + return; + } + + /* If cmt isn't available fallback to lct, also allow raw numbers */ + if (!(input = dinfo.cmt) && !(input = dinfo.lct) && typeof((input = dinfo)) !== "number") { + document.getElementById(event.target.id).value = ""; + return; + } + + /* Calculate the exact timestamp */ + const fps = parseInt(document.getElementById("framerate").value); + const frame = ~~(input * fps) / fps; + document.getElementById(event.target.id).value = `${frame}`; + + /* If all fields are filled the compute */ + if (document.getElementById("startobj").value && document.getElementById("endobj").value) + compute(); +} \ No newline at end of file -- cgit v1.2.3 From 48cedc78c549561912b69076e316962c2c64bfa1 Mon Sep 17 00:00:00 2001 From: Amine El Baghdadi <75886237+NoobJsPerson@users.noreply.github.com> Date: Sat, 15 May 2021 19:56:50 +0000 Subject: update main.js --- main.js | 237 +++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 116 insertions(+), 121 deletions(-) diff --git a/main.js b/main.js index 7c7c783..e806ef5 100644 --- a/main.js +++ b/main.js @@ -1,156 +1,151 @@ /* Define the interpolate function */ function interpolate(template, variables) { - return template.replace(/\${[^{]+}/g, (match) => { - const path = match.slice(2, -1).trim(); - return getObjPath(path, variables); - }); -} - -/* Get the specified property or nested property of an object */ -function getObjPath(path, obj) { - return path.split('.').reduce((res, key) => res[key], obj); + return template.replace(/\${[^{]+}/g, (match) => { + const path = match.slice(2, -1).trim(); + return variables[path]; + }); } /* Compute the total duration of the run. */ function compute() { - const fps = parseInt(document.getElementById("framerate").value); - const s_time = document.getElementById("startobj").value; - const e_time = document.getElementById("endobj").value; - - /* Return early if not all fields are filled */ - if (s_time === undefined || e_time === undefined || fps === undefined) - return; - - /* Return early on a negative time */ - const frames = (e_time - s_time) * fps; - if (frames < 0) { - document.getElementById("time").value = "Error: Negative time"; - return; - } - - const seconds = Math.round(frames / fps * 1000) / 1000; - - /* Show the time and mod message in the DOM. */ - const s_frame = ~~(s_time * fps); - const e_frame = ~~(e_time * fps); - const time = time_format(seconds); - - document.getElementById("time").value = time; - document.getElementById("mod_message").disabled = false; - document.getElementById("mod_message").innerText = generate_mod_message( - fps, s_time, e_time, time, s_frame, e_frame, frames, seconds); - document.getElementById("mod_message_button").disabled = false; + const fps = parseInt(document.getElementById("framerate").value); + const s_time = document.getElementById("startobj").value; + const e_time = document.getElementById("endobj").value; + + /* Return early if not all fields are filled */ + if (s_time === undefined || e_time === undefined || fps === undefined) + return; + + /* Return early on a negative time */ + const frames = (e_time - s_time) * fps; + if (frames < 0) { + document.getElementById("time").value = "Error: Negative time"; + return; + } + + const seconds = Math.round(frames / fps * 1000) / 1000; + + /* Show the time and mod message in the DOM. */ + const s_frame = ~~(s_time * fps); + const e_frame = ~~(e_time * fps); + const time = time_format(seconds); + + document.getElementById("time").value = time; + document.getElementById("mod_message").disabled = false; + document.getElementById("mod_message").innerText = generate_mod_message( + fps, s_time, e_time, time, s_frame, e_frame, frames, seconds); + document.getElementById("mod_message_button").disabled = false; } /* Support custom mod messages. Find a better way to do this, it is very cringe! */ function generate_mod_message( - fps, start_time, end_time, total_time, start_frame, end_frame, total_frames, total_seconds) + fps, start_time, end_time, total_time, start_frame, end_frame, total_frames, total_seconds) { - let mod_message = localStorage.getItem("custom_mod_message"); - - const hours = ~~(total_seconds / 3600) - const minutes = ~~((total_seconds % 3600) / 60); - const seconds = ~~(total_seconds % 60); - const milliseconds = total_seconds % 60 % 1; - - const padded_minutes = (minutes < 10) ? "0" + minutes : minutes; - const padded_seconds = (seconds < 10) ? "0" + seconds : seconds; - - /* - * TODO: THIS IS REALLY STUPID CODE!! - * In a language as bloated as JS surely there is a better way?? - */ - 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.", ""); - 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; + let mod_message = localStorage.getItem("custom_mod_message"); + + const hours = ~~(total_seconds / 3600) + const minutes = ~~((total_seconds % 3600) / 60); + const seconds = ~~(total_seconds % 60); + const milliseconds = total_seconds % 60 % 1; + + const padded_minutes = (minutes < 10) ? "0" + minutes : minutes; + const padded_seconds = (seconds < 10) ? "0" + seconds : seconds; + + /* + * TODO: THIS IS REALLY STUPID CODE!! + * In a language as bloated as JS surely there is a better way?? + */ + 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.", ""); + 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; } /* Convert seconds to human readable time. */ function time_format(t) { - const h = ~~(t / 3600); - const m = ~~((t % 3600) / 60); - const s = t % 60; - let ret = ""; + const h = ~~(t / 3600); + const m = ~~((t % 3600) / 60); + const s = t % 60; + let ret = ""; - if (h > 0) - ret += h + ":" + (m < 10 ? "0" : ""); + if (h > 0) + ret += h + ":" + (m < 10 ? "0" : ""); - ret += m + ":" + (s < 10 ? "0" : "") + s.toFixed(3); + ret += m + ":" + (s < 10 ? "0" : "") + s.toFixed(3); - return ret; + return ret; } /* Allow user to copy mod message to clipboard. */ function copy_mod_message() { - const mod_message = document.getElementById("mod_message"); - mod_message.focus(); - mod_message.select(); - document.execCommand("copy"); + const mod_message = document.getElementById("mod_message"); + mod_message.focus(); + mod_message.select(); + document.execCommand("copy"); } /* If framerate is invalid, show an error message and disable start and end frame fields. */ function check_fps(event) { - fps = event.target.value; - if (fps > 0 && fps % 1 == 0) { - document.getElementById("startobj").disabled = false; - document.getElementById("endobj").disabled = false; - } - else { - document.getElementById("framerate") - .setCustomValidity("Please enter a valid framerate."); - document.getElementById("framerate").reportValidity(); - document.getElementById("startobj").disabled = true; - document.getElementById("endobj").disabled = true; - } + fps = event.target.value; + if (fps > 0 && fps % 1 == 0) { + document.getElementById("startobj").disabled = false; + document.getElementById("endobj").disabled = false; + } + else { + document.getElementById("framerate") + .setCustomValidity("Please enter a valid framerate."); + document.getElementById("framerate").reportValidity(); + document.getElementById("startobj").disabled = true; + document.getElementById("endobj").disabled = true; + } } /* Get current frame from input field (either start time or end time). */ function parse_time(event) { - /* Return early if invalid JSON is passed (numbers are valid) */ - let input, dinfo; - try { - dinfo = JSON.parse(event.target.value); - } catch { - document.getElementById(event.target.id).value = ""; - return; - } - - /* If cmt isn't available fallback to lct, also allow raw numbers */ - if (!(input = dinfo.cmt) && !(input = dinfo.lct) && typeof((input = dinfo)) !== "number") { - document.getElementById(event.target.id).value = ""; - return; - } - - /* Calculate the exact timestamp */ - const fps = parseInt(document.getElementById("framerate").value); - const frame = ~~(input * fps) / fps; - document.getElementById(event.target.id).value = `${frame}`; - - /* If all fields are filled the compute */ - if (document.getElementById("startobj").value && document.getElementById("endobj").value) - compute(); + /* Return early if invalid JSON is passed (numbers are valid) */ + let input, dinfo; + try { + dinfo = JSON.parse(event.target.value); + } catch { + document.getElementById(event.target.id).value = ""; + return; + } + + /* If cmt isn't available fallback to lct, also allow raw numbers */ + if (!(input = dinfo.cmt) && !(input = dinfo.lct) && typeof((input = dinfo)) !== "number") { + document.getElementById(event.target.id).value = ""; + return; + } + + /* Calculate the exact timestamp */ + const fps = parseInt(document.getElementById("framerate").value); + const frame = ~~(input * fps) / fps; + document.getElementById(event.target.id).value = `${frame}`; + + /* If all fields are filled the compute */ + if (document.getElementById("startobj").value && document.getElementById("endobj").value) + compute(); } \ No newline at end of file -- cgit v1.2.3