Add keybind for submitting instead of just using the submission menu

This commit is contained in:
Ajay
2023-12-22 11:41:35 -05:00
parent 5ac19eecd4
commit 157216148c
6 changed files with 39 additions and 10 deletions

View File

@@ -439,6 +439,11 @@
</div> </div>
<div data-type="keybind-change" data-sync="submitKeybind"> <div data-type="keybind-change" data-sync="submitKeybind">
<label class="optionLabel">__MSG_setOpenSubmissionMenuKeybind__:</label>
<div class="inline"></div>
</div>
<div data-type="keybind-change" data-sync="actuallySubmitKeybind">
<label class="optionLabel">__MSG_setSubmitKeybind__:</label> <label class="optionLabel">__MSG_setSubmitKeybind__:</label>
<div class="inline"></div> <div class="inline"></div>
</div> </div>

View File

@@ -143,6 +143,7 @@ class KeybindDialogComponent extends React.Component<KeybindDialogProps, Keybind
if (this.props.option != "skipKeybind" && this.equals(Config.config['skipKeybind']) || if (this.props.option != "skipKeybind" && this.equals(Config.config['skipKeybind']) ||
this.props.option != "submitKeybind" && this.equals(Config.config['submitKeybind']) || this.props.option != "submitKeybind" && this.equals(Config.config['submitKeybind']) ||
this.props.option !== "actuallySubmitKeybind" && this.equals(Config.config['actuallySubmitKeybind']) ||
this.props.option != "startSponsorKeybind" && this.equals(Config.config['startSponsorKeybind'])) this.props.option != "startSponsorKeybind" && this.equals(Config.config['startSponsorKeybind']))
return {message: chrome.i18n.getMessage("keyAlreadyUsed"), blocking: true}; return {message: chrome.i18n.getMessage("keyAlreadyUsed"), blocking: true};

View File

