Skip to content

Commit

Permalink
Add hotkey for frame seeking when time edit is open
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Feb 21, 2024
1 parent 18f55b7 commit ff9641e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion maze-utils
17 changes: 17 additions & 0 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2100,6 +2100,8 @@ 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);
}
}

Expand Down Expand Up @@ -2345,6 +2347,21 @@ 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
*/
export function seekFrameByKeyPress(e) {
const vid = getVideo()
if (!vid.paused) return
if (e.key === ".") { // next frame
vid.currentTime += 1 / 30;
} else if (e.key === ",") { // previous frame
vid.currentTime -= 1 / 30;
}
}

/**
* Adds the CSS to the page if needed. Required on optional sites with Chrome.
*/
Expand Down
7 changes: 5 additions & 2 deletions src/render/SubmissionNotice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const utils = new Utils();

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

class SubmissionNotice {
// Contains functions and variables from the content script needed by the skip notice
Expand All @@ -26,7 +27,7 @@ class SubmissionNotice {
this.callback = callback;

const referenceNode = utils.findReferenceNode();

this.noticeElement = document.createElement("div");
this.noticeElement.id = "submissionNoticeContainer";

Expand All @@ -36,7 +37,7 @@ class SubmissionNotice {
this.root.render(
<SubmissionNoticeComponent
contentContainer={contentContainer}
callback={callback}
callback={callback}
ref={this.noticeRef}
closeListener={() => this.close(false)} />
);
Expand All @@ -51,6 +52,8 @@ class SubmissionNotice {
this.root.unmount();

this.noticeElement.remove();

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

submit(): void {
Expand Down

0 comments on commit ff9641e

Please sign in to comment.