Feature/#94 auto resume after screenshot #101

Merged
Serraniel merged 4 commits from feature/#94-auto-resume-after-screenshot into develop 2020-10-28 19:25:08 +01:00
2 changed files with 50 additions and 0 deletions

View file

@ -0,0 +1,48 @@
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 => {
if (helper.isHtmlElement(node) && node.id === SCREENSHOT_TOOLTIP_ID) {
observeScreenshotTooltip(node);
}
}, "^/anime/[0-9]*/[0-9]*$");
}
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') {
let player = findPlayer();
if(typeof player !== 'undefined'){
resumePlayer(player);
}
}
});
});
observer.observe(tooltip, {
attributes: true,
attributeOldValue: true,
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();
}

View file

@ -3,6 +3,7 @@ import { initCore } from './utils/aniwatchCore';
// helper // helper
import { initHelpers } from './utils/helpers'; import { initHelpers } from './utils/helpers';
// enhancements // enhancements
import { init as anilyr } from './enhancements/anilyr';
import { init as animeRequests } from './enhancements/animeRequests'; import { init as animeRequests } from './enhancements/animeRequests';
import { init as languageDisplay } from './enhancements/languageDisplay'; import { init as languageDisplay } from './enhancements/languageDisplay';
import { init as quickSearch } from './enhancements/quickSearch'; import { init as quickSearch } from './enhancements/quickSearch';
@ -14,6 +15,7 @@ initCore();
initHelpers(); initHelpers();
// enhancements // enhancements
anilyr();
animeRequests(); animeRequests();
languageDisplay(); languageDisplay();
quickSearch(); quickSearch();