Skip to content

Commit

Permalink
F11 keypress does not exit auto full screen
Browse files Browse the repository at this point in the history
  • Loading branch information
sagynbek committed Aug 18, 2021
1 parent a966d51 commit 750bc98
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/inject/player/auto-full-screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ export class AutoFullScreen<T extends HTMLDivElement> extends BaseModel<T> {
private async init() {
await this.subscribeToPreference(FULL_SCREEN.key, FULL_SCREEN.default, this.setPermition);
await this.subscribeToPreference(AUTO_PLAY_VIDEO.key, AUTO_PLAY_VIDEO.default, this.setAutoPlayPermition);
await this.subscribeToPreference(NEXT_EPISODE_LAST_TRIGGER_TIME.key, NEXT_EPISODE_LAST_TRIGGER_TIME.default, (lastTriggerTime) => {
// @ts-ignore
if (lastTriggerTime && (new Date() - new Date(lastTriggerTime)) < TOLERATE_AUTO_FULL_SCREEN_IN_MS) {
this.nextEpisodeLastTriggerTimeFitsTime = true;
}
});
await this.subscribeToPreference(NEXT_EPISODE_LAST_TRIGGER_TIME.key, NEXT_EPISODE_LAST_TRIGGER_TIME.default, this.handleLastTriggerTime);

this.onDomAdd(this.validate, this.action);
}
Expand All @@ -37,6 +32,13 @@ export class AutoFullScreen<T extends HTMLDivElement> extends BaseModel<T> {
this.autoPlayPermitted = permission;
}

private handleLastTriggerTime = (lastTriggerTime) => {
// @ts-ignore
if (lastTriggerTime && (new Date() - new Date(lastTriggerTime)) < TOLERATE_AUTO_FULL_SCREEN_IN_MS) {
this.nextEpisodeLastTriggerTimeFitsTime = true;
}
}

private validate = (element: T) => {
return (
this.permitted
Expand All @@ -53,8 +55,14 @@ export class AutoFullScreen<T extends HTMLDivElement> extends BaseModel<T> {

const bodyElement = document.querySelector("body");
bodyElement.classList.add(CSS_FULL_SCREEN_CLASS);

document.addEventListener("mousedown", this.exitCssFullScreen);
document.addEventListener("keyup", this.exitCssFullScreen);
document.addEventListener("keyup", (e) => {
// F11's keycode = 122
if (e.keyCode !== 122) {
this.exitCssFullScreen();
}
});
}

private exitCssFullScreen = () => {
Expand Down

0 comments on commit 750bc98

Please sign in to comment.