#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 46 additions and 3 deletions
Showing only changes of commit 510061c1e0 - Show all commits

View file

@ -48,6 +48,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">Display character count in chat</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

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

View file

@ -16,6 +16,7 @@ export const SETTINGS_requestBeautifyPage = 'requestBeautifyPage';
export const SETTINGS_playerAutoplayAfterScreenshot = 'playerAutoplayAfterScreenshot'; export const SETTINGS_playerAutoplayAfterScreenshot = 'playerAutoplayAfterScreenshot';
// 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

@ -23,7 +23,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);
} }
@ -38,8 +38,8 @@ function observeScreenshotTooltip(tooltip: HTMLElement): 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

@ -0,0 +1,37 @@
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.runAfterLocationChange(() => {
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;
}
})
}
}, "^/watch2gether/.*$");
}
});
}