Skip to content

Commit

Permalink
Add customizable key for frame seeking
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Feb 21, 2024
1 parent ff9641e commit f82fb79
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion public/_locales
8 changes: 4 additions & 4 deletions public/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,13 @@
<div class="inline"></div>
</div>

<div data-type="keybind-change" data-sync="nextChapterKeybind">
<label class="optionLabel">__MSG_nextChapterKeybind__:</label>
<div data-type="keybind-change" data-sync="nextFrameKeybind">
<label class="optionLabel">__MSG_nextFrameKeybind__:</label>
<div class="inline"></div>
</div>

<div data-type="keybind-change" data-sync="previousChapterKeybind">
<label class="optionLabel">__MSG_previousChapterKeybind__:</label>
<div data-type="keybind-change" data-sync="previousFrameKeybind">
<label class="optionLabel">__MSG_previousFrameKeybind__:</label>
<div class="inline"></div>
</div>

Expand Down
8 changes: 4 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ interface SBConfig {
submitKeybind: Keybind;
actuallySubmitKeybind: Keybind;
previewKeybind: Keybind;
nextChapterKeybind: Keybind;
previousChapterKeybind: Keybind;
nextFrameKeybind: Keybind;
previousFrameKeybind: Keybind;
closeSkipNoticeKeybind: Keybind;

// What categories should be skipped
Expand Down Expand Up @@ -332,8 +332,8 @@ const syncDefaults = {
submitKeybind: { key: "'" },
actuallySubmitKeybind: { key: "'", ctrl: true },
previewKeybind: { key: ";", ctrl: true },
nextChapterKeybind: { key: "ArrowRight", ctrl: true },
previousChapterKeybind: { key: "ArrowLeft", ctrl: true },
nextFrameKeybind: { key: "." },
previousFrameKeybind: { key: "," },
closeSkipNoticeKeybind: { key: "Backspace" },

categorySelections: [{
Expand Down
14 changes: 9 additions & 5 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2101,7 +2101,7 @@ function openSubmissionMenu() {
if (sponsorTimesSubmitting !== undefined && sponsorTimesSubmitting.length > 0) {
submissionNotice = new SubmissionNotice(skipNoticeContentContainer, sendSubmitMessage);
// Add key bind for jumpping to next frame, for easier sponsor time editting
document.addEventListener("keydown", seekFrameByKeyPress);
document.addEventListener("keydown", seekFrameByKeyPressListener);
}
}

Expand Down Expand Up @@ -2350,14 +2350,18 @@ function hotkeyListener(e: KeyboardEvent): void {
/**
* Hot keys to jump to the next or previous frame, for easier segment time editting
* only effective when the SubmissionNotice is open
* @param e keydown event
*
* Uses 1/30s as the frame rate, as it's the most common frame rate for videos
* @param key keydown event
*/
export function seekFrameByKeyPress(e) {
export function seekFrameByKeyPressListener(key) {
const vid = getVideo()
if (!vid.paused) return
if (e.key === ".") { // next frame

// TODO: better way to check framerate or next frame
if (keybindEquals(key, Config.config.nextFrameKeybind)) { // next frame
vid.currentTime += 1 / 30;
} else if (e.key === ",") { // previous frame
} else if (keybindEquals(key, Config.config.previousFrameKeybind)) { // previous frame
vid.currentTime -= 1 / 30;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/render/SubmissionNotice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const utils = new Utils();

import SubmissionNoticeComponent from "../components/SubmissionNoticeComponent";
import { ContentContainer } from "../types";
import { seekFrameByKeyPress } from "../content";
import { seekFrameByKeyPressListener } from "../content";

class SubmissionNotice {
// Contains functions and variables from the content script needed by the skip notice
Expand Down Expand Up @@ -53,7 +53,7 @@ class SubmissionNotice {

this.noticeElement.remove();

document.removeEventListener("keydown", seekFrameByKeyPress);
document.removeEventListener("keydown", seekFrameByKeyPressListener);
}

submit(): void {
Expand Down

0 comments on commit f82fb79

Please sign in to comment.