diff options
author | Teddy Wing | 2020-05-05 22:39:11 +0200 |
---|---|---|
committer | Teddy Wing | 2020-05-05 22:39:11 +0200 |
commit | a70c71fe4e24d0953f01cefdd8b73571716c290b (patch) | |
tree | dbe7b971923e0c250836602094a90d9fbe16c18c /src | |
parent | 0ff130243082c5a509ca1795692c22adc9e194da (diff) | |
download | netflix-immersive-a70c71fe4e24d0953f01cefdd8b73571716c290b.tar.bz2 |
Extract credits handling and CSS styles to separate modules
Start to establish a bit of separation and organisation.
Diffstat (limited to 'src')
-rw-r--r-- | src/fullscreen_credits.ts | 60 | ||||
-rw-r--r-- | src/index.ts | 79 | ||||
-rw-r--r-- | src/styles.ts | 16 |
3 files changed, 78 insertions, 77 deletions
diff --git a/src/fullscreen_credits.ts b/src/fullscreen_credits.ts new file mode 100644 index 0000000..a569fa2 --- /dev/null +++ b/src/fullscreen_credits.ts @@ -0,0 +1,60 @@ +export function with_player (callback) { + var interval = setInterval( + function() { + var player = document.querySelector('.NFPlayer.nf-player-container'); + + if (player) { + clearInterval(interval); + + callback(player); + } + }, + 1000 + ); +} + +export function init_mutation_observer (player) { + var observer = new MutationObserver(function(mutation_list) { + for (var i = 0; i < mutation_list.length; i++) { + var mutation = mutation_list[i]; + var player = mutation.target as HTMLElement; + + if (player.classList.contains('postplay')) { + player.classList.remove('postplay'); + + // Activate player controls. + player.click(); + + // TODO: Change .active to .inactive + // mutation.target.classList.replace('active', 'inactive'); // Didn't work + // Remove .can-resume: Removes white border on hover + // PlayerControlsNeo__bottom-controls PlayerControlsNeo__bottom-controls--faded + // PlayerControlsNeo__layout PlayerControlsNeo__layout--active + // PlayerControlsNeo__layout PlayerControlsNeo__layout--inactive + + // document.querySelector('.PlayerControlsNeo__bottom-controls') + // .classList + // .add('PlayerControlsNeo__bottom-controls--faded'); + + document.querySelector('.PlayerControlsNeo__layout.PlayerControlsNeo__layout--active') + .classList + .replace( + 'PlayerControlsNeo__layout--active', + 'PlayerControlsNeo__layout--inactive' + ); + + // .OriginalsPostPlay-BackgroundTrailer .BackToBrowse + + return; + } + } + }); + + observer.observe( + player, + { + attributeFilter: ['class'], + attributeOldValue: true + } + ); +} diff --git a/src/index.ts b/src/index.ts index b8fcf0f..8c24c2a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,80 +1,5 @@ -function with_player (callback) { - var interval = setInterval( - function() { - var player = document.querySelector('.NFPlayer.nf-player-container'); - - if (player) { - clearInterval(interval); - - callback(player); - } - }, - 1000 - ); -} - -function init_mutation_observer (player) { - var observer = new MutationObserver(function(mutation_list) { - for (var i = 0; i < mutation_list.length; i++) { - var mutation = mutation_list[i]; - var player = mutation.target as HTMLElement; - - if (player.classList.contains('postplay')) { - player.classList.remove('postplay'); - - // Activate player controls. - player.click(); - - // TODO: Change .active to .inactive - // mutation.target.classList.replace('active', 'inactive'); // Didn't work - // Remove .can-resume: Removes white border on hover - // PlayerControlsNeo__bottom-controls PlayerControlsNeo__bottom-controls--faded - // PlayerControlsNeo__layout PlayerControlsNeo__layout--active - // PlayerControlsNeo__layout PlayerControlsNeo__layout--inactive - - // document.querySelector('.PlayerControlsNeo__bottom-controls') - // .classList - // .add('PlayerControlsNeo__bottom-controls--faded'); - - document.querySelector('.PlayerControlsNeo__layout.PlayerControlsNeo__layout--active') - .classList - .replace( - 'PlayerControlsNeo__layout--active', - 'PlayerControlsNeo__layout--inactive' - ); - - // .OriginalsPostPlay-BackgroundTrailer .BackToBrowse - - return; - } - } - }); - - observer.observe( - player, - { - attributeFilter: ['class'], - attributeOldValue: true - } - ); -} - -function styles () { - var style = document.createElement('style'); - var stylesheet = style.sheet as CSSStyleSheet; - - document.head.appendChild(style); - - stylesheet.insertRule( - '.OriginalsPostPlay-BackgroundTrailer .BackToBrowse { visibility: hidden; }', - stylesheet.cssRules.length - ); - - stylesheet.insertRule( - '.player-view-childrens { visibility: hidden; }', - stylesheet.cssRules.length - ); -} +import { init_mutation_observer, with_player } from './fullscreen_credits'; +import { styles } from './styles'; with_player(function(player) { diff --git a/src/styles.ts b/src/styles.ts new file mode 100644 index 0000000..a9997cf --- /dev/null +++ b/src/styles.ts @@ -0,0 +1,16 @@ +export function styles () { + var style = document.createElement('style'); + var stylesheet = style.sheet as CSSStyleSheet; + + document.head.appendChild(style); + + stylesheet.insertRule( + '.OriginalsPostPlay-BackgroundTrailer .BackToBrowse { visibility: hidden; }', + stylesheet.cssRules.length + ); + + stylesheet.insertRule( + '.player-view-childrens { visibility: hidden; }', + stylesheet.cssRules.length + ); +} |