#144 Autotoggle the hide feature #179
|
@ -54,6 +54,9 @@
|
|||
<input type="checkbox" id="w2gDisplayCharacterCounter" data-default-value="true" />
|
||||
<label for="w2gDisplayCharacterCounter">Display character count in chat</label><br />
|
||||
|
||||
<input type="checkbox" id="w2gAutotoggleHide" data-default-value="true" />
|
||||
<label for="w2gAutotoggleHide">Autotoggle the Hide-Button for w2g</label><br />
|
||||
|
||||
<br /><br />
|
||||
<button id="btnSave">Save</button>
|
||||
<button id="btnReset">Reset</button>
|
||||
|
|
|
@ -10,7 +10,7 @@ import { init as languageDisplay } from './enhancements/languageDisplay';
|
|||
import { init as notifications } from './enhancements/notifications';
|
||||
import { init as quickSearch } from './enhancements/quickSearch';
|
||||
import { init as timeConversion } from './enhancements/timeConversion';
|
||||
import { init as watch2getherChat } from './enhancements/watch2getherChat';
|
||||
import { init as watch2gether } from './enhancements/watch2gether';
|
||||
// css
|
||||
import { init as cssEnhancements } from './enhancements/cssEnhancements';
|
||||
|
||||
|
@ -28,7 +28,7 @@ languageDisplay();
|
|||
notifications();
|
||||
quickSearch();
|
||||
timeConversion();
|
||||
watch2getherChat();
|
||||
watch2gether();
|
||||
|
||||
// css
|
||||
cssEnhancements();
|
|
@ -18,6 +18,7 @@ export const SETTINGS_playerAutopauseAfterFocusLost = 'playerAutopauseAfterFocus
|
|||
export const SETTINGS_playerAutoplayAfterFocusGain = 'playerAutoplayAfterFocusGain';
|
||||
// w2g
|
||||
export const SETTINGS_w2gDisplayCharacterCounter = 'w2gDisplayCharacterCounter';
|
||||
export const SETTINGS_w2gAutotoggleHide = 'w2gAutotoggleHide';
|
||||
class Configuration {
|
||||
settingsCache: Map<string, boolean>;
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ function observeScreenshotTooltip(tooltip: HTMLElement): void {
|
|||
mutations.forEach(mutation => {
|
||||
// Switched to invisible
|
||||
if (!mutation.oldValue.includes('display: none') && helper.isHtmlElement(mutation.target) && (mutation.target as HTMLElement).style.display == 'none') {
|
||||
let playerElement = findPlayerElement();
|
||||
let playerElement = findPlayerElement(PLAYER_ID);
|
||||
if (helper.assigned(playerElement)) {
|
||||
resumePlayer(playerElement);
|
||||
}
|
||||
|
@ -54,9 +54,10 @@ function observeScreenshotTooltip(tooltip: HTMLElement): void {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
function observeTabFocus(): void {
|
||||
let docState = document.visibilityState;
|
||||
let playerElement = findPlayerElement();
|
||||
let playerElement = findPlayerElement(PLAYER_ID);
|
||||
if (docState === 'hidden') {
|
||||
if (helper.assigned(playerElement)) {
|
||||
pausePlayer(playerElement);
|
||||
|
@ -69,8 +70,8 @@ function observeTabFocus(): void {
|
|||
}
|
||||
}
|
||||
|
||||
function findPlayerElement(): HTMLVideoElement {
|
||||
let playerCandidate = document.getElementById(PLAYER_ID);
|
||||
export function findPlayerElement(id: string): HTMLVideoElement {
|
||||
let playerCandidate = document.getElementById(id);
|
||||
if (playerCandidate instanceof HTMLVideoElement) {
|
||||
return playerCandidate;
|
||||
}
|
||||
|
|
|
@ -1,16 +1,33 @@
|
|||
import * as core from '../utils/aniwatchCore';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { getGlobalConfiguration, SETTINGS_w2gDisplayCharacterCounter } from '../configuration/configuration';
|
||||
import { getGlobalConfiguration, SETTINGS_w2gDisplayCharacterCounter, SETTINGS_w2gAutotoggleHide } from '../configuration/configuration';
|
||||
import { assigned } from '../utils/helpers';
|
||||
import { findPlayerElement } from "../enhancements/anilyr";
|
||||
|
||||
const PLAYER_ID = 'wPlayer';
|
||||
let hidden: boolean;
|
||||
|
||||
export function init(): void {
|
||||
getGlobalConfiguration().getProperty(SETTINGS_w2gDisplayCharacterCounter, value => {
|
||||
if (value) {
|
||||
core.runAfterLoad(() => {
|
||||
manipulateChatInput();
|
||||
}, "^/watch2gether/.*$");
|
||||
core.runAfterLocationChange(() => {
|
||||
manipulateChatInput();
|
||||
}, "^/watch2gether/.*$");
|
||||
}
|
||||
});
|
||||
getGlobalConfiguration().getProperty(SETTINGS_w2gAutotoggleHide, value => {
|
||||
if (value) {
|
||||
core.runAfterLoad(() => {
|
||||
addAutohideListener();
|
||||
}, "^/watch2gether/.*$");
|
||||
core.runAfterLocationChange(() => {
|
||||
addAutohideListener();
|
||||
}, "^/watch2gether/.*$");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function manipulateChatInput(): void {
|
||||
|
@ -62,4 +79,28 @@ function updateCharCounter(textarea: HTMLTextAreaElement, charCounterSpan: HTMLS
|
|||
charCounterSpan.classList.remove(SHAKE_CLASS);
|
||||
}, 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addAutohideListener(): void {
|
||||
let playerElement = findPlayerElement(PLAYER_ID);
|
||||
let hideButton: HTMLButtonElement = document.getElementsByClassName('no-margin md-button md-ink-ripple layout-align-center-center layout-row')[0] as HTMLButtonElement;
|
||||
if (assigned(playerElement) && assigned(hideButton)) {
|
||||
if (hideButton.textContent.includes('HIDE')) {
|
||||
hidden = false;
|
||||
} else if (hideButton.textContent.includes('SHOW')) {
|
||||
hidden = true;
|
||||
}
|
||||
playerElement.addEventListener('play', fn => {
|
||||
if (!hidden) {
|
||||
hideButton.click();
|
||||
hidden = !hidden;
|
||||
}
|
||||
})
|
||||
playerElement.addEventListener('pause', fn => {
|
||||
if (hidden) {
|
||||
hideButton.click();
|
||||
hidden = !hidden;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue