aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.clang-format44
-rw-r--r--index.html21
-rw-r--r--main.js130
3 files changed, 119 insertions, 76 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..f7f31ac
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,44 @@
+Language: JavaScript
+
+AlignAfterOpenBracket: DontAlign
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignOperands: Align
+AlignTrailingComments: true
+AllowShortBlocksOnASingleLine: Empty
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: Empty
+AllowShortIfStatementsOnASingleLine: Never
+AllowShortLoopsOnASingleLine: false
+BinPackArguments: true
+BinPackParameters: true
+BreakBeforeBinaryOperators: NonAssignment
+BreakBeforeBraces: Attach
+BreakBeforeTernaryOperators: true
+ColumnLimit: 100
+ContinuationIndentWidth: 4
+DeriveLineEnding: true
+IndentCaseBlocks: false
+IndentCaseLabels: false
+IndentWidth: 4
+InsertTrailingCommas: None
+JavaScriptQuotes: Double
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MaxEmptyLinesToKeep: 2
+ReflowComments: true
+SpaceAfterLogicalNot: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceBeforeSquareBrackets: false
+SpaceInEmptyBlock: false
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInConditionalStatement: false
+SpacesInContainerLiterals: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+TabWidth: 4
+UseCRLF: false
+UseTab: Never \ No newline at end of file
diff --git a/index.html b/index.html
index 401e392..3dfcbb0 100644
--- a/index.html
+++ b/index.html
@@ -12,18 +12,13 @@
<body class="stackedit">
<div class="stackedit__html">
- <h1 id="youtube-interval-timer">YouTube Interval Timer</h1>
- <h3 id="about">About</h3>
- <p>Takes start and stop points of a YouTube video, down to the frame, and gives the time between them in the format
- <code>1h 23m 45s 678ms</code>. Source code is <a
- href="https://github.com/slashinfty/yt-frame-timer">available</a>.
- </p>
+ <h1 id="youtube-interval-timer">Speedrun Retimer without Ads</h1>
<h3 id="video-framerate">Video Framerate</h3>
<p>Right click the YouTube video and select “Stats for nerds.” The third line is “Current / Optimal Res” - find the
two numbers after the @ and enter them for framerate.</p>
<p>
<label for="framerate">Framerate: </label>
- <input type="text" id="framerate" size="3" value="60" onchange='validateFPS(event)' />
+ <input type="text" id="framerate" size="3" value="60" onchange='check_fps(event)' />
</p>
<h3 id="video-endpoints">Video Endpoints</h3>
<p>
@@ -32,20 +27,20 @@
</p>
<p>
<label for="startobj">Starting frame: </label>
- <input type="text" id="startobj" style='width:100%' onchange='parseForTime(event)' />
+ <input type="text" id="startobj" style='width:100%' onchange='parse_time(event)' />
</p>
<p>
<label for="endobj">Ending frame: </label>
- <input type="text" id="endobj" style='width:100%' onchange='parseForTime(event)' />
+ <input type="text" id="endobj" style='width:100%' onchange='parse_time(event)' />
</p>
<h3 id="video-time">Video Time</h3>
- <button id="computeButton" onclick="compute()">Compute time</button>&nbsp;<input type="text" id="time" readonly
+ <button id="compute_button" onclick="compute()">Compute time</button>&nbsp;<input type="text" id="time" readonly
size="20" />
<p>
- <textarea id="modMessage" cols="40" rows="5" disabled></textarea>
+ <textarea id="mod_message" cols="40" rows="5" disabled></textarea>
</p>
- <button id="modMessageButton" onclick="copyModMessage()" disabled>Copy Mod Message to Clipboard</button>
+ <button id="mod_message_button" onclick="copy_mod_message()" disabled>Copy Mod Message to Clipboard</button>
</div>
</body>
-</html>
+</html> \ No newline at end of file
diff --git a/main.js b/main.js
index be50fd7..8ab2fee 100644
--- a/main.js
+++ b/main.js
@@ -1,86 +1,90 @@
-function compute()
-{
+function compute() {
/* Initiate basic time variables */
- let hours = 0;
- let minutes = 0;
- let seconds = 0;
- let milliseconds = 0;
+ let h = 0;
+ let m = 0;
+ let s = 0;
+ let ms = 0;
/*
* Get framerate, start frame, and end frame from corresponding elements
* Double check they all have a value
*/
- let frameRate = parseInt(document.getElementById('framerate').value);
- let startFrame = document.getElementById('startobj').value;
- let endFrame = document.getElementById('endobj').value;
- if (typeof (startFrame) === 'undefined' || endFrame === 'undefined' || framerate === 'undefined')
+ let fps = parseInt(document.getElementById("framerate").value);
+ let sframe = document.getElementById("startobj").value;
+ let eframe = document.getElementById("endobj").value;
+
+ if (typeof (sframe) === "undefined" || typeof (eframe) === "undefined"
+ || typeof (fps) === "undefined")
return;
/* Calculate framerate */
- let frames = (endFrame - startFrame) * frameRate;
- seconds = Math.floor(frames / frameRate);
- frames = frames % frameRate;
- milliseconds = Math.round(frames / frameRate * 1000);
- if (milliseconds < 10)
- milliseconds = '00' + milliseconds;
- else if (milliseconds < 100)
- milliseconds = '0' + milliseconds;
-
- if (seconds >= 60) {
- minutes = Math.floor(seconds / 60);
- seconds = seconds % 60;
- seconds = seconds < 10 ? '0' + seconds : seconds;
+ let frames = (eframe - sframe) * fps;
+ s = Math.floor(frames / fps);
+ frames = frames % fps;
+ ms = Math.round(frames / fps * 1000);
+ if (ms < 10)
+ ms = "00" + ms;
+ else if (ms < 100)
+ ms = "0" + ms;
+
+ if (s >= 60) {
+ m = Math.floor(s / 60);
+ s = s % 60;
+ s = s < 10 ? "0" + s : s;
}
- if (minutes >= 60) {
- hours = Math.floor(minutes / 60);
- minutes = minutes % 60;
- minutes = minutes < 10 ? '0' + minutes : minutes;
+ if (m >= 60) {
+ h = Math.floor(m / 60);
+ m = m % 60;
+ m = m < 10 ? "0" + m : m;
}
/* Show the time and mod message in the DOM */
- let finalTime = hours.toString() + 'h ' + minutes.toString() + 'm ' + seconds.toString() + 's ' + milliseconds.toString() + 'ms';
- let modMessage = `Mod Note: Retimed (Start: ${parseFloat(startFrame).toFixed(3)}, End: ${parseFloat(endFrame).toFixed(3)}, FPS: ${frameRate}, Total Time: ${finalTime})`;
- document.getElementById('time').value = finalTime;
- document.getElementById('modMessage').disabled = false;
- document.getElementById('modMessage').innerText = modMessage;
- document.getElementById("modMessageButton").disabled = false;
+ let ftime =
+ h.toString() + "h " + m.toString() + "m " + s.toString() + "s " + ms.toString() + "ms";
+ let mod_message = `Mod Note: Retimed (Start: Frame ${sframe * fps}, End: ${
+ eframe * fps}, FPS: ${fps}, Total Time: ${ftime})`;
+
+ document.getElementById("time").value = ftime;
+ document.getElementById("mod_message").disabled = false;
+ document.getElementById("mod_message").innerText = mod_message;
+ document.getElementById("mod_message_button").disabled = false;
}
/* Allow user to copy mod message to clipboard */
-function copyModMessage()
-{
- const textArea = document.getElementById('modMessage');
- textArea.focus();
- textArea.select();
- document.execCommand('copy');
- alert(`The mod message has been copied to clipboard! Please paste it into the comment of the run you are verifying.`);
+function copyModMessage() {
+ const text_area = document.getElementById("mod_message");
+ text_area.focus();
+ text_area.select();
+ document.execCommand("copy");
+ alert(
+ `The mod message has been copied to clipboard! Please paste it into the comment of the run you are verifying.`);
}
/* If framerate is invalid, show an error message and disable start and end frame fields */
-const validateFPS = (event) => {
- if (event.target.value === '' || parseInt(event.target.value) <= 0 || isNaN(parseInt(event.target.value))) {
- document.getElementById('framerate').setCustomValidity('Please enter a valid framerate.');
- document.getElementById('framerate').reportValidity();
- document.getElementById('startobj').disabled = true;
- document.getElementById('endobj').disabled = true;
- document.getElementById('computeButton').disabled = true;
- } else {
- document.getElementById('startobj').disabled = false;
- document.getElementById('endobj').disabled = false;
- document.getElementById('computeButton').disabled = false;
+const check_fps =
+ (event) => {
+ if (event.target.value === "" || parseInt(event.target.value) <= 0
+ || isNaN(parseInt(event.target.value))) {
+ document.getElementById("framerate")
+ .setCustomValidity("Please enter a valid framerate.");
+ document.getElementById("framerate").reportValidity();
+ document.getElementById("startobj").disabled = true;
+ document.getElementById("endobj").disabled = true;
+ document.getElementById("computeButton").disabled = true;
+ } else {
+ document.getElementById("startobj").disabled = false;
+ document.getElementById("endobj").disabled = false;
+ document.getElementById("computeButton").disabled = false;
+ }
}
-}
-const parseForTime = (event) => {
- /* Get current frame from input field (either start time or end time) */
- let frameFromInputText = (JSON.parse(event.target.value)).lct;
- if (typeof frameFromInputText !== 'undefined') {
- /* Get the framerate */
- let frameRate = parseInt(document.getElementById('framerate').value);
- /* Calculate the frame */
- let frameFromObj = (time, fps) => Math.floor(time * fps) / fps; //round to the nearest frame
- let finalFrame = frameFromObj(frameFromInputText, frameRate);
- /* Update the DOM */
- document.getElementById(event.target.id).value = `${finalFrame}`;
+/* Get current frame from input field (either start time or end time) */
+const parse_time = (event) => {
+ let inptext_frame = (JSON.parse(event.target.value)).lct;
+ if (typeof inptext_frame !== "undefined") {
+ let fps = parseInt(document.getElementById("framerate").value);
+ let frameFromObj = (time, fps) => Math.floor(time * fps) / fps;
+ let fframe = frameFromObj(inptext_frame, fps);
+ document.getElementById(event.target.id).value = `${fframe}`;
}
}