Feature/#94 auto resume after screenshot #101
48
src/javascript/enhancements/anilyr.js
Normal file
48
src/javascript/enhancements/anilyr.js
Normal 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();
|
||||
}
|
|
@ -3,6 +3,7 @@ import { initCore } from './utils/aniwatchCore';
|
|||
// helper
|
||||
import { initHelpers } from './utils/helpers';
|
||||
// enhancements
|
||||
import { init as anilyr } from './enhancements/anilyr';
|
||||
import { init as animeRequests } from './enhancements/animeRequests';
|
||||
import { init as languageDisplay } from './enhancements/languageDisplay';
|
||||
import { init as quickSearch } from './enhancements/quickSearch';
|
||||
|
@ -14,6 +15,7 @@ initCore();
|
|||
initHelpers();
|
||||
|
||||
// enhancements
|
||||
anilyr();
|
||||
animeRequests();
|
||||
languageDisplay();
|
||||
quickSearch();
|
Loading…
Reference in a new issue