Custom YouTube Video Seeking

Adds buttons to YouTube videos to allow custom seeking. It also adds a handy stop start button for stopping to video quickly.

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

  1. // ==UserScript==
  2. // @name Custom YouTube Video Seeking
  3. // @namespace http://www.diamonddownload.weebly.com
  4. // @description Adds buttons to YouTube videos to allow custom seeking. It also adds a handy stop start button for stopping to video quickly.
  5. // @include http://*.youtube.com/*
  6. // @include http://youtube.com/*
  7. // @include https://*.youtube.com/*
  8. // @include https://youtube.com/*
  9. // @grant none
  10. // @version 1.2
  11. // @run-at document-body
  12. // @author R.F Geraci
  13. // @icon64 http://icons.iconarchive.com/icons/designbolts/minimalist-social/64/YouTube-icon.png
  14. // ==/UserScript==
  15.  
  16. //============CUSTOM SETTINGS============
  17. var showPauseButton = true;
  18. var showBackwardsSeekButton = true;
  19. var showForwardsSeekButton = true;
  20. //=======================================
  21.  
  22. var toggle = false;
  23. var btn;
  24. var Tbox;
  25. var SeekBBtn;
  26. var SeekFBtn;
  27. var label;
  28.  
  29. var p = document.getElementsByClassName('video-stream html5-main-video')[0];
  30. var container = document.getElementById('watch7-user-header');
  31.  
  32. function stopvidload(){
  33. if (p){
  34. toggle = !toggle;
  35. if (toggle){
  36. btn.innerText = "Play Video";
  37. p.pause();
  38. }else{
  39. btn.innerText = "Stop Video";
  40. p.play();
  41. }
  42. }
  43. }
  44.  
  45. function seekForward(){
  46. if (Tbox.value != "" && Tbox.value > 0){
  47. var int = parseInt(Tbox.value, 10);
  48. p.currentTime += int;
  49. }
  50. }
  51.  
  52. function seekBackward(){
  53. if (Tbox.value != "" && Tbox.value > 0){
  54. var int = parseInt(Tbox.value, 10);
  55. p.currentTime -= int;
  56. }
  57. }
  58.  
  59. btn = document.createElement('button');
  60. btn.id = 'stop-download';
  61. btn.type = 'button';
  62. btn.title = 'Stop Youtube Download';
  63. btn.className ='yt-subscription-button yt-uix-button yt-uix-button-subscribe-branded';
  64. btn.setAttribute('style', 'margin-left: 5px; outline: none;');
  65. btn.innerText = "Stop Video";
  66. container.appendChild(btn);
  67. btn.addEventListener('click',stopvidload, true);
  68.  
  69.  
  70. if (showPauseButton == true){
  71. btn.style.display = "inline-block";
  72. }else{
  73. btn.style.display = "none";
  74. }
  75.  
  76.  
  77. SeekBBtn = document.createElement('button');
  78. SeekBBtn.id = 'Seek-B-Increment';
  79. SeekBBtn.type = 'button';
  80. SeekBBtn.title = 'Seek Backward';
  81. SeekBBtn.className = 'yt-subscription-button yt-uix-button yt-uix-button-subscribe-branded';
  82. SeekBBtn.setAttribute('style', 'margin-left: 5px; outline: none; width: 25px;');
  83. SeekBBtn.innerText = "◄";
  84. container.appendChild(SeekBBtn);
  85. SeekBBtn.addEventListener('click',seekBackward, true);
  86.  
  87.  
  88. if (showBackwardsSeekButton == true){
  89. SeekBBtn.style.display = "inline-block";
  90. }else{
  91. SeekBBtn.style.display = "none";
  92. }
  93.  
  94. SeekFBtn = document.createElement('button');
  95. SeekFBtn.id = 'Seek-F-Increment';
  96. SeekFBtn.type = 'button';
  97. SeekBBtn.title = 'Seek Forward';
  98. SeekFBtn.className = 'yt-subscription-button yt-uix-button yt-uix-button-subscribe-branded';
  99. SeekFBtn.setAttribute('style', 'margin-left: 5px; outline: none; width: 25px;');
  100. SeekFBtn.innerText = "►";
  101. container.appendChild(SeekFBtn);
  102. SeekFBtn.addEventListener('click',seekForward, true);
  103.  
  104. if (showForwardsSeekButton == true){
  105. SeekFBtn.style.display = "inline-block";
  106. }else{
  107. SeekFBtn.style.display = "none";
  108. }
  109.  
  110. if (showForwardsSeekButton || showBackwardsSeekButton){
  111. Tbox = document.createElement('input');
  112. Tbox.id = 'Increment-value';
  113. Tbox.type ='number';
  114. Tbox.setAttribute('style', 'position: relative; top: 2px; margin-left: 5px; outline: none; width: 35px;');
  115. Tbox.value = "5";
  116. Tbox.min = "0";
  117. Tbox.setAttribute('maxlength', "5");
  118. container.appendChild(Tbox);
  119. label = document.createElement('label');
  120. label.id = 'Seek-Label';
  121. label.type = 'text';
  122. label.setAttribute('style', 'position: relative; top: 2px; margin-left: 5px; outline: none;');
  123. label.innerText = "Seconds";
  124. container.appendChild(label);
  125. }
  126. p.onpause = function(){btn.innerText = "Play Video";};
  127. p.onplay = function(){btn.innerText = "Stop Video";};
  128.  
  129.