#144 Autotoggle the hide feature #179
2180
package-lock.json
generated
2180
package-lock.json
generated
File diff suppressed because it is too large
Load diff
10
package.json
10
package.json
|
@ -39,11 +39,11 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@babel/compat-data": "^7.12.13",
|
||||
"@babel/core": "^7.12.13",
|
||||
"@babel/core": "^7.12.16",
|
||||
"@babel/helper-module-imports": "^7.12.13",
|
||||
"@babel/plugin-proposal-class-properties": "^7.12.13",
|
||||
"@babel/plugin-proposal-private-methods": "^7.12.13",
|
||||
"@babel/preset-env": "^7.12.13",
|
||||
"@babel/preset-env": "^7.12.16",
|
||||
"@babel/register": "^7.12.13",
|
||||
"@types/chrome": "0.0.129",
|
||||
"babelify": "^10.0.0",
|
||||
|
@ -70,11 +70,11 @@
|
|||
"gulp-typescript": "^6.0.0-alpha.1",
|
||||
"gulp-zip": "^5.0.2",
|
||||
"merge-stream": "^2.0.0",
|
||||
"postcss": "^8.2.5",
|
||||
"sass": "^1.32.6",
|
||||
"postcss": "^8.2.6",
|
||||
"sass": "^1.32.7",
|
||||
"terser": "^5.5.1",
|
||||
"tsify": "^5.0.2",
|
||||
"typescript": "^4.1.3",
|
||||
"typescript": "^4.1.5",
|
||||
"vinyl-buffer": "^1.0.1",
|
||||
"vinyl-source-stream": "^2.0.0",
|
||||
"web-ext-types": "^3.2.1"
|
||||
|
|
|
@ -44,6 +44,12 @@
|
|||
<input type="checkbox" id="playerAutoplayAfterScreenshot" data-default-value="true" />
|
||||
<label for="playerAutoplayAfterScreenshot">Autoplay after screenshots</label><br />
|
||||
|
||||
<input type="checkbox" id="playerAutopauseAfterFocusLost" data-default-value="true" />
|
||||
<label for="playerAutopauseAfterFocusLost">Autopause after tab unfocused</label><br />
|
||||
|
||||
<input type="checkbox" id="playerAutoplayAfterFocusGain" data-default-value="true" />
|
||||
<label for="playerAutoplayAfterFocusGain">Autoplay after tab focused</label><br />
|
||||
|
||||
<h3>Watch2gether</h3>
|
||||
<input type="checkbox" id="w2gDisplayCharacterCounter" data-default-value="true" />
|
||||
<label for="w2gDisplayCharacterCounter">Display character count in chat</label><br />
|
||||
|
|
|
@ -14,6 +14,8 @@ export const SETTINGS_animeLanguageDisplay = 'animeLanguageDisplay';
|
|||
export const SETTINGS_requestBeautifyPage = 'requestBeautifyPage';
|
||||
// player
|
||||
export const SETTINGS_playerAutoplayAfterScreenshot = 'playerAutoplayAfterScreenshot';
|
||||
export const SETTINGS_playerAutopauseAfterFocusLost = 'playerAutopauseAfterFocusLost';
|
||||
export const SETTINGS_playerAutoplayAfterFocusGain = 'playerAutoplayAfterFocusGain';
|
||||
// w2g
|
||||
export const SETTINGS_w2gDisplayCharacterCounter = 'w2gDisplayCharacterCounter';
|
||||
export const SETTINGS_w2gAutotoggleHide = 'w2gAutotoggleHide';
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
import { getGlobalConfiguration, SETTINGS_playerAutoplayAfterScreenshot } from '../configuration/configuration';
|
||||
import { getGlobalConfiguration,
|
||||
SETTINGS_playerAutoplayAfterScreenshot,
|
||||
SETTINGS_playerAutopauseAfterFocusLost,
|
||||
SETTINGS_playerAutoplayAfterFocusGain } from '../configuration/configuration';
|
||||
import * as core from '../utils/aniwatchCore';
|
||||
import * as helper from '../utils/helpers';
|
||||
|
||||
const SCREENSHOT_TOOLTIP_ID = 'anilyr-screenshots-tooltip';
|
||||
const PLAYER_ID = 'player';
|
||||
let resumePlayerOnVisible: boolean;
|
||||
|
||||
export function init(): void {
|
||||
getGlobalConfiguration().getProperty(SETTINGS_playerAutoplayAfterScreenshot, value => {
|
||||
|
@ -16,6 +20,18 @@ export function init(): void {
|
|||
}, "^/anime/[0-9]*/[0-9]*$");
|
||||
}
|
||||
});
|
||||
|
||||
getGlobalConfiguration().getProperty(SETTINGS_playerAutopauseAfterFocusLost, value => {
|
||||
if (value) {
|
||||
core.registerScript((node: Node) => {
|
||||
window.addEventListener('visibilitychange', observeTabFocus, false);
|
||||
}, "^/anime/[0-9]*/[0-9]*$");
|
||||
}
|
||||
});
|
||||
|
||||
getGlobalConfiguration().getProperty(SETTINGS_playerAutoplayAfterFocusGain, value => {
|
||||
resumePlayerOnVisible = value;
|
||||
});
|
||||
}
|
||||
|
||||
function observeScreenshotTooltip(tooltip: HTMLElement): void {
|
||||
|
@ -38,6 +54,22 @@ function observeScreenshotTooltip(tooltip: HTMLElement): void {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
function observeTabFocus(): void {
|
||||
let docState = document.visibilityState;
|
||||
let playerElement = findPlayerElement(PLAYER_ID);
|
||||
if (docState === 'hidden') {
|
||||
if (helper.assigned(playerElement)) {
|
||||
pausePlayer(playerElement);
|
||||
}
|
||||
}
|
||||
else if (docState === 'visible' && resumePlayerOnVisible) {
|
||||
if (helper.assigned(playerElement)) {
|
||||
resumePlayer(playerElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function findPlayerElement(id: string): HTMLVideoElement {
|
||||
let playerCandidate = document.getElementById(id);
|
||||
if (playerCandidate instanceof HTMLVideoElement) {
|
||||
|
@ -49,4 +81,8 @@ export function findPlayerElement(id: string): HTMLVideoElement {
|
|||
|
||||
function resumePlayer(player: HTMLVideoElement) {
|
||||
player.play();
|
||||
}
|
||||
|
||||
function pausePlayer(player: HTMLVideoElement) {
|
||||
player.pause()
|
||||
}
|
Loading…
Reference in a new issue