Total Complexity | 11 |
Complexity/F | 1.57 |
Lines of Code | 48 |
Function Count | 7 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import * as core from '../utils/aniwatchCore'; |
||
2 | import * as helper from '../utils/helpers'; |
||
3 | |||
4 | const SCREENSHOT_TOOLTIP_ID = 'anilyr-screenshots-tooltip'; |
||
5 | const PLAYER_ID = 'player'; |
||
6 | |||
7 | export function init() { |
||
8 | core.registerScript(node => { |
||
9 | if (helper.isHtmlElement(node) && node.id === SCREENSHOT_TOOLTIP_ID) { |
||
10 | observeScreenshotTooltip(node); |
||
11 | } |
||
12 | }, "^/anime/[0-9]*/[0-9]*$"); |
||
13 | } |
||
14 | |||
15 | function observeScreenshotTooltip(tooltip) { |
||
16 | let observer = new MutationObserver(mutations => { |
||
|
|||
17 | mutations.forEach(mutation => { |
||
18 | // Switched to invisible |
||
19 | if (!mutation.oldValue.includes('display: none') && mutation.target.style.display == 'none') { |
||
20 | let player = findPlayer(); |
||
21 | if(typeof player !== 'undefined'){ |
||
22 | resumePlayer(player); |
||
23 | } |
||
24 | } |
||
25 | }); |
||
26 | }); |
||
27 | |||
28 | observer.observe(tooltip, { |
||
29 | attributes: true, |
||
30 | attributeOldValue: true, |
||
31 | attributeFilter: ['style'], |
||
32 | }); |
||
33 | } |
||
34 | |||
35 | function findPlayer() { |
||
36 | const PLAYER_TAG_NAME = 'VIDEO'; // tagName gives UpperCase |
||
37 | |||
38 | let playerCandidate = document.getElementById(PLAYER_ID); |
||
39 | if (playerCandidate.tagName === PLAYER_TAG_NAME) { |
||
40 | return playerCandidate; |
||
41 | } |
||
42 | |||
43 | return undefined; |
||
44 | } |
||
45 | |||
46 | function resumePlayer(player) { |
||
47 | player.play(); |
||
48 | } |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.