@@ -92,6 +92,7 @@ interface SBConfig {
skipToHighlightKeybind: Keybind; skipToHighlightKeybind: Keybind;
startSponsorKeybind: Keybind; startSponsorKeybind: Keybind;
submitKeybind: Keybind; submitKeybind: Keybind;
actuallySubmitKeybind: Keybind;
nextChapterKeybind: Keybind; nextChapterKeybind: Keybind;
previousChapterKeybind: Keybind; previousChapterKeybind: Keybind;
@@ -341,6 +342,7 @@ const syncDefaults = {
skipToHighlightKeybind: { key: "Enter", ctrl: true }, skipToHighlightKeybind: { key: "Enter", ctrl: true },
startSponsorKeybind: { key: ";" }, startSponsorKeybind: { key: ";" },
submitKeybind: { key: "'" }, submitKeybind: { key: "'" },
actuallySubmitKeybind: { key: "'", ctrl: true },
nextChapterKeybind: { key: "ArrowRight", ctrl: true }, nextChapterKeybind: { key: "ArrowRight", ctrl: true },
previousChapterKeybind: { key: "ArrowLeft", ctrl: true }, previousChapterKeybind: { key: "ArrowLeft", ctrl: true },

View File

@@ -251,7 +251,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
break; break;
case "submitTimes": case "submitTimes":
submitSponsorTimes(); openSubmissionMenu();
break; break;
case "refreshSegments": case "refreshSegments":
// update video on refresh if videoID invalid // update video on refresh if videoID invalid
@@ -312,7 +312,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
updateEditButtonsOnPlayer(); updateEditButtonsOnPlayer();
updateSponsorTimesSubmitting(false); updateSponsorTimesSubmitting(false);
submitSponsorTimes(); openSubmissionMenu();
} }
sendResponse({ sendResponse({
@@ -1816,7 +1816,7 @@ async function createButtons(): Promise<void> {
createButton("startSegment", "sponsorStart", () => startOrEndTimingNewSegment(), "PlayerStartIconSponsorBlocker.svg"); createButton("startSegment", "sponsorStart", () => startOrEndTimingNewSegment(), "PlayerStartIconSponsorBlocker.svg");
createButton("cancelSegment", "sponsorCancel", () => cancelCreatingSegment(), "PlayerCancelSegmentIconSponsorBlocker.svg"); createButton("cancelSegment", "sponsorCancel", () => cancelCreatingSegment(), "PlayerCancelSegmentIconSponsorBlocker.svg");
createButton("delete", "clearTimes", () => clearSponsorTimes(), "PlayerDeleteIconSponsorBlocker.svg"); createButton("delete", "clearTimes", () => clearSponsorTimes(), "PlayerDeleteIconSponsorBlocker.svg");
createButton("submit", "OpenSubmissionMenu", () => submitSponsorTimes(), "PlayerUploadIconSponsorBlocker.svg"); createButton("submit", "OpenSubmissionMenu", () => openSubmissionMenu(), "PlayerUploadIconSponsorBlocker.svg");
createButton("info", "openPopup", () => openInfoMenu(), "PlayerInfoIconSponsorBlocker.svg"); createButton("info", "openPopup", () => openInfoMenu(), "PlayerInfoIconSponsorBlocker.svg");
const controlsContainer = getControls(); const controlsContainer = getControls();
@@ -2227,10 +2227,14 @@ function resetSponsorSubmissionNotice(callRef = true) {
submissionNotice = null; submissionNotice = null;
} }
function submitSponsorTimes() { function closeSubmissionMenu() {
submissionNotice?.close();
submissionNotice = null;
}
function openSubmissionMenu() {
if (submissionNotice !== null){ if (submissionNotice !== null){
submissionNotice.close(); closeSubmissionMenu();
submissionNotice = null;
return; return;
} }
@@ -2240,6 +2244,15 @@ function submitSponsorTimes() {
} }
function submitSegments() {
if (sponsorTimesSubmitting !== undefined
&& sponsorTimesSubmitting.length > 0
&& submissionNotice !== null) {
submissionNotice.submit();
}
}
//send the message to the background js //send the message to the background js
//called after all the checks have been made that it's okay to do so //called after all the checks have been made that it's okay to do so
async function sendSubmitMessage() { async function sendSubmitMessage() {
@@ -2446,7 +2459,8 @@ function hotkeyListener(e: KeyboardEvent): void {
const skipKey = Config.config.skipKeybind; const skipKey = Config.config.skipKeybind;
const skipToHighlightKey = Config.config.skipToHighlightKeybind; const skipToHighlightKey = Config.config.skipToHighlightKeybind;
const startSponsorKey = Config.config.startSponsorKeybind; const startSponsorKey = Config.config.startSponsorKeybind;
const submitKey = Config.config.submitKeybind; const submitKey = Config.config.actuallySubmitKeybind;
const openSubmissionMenuKey = Config.config.submitKeybind;
const nextChapterKey = Config.config.nextChapterKeybind; const nextChapterKey = Config.config.nextChapterKeybind;
const previousChapterKey = Config.config.previousChapterKeybind; const previousChapterKey = Config.config.previousChapterKeybind;
@@ -2466,7 +2480,10 @@ function hotkeyListener(e: KeyboardEvent): void {
startOrEndTimingNewSegment(); startOrEndTimingNewSegment();
return; return;
} else if (keybindEquals(key, submitKey)) { } else if (keybindEquals(key, submitKey)) {
submitSponsorTimes(); submitSegments();
return;
} else if (keybindEquals(key, openSubmissionMenuKey)) {
openSubmissionMenu();
return; return;
} else if (keybindEquals(key, nextChapterKey)) { } else if (keybindEquals(key, nextChapterKey)) {
if (sponsorTimes.length > 0) e.stopPropagation(); if (sponsorTimes.length > 0) e.stopPropagation();
@@ -2485,7 +2502,7 @@ function hotkeyListener(e: KeyboardEvent): void {
} else if (key.key == startSponsorKey?.key && startSponsorKey.code == null && !keybindEquals(Config.syncDefaults.startSponsorKeybind, startSponsorKey)) { } else if (key.key == startSponsorKey?.key && startSponsorKey.code == null && !keybindEquals(Config.syncDefaults.startSponsorKeybind, startSponsorKey)) {
startOrEndTimingNewSegment(); startOrEndTimingNewSegment();
} else if (key.key == submitKey?.key && submitKey.code == null && !keybindEquals(Config.syncDefaults.submitKeybind, submitKey)) { } else if (key.key == submitKey?.key && submitKey.code == null && !keybindEquals(Config.syncDefaults.submitKeybind, submitKey)) {
submitSponsorTimes(); openSubmissionMenu();
} }
} }

View File

@@ -52,6 +52,10 @@ class SubmissionNotice {
this.noticeElement.remove(); this.noticeElement.remove();
} }
submit(): void {
this.noticeRef.current?.submit?.();
}
} }
export default SubmissionNotice; export default SubmissionNotice;