From a8d66ecf78147b2056ffec7e270369852501bf9e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 8 May 2020 17:55:31 +0200 Subject: watch_credits: Fix shadowed `controls` variable Silly me, the `controls` module was getting shadowed by the `controls` variable in `init_mutation_observer()`, which contained the DOM element. That's why the controls weren't getting hidden. Now that we're no longer shadowing the variable, the controls do get properly hidden. --- src/wait_element.ts | 5 +++++ src/watch_credits.ts | 17 +++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/wait_element.ts b/src/wait_element.ts index f24b891..cd1bb1d 100644 --- a/src/wait_element.ts +++ b/src/wait_element.ts @@ -1,3 +1,6 @@ +import logger from './logger'; + + export default function wait_element (selector: string): Promise { return new Promise(function(resolve) { const interval = setInterval( @@ -5,6 +8,8 @@ export default function wait_element (selector: string): Promise { const element = document.querySelector(selector); if (element) { + logger.debug('wait_element():', 'found', element); + clearInterval(interval); resolve(element); diff --git a/src/watch_credits.ts b/src/watch_credits.ts index ceba425..fd021ac 100644 --- a/src/watch_credits.ts +++ b/src/watch_credits.ts @@ -3,7 +3,7 @@ import logger from './logger'; import wait_element from './wait_element'; -function init_mutation_observer (controls) { +function init_mutation_observer (controls_el) { const observer = new MutationObserver(function(mutation_list) { for (var i = 0; i < mutation_list.length; i++) { const mutation = mutation_list[i]; @@ -14,7 +14,12 @@ function init_mutation_observer (controls) { ); if (watch_credits_button) { - logger.debug('found Watch Credits button', watch_credits_button); + logger.debug( + 'watch_credits', + 'init_mutation_observer()', + 'found Watch Credits button', + watch_credits_button, + ); const pointer_event = new PointerEvent('pointerdown', { bubbles: true }); watch_credits_button.dispatchEvent(pointer_event); @@ -27,7 +32,7 @@ function init_mutation_observer (controls) { }); observer.observe( - controls, + controls_el, { childList: true, subtree: true @@ -37,9 +42,9 @@ function init_mutation_observer (controls) { export default function init () { wait_element('.PlayerControlsNeo__all-controls') - .then(function(controls) { - logger.debug('Controls element:', controls); + .then(function(controls_el) { + logger.debug('Controls element:', controls_el); - init_mutation_observer(controls); + init_mutation_observer(controls_el); }); } -- cgit v1.2.3