#144 working prototype

This commit is contained in:
kaffem 2021-02-08 13:37:34 +01:00
parent edb881b95c
commit 510061c1e0
5 changed files with 46 additions and 3 deletions

View file

@ -48,6 +48,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">Display character count in chat</label><br />
<br /><br />
<button id="btnSave">Save</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 timeConversion } from './enhancements/timeConversion';
import { init as watch2getherChat } from './enhancements/watch2getherChat';
import { init as watch2getherAutotoggleHide } from './enhancements/watch2getherHide';
// css
import { init as cssEnhancements } from './enhancements/cssEnhancements';
@ -29,6 +30,7 @@ notifications();
quickSearch();
timeConversion();
watch2getherChat();
watch2getherAutotoggleHide();
// css
cssEnhancements();

View file

@ -16,6 +16,7 @@ export const SETTINGS_requestBeautifyPage = 'requestBeautifyPage';
export const SETTINGS_playerAutoplayAfterScreenshot = 'playerAutoplayAfterScreenshot';
// w2g
export const SETTINGS_w2gDisplayCharacterCounter = 'w2gDisplayCharacterCounter';
export const SETTINGS_w2gAutotoggleHide = 'w2gAutotoggleHide';
class Configuration {
settingsCache: Map<string, boolean>;

View file

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

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/.*$");
}
});
}