#94 Detect player and resume video

This commit is contained in:
Serraniel 2020-10-26 20:52:51 +01:00
parent 9ada3dbee6
commit 4099841d4b
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3

View file

@ -2,6 +2,7 @@ import * as core from '../utils/aniwatchCore';
import * as helper from '../utils/helpers'; import * as helper from '../utils/helpers';
const SCREENSHOT_TOOLTIP_ID = 'anilyr-screenshots-tooltip'; const SCREENSHOT_TOOLTIP_ID = 'anilyr-screenshots-tooltip';
const PLAYER_ID = 'player';
export function init() { export function init() {
core.registerScript(node => { core.registerScript(node => {
@ -15,8 +16,11 @@ function observeScreenshotTooltip(tooltip) {
let observer = new MutationObserver(mutations => { let observer = new MutationObserver(mutations => {
mutations.forEach(mutation => { mutations.forEach(mutation => {
// Switched to invisible // Switched to invisible
if(!mutation.oldValue.includes('display: none') && mutation.target.style.display == 'none') { if (!mutation.oldValue.includes('display: none') && mutation.target.style.display == 'none') {
console.log('SCREENSHOT TOOLTIP CLOSED'); let player = findPlayer();
if(typeof player !== 'undefined'){
resumePlayer(player);
}
} }
}); });
}); });
@ -27,3 +31,18 @@ function observeScreenshotTooltip(tooltip) {
attributeFilter: ['style'], attributeFilter: ['style'],
}); });
} }
function findPlayer() {
const PLAYER_TAG_NAME = 'VIDEO'; // tagName gives UpperCase
let playerCandidate = document.getElementById(PLAYER_ID);
if (playerCandidate.tagName === PLAYER_TAG_NAME) {
return playerCandidate;
}
return undefined;
}
function resumePlayer(player) {
player.play();
}