merged watch2getherHide.ts into watch2gether.ts

This commit is contained in:
kaffem 2021-02-13 19:37:37 +01:00
parent 53fbd797fe
commit 8091d98799
3 changed files with 42 additions and 50 deletions

View file

@ -10,8 +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/watch2gether'; import { init as watch2gether } from './enhancements/watch2gether';
import { init as watch2getherAutotoggleHide } from './enhancements/watch2getherHide';
// css // css
import { init as cssEnhancements } from './enhancements/cssEnhancements'; import { init as cssEnhancements } from './enhancements/cssEnhancements';
@ -29,8 +28,7 @@ languageDisplay();
notifications(); notifications();
quickSearch(); quickSearch();
timeConversion(); timeConversion();
watch2getherChat(); watch2gether();
watch2getherAutotoggleHide();
// css // css
cssEnhancements(); cssEnhancements();

View file

@ -1,7 +1,11 @@
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 => {
@ -14,6 +18,16 @@ export function init(): void {
}, "^/watch2gether/.*$"); }, "^/watch2gether/.*$");
} }
}); });
getGlobalConfiguration().getProperty(SETTINGS_w2gAutotoggleHide, value => {
if (value) {
core.runAfterLoad(() => {
addAutohideListener();
}, "^/watch2gether/.*$");
core.runAfterLocationChange(() => {
addAutohideListener();
}, "^/watch2gether/.*$");
}
});
} }
function manipulateChatInput(): void { function manipulateChatInput(): void {
@ -65,4 +79,28 @@ function updateCharCounter(textarea: HTMLTextAreaElement, charCounterSpan: HTMLS
charCounterSpan.classList.remove(SHAKE_CLASS); charCounterSpan.classList.remove(SHAKE_CLASS);
}, 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;
}
})
}
}

View file

@ -1,44 +0,0 @@
import * as core from '../utils/aniwatchCore';
import * as helper from '../utils/helpers';
import { getGlobalConfiguration, SETTINGS_w2gAutotoggleHide } from '../configuration/configuration';
import { findPlayerElement } from "../enhancements/anilyr";
const PLAYER_ID = 'wPlayer';
let hidden: boolean;
export function init(): void {
getGlobalConfiguration().getProperty(SETTINGS_w2gAutotoggleHide, value => {
if (value) {
core.runAfterLoad(() => {
addAutohideListener();
}, "^/watch2gether/.*$");
core.runAfterLocationChange(() => {
addAutohideListener();
}, "^/watch2gether/.*$");
}
});
}
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 (helper.assigned(playerElement) && helper.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;
}
})
}
}