HDRezka Assistant

Расширяет функционал плеера HDRezka.

当前为 2018-08-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name HDRezka Assistant
  3. // @name:en HDRezka Assistant
  4. // @namespace ANT0x1
  5. // @version 2.0.1
  6. // @date 2018-08-08
  7. // @description Расширяет функционал плеера HDRezka.
  8. // @description:en Extends player functionality on HDRezka.
  9. // @author ANT0x1
  10. // @match http://*.abbanole.com/*/iframe*
  11. // @icon http://hdrezka.me/templates/hdrezka/images/favicon.ico
  12. // @run-at document-end
  13. // @homepage https://openuserjs.org/scripts/ANT0x1/
  14. // @grant none
  15. // @copyright 2018, ANT0x1
  16. // @license CC-BY-NC-SA-4.0; https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
  17. // @license GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
  18. // @namespace ANT0x1
  19. // ==/UserScript==
  20.  
  21. // ==OpenUserJS==
  22. // @author ANT0x1
  23. // ==/OpenUserJS==
  24.  
  25. (function() {
  26. 'use strict';
  27. removeAds();
  28. })();
  29.  
  30. var currentVideo = {
  31. position: 0,
  32. isFinished: false,
  33. volume: 100
  34. }
  35.  
  36. function removeAds(){
  37. setTimeout(function(){
  38. if (typeof player === 'undefined') {
  39. removeAds();
  40. }
  41. else {
  42. if (typeof player.vast === 'undefined' || typeof player.vast.remove === 'undefined'){
  43. removeAds();
  44. }
  45. else{
  46. player.vast.remove();
  47. console.debug("[Assistant] Ads disabled.");
  48. playVideo();
  49. }
  50. }
  51. }, 2000);
  52. }
  53.  
  54. function playVideo(){
  55. setTimeout(function(){
  56. if (typeof player === 'undefined' || typeof player.api === 'undefined'){
  57. playVideo();
  58. return;
  59. }
  60. player.api.play();
  61. console.debug("[Assistant] Playing.");
  62. restoreFromStorage();
  63.  
  64. api.fullscreen();
  65. console.debug("[Assistant] Set to fullscreen.");
  66.  
  67. player.api.setVolume(currentVideo.volume);
  68. autoSave();
  69. }, 2000);
  70. }
  71.  
  72. function autoSave(){
  73. var timeout = api.paused ? 20000 : 5000;
  74. setTimeout(function(){
  75. savePosition();
  76. if (!api.paused)
  77. saveToStorage();
  78. if (!currentVideo.isFinished)
  79. autoSave();
  80. }, timeout);
  81. }
  82.  
  83. function savePosition(){
  84. currentVideo.position = _mw_current_time;
  85. currentVideo.volume = api.volumeLevel;
  86. currentVideo.isFinished = api.finished;
  87. }
  88.  
  89. function restorePosition(){
  90. if (currentVideo.position > 0){
  91. player.api.seek(currentVideo.position);
  92. console.debug("[Assistant] Position restored to "+currentVideo.position+' sec.');
  93. }
  94. }
  95.  
  96. function saveToStorage(){
  97. var videos = JSON.parse(localStorage.getItem('videos'));
  98. if (!videos)
  99. videos = {};
  100. videos[video_balancer.options.video_token] = currentVideo;
  101. localStorage.setItem('videos', JSON.stringify(videos));
  102. console.debug('[Assistant] Saved to storage');
  103. }
  104.  
  105. function restoreFromStorage(){
  106. var videos = JSON.parse(localStorage.getItem('videos'));
  107. if (!videos)
  108. {
  109. videos = {};
  110. }
  111. currentVideo = videos[video_balancer.options.video_token];
  112. if (!currentVideo){
  113. currentVideo = {
  114. position: 0,
  115. isFinished: false,
  116. volume: api.volumeLevel
  117. }
  118. }
  119. console.debug('[Assistant] Restored from storage');
  120. if (!currentVideo.isFinished)
  121. restorePosition();
  122. else
  123. currentVideo.isFinished = false;
  124. }