From 4099841d4b705c3d761377bbff75e9d84aba402d Mon Sep 17 00:00:00 2001 From: Serraniel Date: Mon, 26 Oct 2020 20:52:51 +0100 Subject: [PATCH] #94 Detect player and resume video --- src/javascript/enhancements/anilyr.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/javascript/enhancements/anilyr.js b/src/javascript/enhancements/anilyr.js index dc6ecbf..f80ebd8 100644 --- a/src/javascript/enhancements/anilyr.js +++ b/src/javascript/enhancements/anilyr.js @@ -2,6 +2,7 @@ import * as core from '../utils/aniwatchCore'; import * as helper from '../utils/helpers'; const SCREENSHOT_TOOLTIP_ID = 'anilyr-screenshots-tooltip'; +const PLAYER_ID = 'player'; export function init() { core.registerScript(node => { @@ -15,8 +16,11 @@ function observeScreenshotTooltip(tooltip) { let observer = new MutationObserver(mutations => { mutations.forEach(mutation => { // Switched to invisible - if(!mutation.oldValue.includes('display: none') && mutation.target.style.display == 'none') { - console.log('SCREENSHOT TOOLTIP CLOSED'); + if (!mutation.oldValue.includes('display: none') && mutation.target.style.display == 'none') { + let player = findPlayer(); + if(typeof player !== 'undefined'){ + resumePlayer(player); + } } }); }); @@ -24,6 +28,21 @@ function observeScreenshotTooltip(tooltip) { observer.observe(tooltip, { attributes: true, attributeOldValue: true, - 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(); } \ No newline at end of file