#144 Autotoggle the hide feature #179

Merged
kaffem merged 7 commits from feature/#144-autotoggle-hide-w2g into develop 2021-02-13 20:02:03 +01:00
5 changed files with 54 additions and 8 deletions

View file

@ -54,6 +54,9 @@
<input type="checkbox" id="w2gDisplayCharacterCounter" data-default-value="true" /> <input type="checkbox" id="w2gDisplayCharacterCounter" data-default-value="true" />
<label for="w2gDisplayCharacterCounter">Display character count in chat</label><br /> <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 /> <br /><br />
<button id="btnSave">Save</button> <button id="btnSave">Save</button>
<button id="btnReset">Reset</button> <button id="btnReset">Reset</button>

View file

@ -10,7 +10,7 @@ import { init as languageDisplay } from './enhancements/languageDisplay';
import { init as notifications } from './enhancements/notifications'; import { init as notifications } from './enhancements/notifications';
import { init as quickSearch } from './enhancements/quickSearch'; import { init as quickSearch } from './enhancements/quickSearch';
import { init as timeConversion } from './enhancements/timeConversion'; import { init as timeConversion } from './enhancements/timeConversion';
import { init as watch2getherChat } from './enhancements/watch2getherChat'; import { init as watch2gether } from './enhancements/watch2gether';
// css // css
import { init as cssEnhancements } from './enhancements/cssEnhancements'; import { init as cssEnhancements } from './enhancements/cssEnhancements';
@ -28,7 +28,7 @@ languageDisplay();
notifications(); notifications();
quickSearch(); quickSearch();
timeConversion(); timeConversion();
watch2getherChat(); watch2gether();
// css // css
cssEnhancements(); cssEnhancements();

View file

@ -18,6 +18,7 @@ export const SETTINGS_playerAutopauseAfterFocusLost = 'playerAutopauseAfterFocus
export const SETTINGS_playerAutoplayAfterFocusGain = 'playerAutoplayAfterFocusGain'; export const SETTINGS_playerAutoplayAfterFocusGain = 'playerAutoplayAfterFocusGain';
// w2g // w2g
export const SETTINGS_w2gDisplayCharacterCounter = 'w2gDisplayCharacterCounter'; export const SETTINGS_w2gDisplayCharacterCounter = 'w2gDisplayCharacterCounter';
export const SETTINGS_w2gAutotoggleHide = 'w2gAutotoggleHide';
class Configuration { class Configuration {
settingsCache: Map<string, boolean>; settingsCache: Map<string, boolean>;

View file

@ -39,7 +39,7 @@ function observeScreenshotTooltip(tooltip: HTMLElement): void {
mutations.forEach(mutation => { mutations.forEach(mutation => {
// Switched to invisible // Switched to invisible
if (!mutation.oldValue.includes('display: none') && helper.isHtmlElement(mutation.target) && (mutation.target as HTMLElement).style.display == 'none') { 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)) { if (helper.assigned(playerElement)) {
resumePlayer(playerElement); resumePlayer(playerElement);
} }
@ -54,9 +54,10 @@ function observeScreenshotTooltip(tooltip: HTMLElement): void {
}); });
} }
function observeTabFocus(): void { function observeTabFocus(): void {
let docState = document.visibilityState; let docState = document.visibilityState;
let playerElement = findPlayerElement(); let playerElement = findPlayerElement(PLAYER_ID);
if (docState === 'hidden') { if (docState === 'hidden') {
if (helper.assigned(playerElement)) { if (helper.assigned(playerElement)) {
pausePlayer(playerElement); pausePlayer(playerElement);
@ -69,8 +70,8 @@ function observeTabFocus(): void {
} }
} }
function findPlayerElement(): HTMLVideoElement { export function findPlayerElement(id: string): HTMLVideoElement {
let playerCandidate = document.getElementById(PLAYER_ID); let playerCandidate = document.getElementById(id);
if (playerCandidate instanceof HTMLVideoElement) { if (playerCandidate instanceof HTMLVideoElement) {
return playerCandidate; return playerCandidate;
} }

View file

@ -1,16 +1,33 @@
import * as core from '../utils/aniwatchCore'; import * as core from '../utils/aniwatchCore';
import { v4 as uuidv4 } from 'uuid'; 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 { assigned } from '../utils/helpers';
import { findPlayerElement } from "../enhancements/anilyr";
const PLAYER_ID = 'wPlayer';
let hidden: boolean;
export function init(): void { export function init(): void {
getGlobalConfiguration().getProperty(SETTINGS_w2gDisplayCharacterCounter, value => { getGlobalConfiguration().getProperty(SETTINGS_w2gDisplayCharacterCounter, value => {
if (value) { if (value) {
core.runAfterLoad(() => {
manipulateChatInput();
}, "^/watch2gether/.*$");
core.runAfterLocationChange(() => { core.runAfterLocationChange(() => {
manipulateChatInput(); manipulateChatInput();
}, "^/watch2gether/.*$"); }, "^/watch2gether/.*$");
} }
}); });
getGlobalConfiguration().getProperty(SETTINGS_w2gAutotoggleHide, value => {
if (value) {
core.runAfterLoad(() => {
addAutohideListener();
}, "^/watch2gether/.*$");
core.runAfterLocationChange(() => {
addAutohideListener();
}, "^/watch2gether/.*$");
}
});
} }
function manipulateChatInput(): void { function manipulateChatInput(): void {
@ -63,3 +80,27 @@ function updateCharCounter(textarea: HTMLTextAreaElement, charCounterSpan: HTMLS
}, 200); }, 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;
}
})
}
}