JWPlayer Enhancer

Auto plays JWPlayer Enhancer

目前为 2021-10-31 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name JWPlayer Enhancer
  3. // @namespace JWPlayerEnhancer
  4. // @version 0.1
  5. // @description Auto plays JWPlayer Enhancer
  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 = function() //When the page is loaded
  16. { //Starts the onload event listener
  17. var Container = unsafeWindow.jwplayer().getContainer(); //Store the jwplayer element container to a variable
  18. var 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() //playerfullhdbeta //Plays the hd video
  26. Player.setFullscreen(); //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. //document.hasFocus = function(){return true};
  33. setTimeout(function() { //Starts the settimeout function
  34. Visibility(); //Calls the function
  35. }, 1000); //Finishes the settimeout function
  36.  
  37. if (document.hidden) { //If the tab is unfocused
  38. Player.pause(); //Pause the video
  39. } //Finishes the if condition
  40.  
  41. }, false); //Finishes the visibilitychange event listener
  42. }, 1500); //Finishes the settimeout function
  43.  
  44. Player.on('complete', function() { //When the video ends
  45. Player.setFullscreen(false); //Leave video full screen mode
  46. }); //Finishes the oncomplete event listener
  47.  
  48. Player.on('play', function() { //When the video is playing
  49. Player.setFullscreen(true); //Enter video full screen mode
  50. }); //Finishes the oncomplete event listener
  51.  
  52. document.head.insertAdjacentHTML('beforeend', '<style>.jw-rightclick { display: none !important; }</style>'); //Hide the right click jwplayer video menu options
  53.  
  54. document.getElementById(unsafeWindow.jwplayer().id).addEventListener('click', function(e) { //When the video is clicked
  55. setTimeout(function() { //Starts the settimeout function
  56. if (Player.getState() === 'paused') //If the video is paused
  57. { //Starts the if condition
  58. Player.setFullscreen(false); //Leave video full screen mode
  59. } //Finishes the if condition
  60. }, 500); //Finishes the settimeout function
  61. }); //Finishes the on click event listener
  62.  
  63. document.getElementById(unsafeWindow.jwplayer().id).addEventListener('contextmenu', function(e) { //When the video is right clicked
  64. if (Player.getPosition() > 1080) //If 18 or more minutes was watched. (skip ending and next episode preview)
  65. { //Starts the if condition
  66. Player.setFullscreen(false); //Leave video full screen mode
  67. } //Finishes the else condition
  68. else //If less than 18 minutes was watched (skip the oppening)
  69. { //Starts the if condition
  70. Player.seek(Player.getPosition() + 85); //Seek 1:25 secs foward
  71. } //Finishes the else condition
  72. }); //Finishes the context menu event listener
  73. } //Finishes the onload event listener
  74.  
  75. })();