Advertisement
Guest User

Untitled

a guest
Jul 28th, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         testy
  3. // @namespace    https://greasyfork.org/en/users/670188-hacker09?sort=daily_installs
  4. // @version      2
  5. // @description  Improves binge watch experiences on any JWPlayer videos online.
  6. // @author       hacker09
  7. // @include      *
  8. // @icon         https://www.jwplayer.com/hubfs/JW_Player_August2021/Images/favicon-152.png
  9. // @run-at       document-end
  10. // @grant        unsafeWindow
  11. // ==/UserScript==
  12.  
  13. (function() {
  14.   'use strict';
  15.   window.onload = setTimeout(function() //When the page is loaded
  16.     { //Starts the onload event listener
  17.       const Container = unsafeWindow.jwplayer().getContainer(); //Store the jwplayer element container to a variable
  18.       const Player = unsafeWindow.jwplayer(Container); //Store the Player element to a variable
  19.  
  20.       setTimeout(function() { //Starts the settimeout function
  21.  
  22.         function Visibility() //Create a function to check the tab visibility status
  23.         { //Starts the function
  24.           if (document.visibilityState === 'visible') { //If the tab is unfocused
  25.             Player.play() //Plays the video
  26.             Player.setFullscreen(true); //Auto full screen the video
  27.           } //Finishes the if condition
  28.         } //Finishes the if function
  29.         Visibility(); //Calls the function
  30.  
  31.         document.addEventListener("visibilitychange", function() { //When the tab is focused/unfocused
  32.           setTimeout(function() { //Starts the settimeout function
  33.             Visibility(); //Calls the function
  34.           }, 1000); //Finishes the settimeout function
  35.  
  36.           if (document.hidden) { //If the tab is unfocused
  37.             Player.pause(); //Pause the video
  38.           } //Finishes the if condition
  39.  
  40.         }, false); //Finishes the visibilitychange event listener
  41.       }, 500); //Finishes the settimeout function
  42.  
  43.       Player.on('complete', function() { //When the video ends
  44.         Player.setFullscreen(false); //Leave video full screen mode
  45.       }); //Finishes the oncomplete event listener
  46.  
  47.       Player.on('pause', function() { //When the video is pause
  48.         Player.setFullscreen(false); //Leave video full screen mode
  49.       }); //Finishes the oncomplete event listener
  50.  
  51.       document.head.insertAdjacentHTML('beforeend', '<style>.jw-rightclick { display: none !important; }</style>'); //Hide the right click jwplayer video menu options
  52.  
  53.       document.getElementById(unsafeWindow.jwplayer().id).addEventListener('click', function(e) { //When the video is clicked
  54.         setTimeout(function() { //Starts the settimeout function
  55.           if (Player.getState() === 'paused') //If the video is paused
  56.           { //Starts the if condition
  57.             Player.setFullscreen(false); //Leave video full screen mode
  58.           } //Finishes the if condition
  59.           else //If the video is playing
  60.           { //Starts the else condition
  61.             Player.setFullscreen(true); //Enters video full screen mode
  62.           } //Finishes the else condition
  63.         }, 500); //Finishes the settimeout function
  64.       }); //Finishes the on click event listener
  65.  
  66.       document.querySelector("video").addEventListener("keydown", function(e) { //Listen for keypresses
  67.         if (e.key === 'n') //If the N key was pressed (skip end and next ep preview)
  68.         { //Starts the if condition
  69.           Player.setFullscreen(false); //Leave video full screen mode
  70.           if (location.href.match('crunchyroll') !== null) //If the N key was pressed (skip end and next ep preview)
  71.           { //Starts the if condition
  72.             Player.next(); //Jump to next ep
  73.             //window.querySelector(".collection-carousel-media-link-current").parentElement.nextElementSibling.querySelector("div > div > div > a").click(); //Jump to next ep
  74.           } //Finishes the else condition
  75.         } //Finishes the else condition
  76.         if (e.key === 'l') //If the L key was pressed (skip the opening)
  77.         { //Starts the if condition
  78.           Player.seek(Player.getPosition() + 85); //Seek 1:25 secs foward
  79.         } //Finishes the else condition
  80.       }); //Finishes the keydown event listener
  81.     }, 500); //Finishes the onload event listener
  82. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement