diff options
-rw-r--r-- | main.js | 57 | ||||
-rw-r--r-- | settings.html | 4 | ||||
-rw-r--r-- | settings.js | 21 |
3 files changed, 76 insertions, 6 deletions
@@ -22,15 +22,64 @@ function compute() const s_frame = Math.trunc(s_time * fps); const e_frame = Math.trunc(e_time * fps); const time = time_format(seconds); - const mod_message = `Mod Note: Retimed (Start Frame: ${s_frame}, End Frame: ${ - e_frame}, FPS: ${fps}, Total Time: ${time})`; document.getElementById("time").value = time; document.getElementById("mod_message").disabled = false; - document.getElementById("mod_message").innerText = mod_message; + 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) +{ + let mod_message = localStorage.getItem("custom_mod_message"); + + const hours = ~~(total_seconds / 3600) + const minutes = ~~((total_seconds % 3600) / 60); + const seconds = Math.trunc(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 BAD CODE!! FIX THIS!! */ + 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) + + return mod_message; +} + /* Convert seconds to human readable time. */ function time_format(t) { @@ -93,7 +142,7 @@ function parse_time(event) /* Calculate the exact timestamp */ const fps = parseInt(document.getElementById("framerate").value); - const frame = Math.floor(input * fps) / fps; + const frame = ~~(input * fps) / fps; document.getElementById(event.target.id).value = `${frame}`; /* If all fields are filled the compute */ diff --git a/settings.html b/settings.html index c4eaced..3db898b 100644 --- a/settings.html +++ b/settings.html @@ -53,6 +53,10 @@ <input type="checkbox" id="page_text" onclick="remove_text()"> <span class="slider" id="slider"></span> </label> + <br> + <br> + <h3 class="options">Custom Mod Message</h3> + <textarea id="custom_mod_message" cols="40" rows="3" onchange="set_mod_message(event)"></textarea> <!-- This needs to come after the switches switch --> <script src="settings.js"></script> diff --git a/settings.js b/settings.js index a82281d..84a078c 100644 --- a/settings.js +++ b/settings.js @@ -1,3 +1,5 @@ +const mod_message_default = "Mod Note: Retimed (Start Frame: ${SF}, End Frame: ${EF}, FPS: ${FPS}, Total Time: ${TT})"; + /* Set all the settings any time someone loads a page */ function set_settings() { @@ -10,8 +12,12 @@ function set_settings() function settings_init() { document.getElementById("page_theme").checked = (localStorage.getItem("theme") === "dark"); - document.getElementById("page_titles").checked = (localStorage.getItem("remove_titles") === "true"); - document.getElementById("page_text").checked = (localStorage.getItem("remove_text") === "true"); + document.getElementById("page_titles").checked = (localStorage.getItem("remove_titles") + === "true"); + document.getElementById("page_text").checked = (localStorage.getItem("remove_text") + === "true"); + const mod_message = localStorage.getItem("custom_mod_message"); + document.getElementById("custom_mod_message").value = mod_message ? mod_message : mod_message_default; } /* Change the users preferred theme. */ @@ -72,6 +78,17 @@ function remove_text() localStorage.setItem("remove_text", checked.toString()); } +/* Set a custom mod message */ +function set_mod_message(event) +{ + if (event.target.value.replace(/\s/g, "")) + localStorage.setItem("custom_mod_message", event.target.value); + else { + event.target.value = mod_message_default; + localStorage.setItem("custom_mod_message", mod_message_default); + } +} + /* Conform to the users preferences */ if (window.location.href.endsWith("settings.html")) settings_init(); |