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.1.0
  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 showOnPageLoad = false;
  18. //=======================================
  19.  
  20. var toggle = false;
  21. var btn;
  22. var Tbox;
  23. var SeekBBtn;
  24. var SeekFBtn;
  25. var label;
  26. var CheckBox;
  27. var div;
  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. div = document.createElement('div');
  60. div.id = 'myDiv';
  61. div.setAttribute('style', 'outline: none; display:none; ');
  62. container.appendChild(div);
  63.  
  64. btn = document.createElement('button');
  65. btn.id = 'Play-Video';
  66. btn.type = 'button';
  67. btn.title = 'Play/Pause Video';
  68. btn.className ='yt-subscription-button yt-uix-button yt-uix-button-subscribe-branded';
  69. btn.setAttribute('style', 'margin-left: 5px; outline: none; display: inline;');
  70. btn.innerText = "Stop Video";
  71. div.appendChild(btn);
  72. btn.addEventListener('click',stopvidload, true);
  73.  
  74. SeekBBtn = document.createElement('button');
  75. SeekBBtn.id = 'Seek-B-Increment';
  76. SeekBBtn.type = 'button';
  77. //SeekBBtn.title = 'Seek Backward';
  78. SeekBBtn.className = 'yt-subscription-button yt-uix-button yt-uix-button-subscribe-branded';
  79. SeekBBtn.setAttribute('style', 'margin-left: 5px; outline: none; width: 25px; display: inline;');
  80. SeekBBtn.innerText = "◄";
  81. div.appendChild(SeekBBtn);
  82. SeekBBtn.addEventListener('click',seekBackward, true);
  83.  
  84. SeekFBtn = document.createElement('button');
  85. SeekFBtn.id = 'Seek-F-Increment';
  86. SeekFBtn.type = 'button';
  87. //SeekBBtn.title = 'Seek Forward';
  88. SeekFBtn.className = 'yt-subscription-button yt-uix-button yt-uix-button-subscribe-branded';
  89. SeekFBtn.setAttribute('style', 'margin-left: 5px; outline: none; width: 25px; display: inline;');
  90. SeekFBtn.innerText = "►";
  91. div.appendChild(SeekFBtn);
  92. SeekFBtn.addEventListener('click',seekForward, true);
  93.  
  94. Tbox = document.createElement('input');
  95. Tbox.id = 'Increment-value';
  96. Tbox.type ='number';
  97. Tbox.setAttribute('style', 'margin-left: 5px; outline: none; width: 35px; display: inline; position: relative; top: 2px;');
  98. Tbox.value = "5";
  99. Tbox.min = "0";
  100. Tbox.setAttribute('maxlength', "5");
  101. div.appendChild(Tbox);
  102.  
  103. label = document.createElement('label');
  104. label.id = 'Seek-Label';
  105. label.type = 'text';
  106. label.setAttribute('style', 'margin-left: 5px; outline: none; display: inline; position: relative; top: 2px;');
  107. label.innerText = "Seconds";
  108. div.appendChild(label);
  109.  
  110. CheckBox = document.createElement('input');
  111. CheckBox.id = 'myCheckbox';
  112. CheckBox.type = 'checkbox';
  113. CheckBox.title = 'Show/Hide Custom Video Seeking';
  114. CheckBox.className ='yt-subscription-button yt-uix-button yt-uix-button-subscribe-branded';
  115. CheckBox.setAttribute('style', 'margin-left: 5px; outline: none; display: inline; position: relative; top: 2px;');
  116. CheckBox.checked = false;
  117. container.appendChild(CheckBox);
  118.  
  119. if (showOnPageLoad){
  120. CheckBox.checked = true;
  121. div.style.display = "inline-block";
  122. }else{
  123. CheckBox.checked = false;
  124. div.style.display = "none";
  125. }
  126. setInterval(function(){
  127. if(CheckBox.checked == true){
  128. div.style.display = "inline-block";
  129. }else{
  130. div.style.display = "none";
  131. }
  132. }, 10);
  133.  
  134. p.onpause = function(){btn.innerText = "Play Video"; toggle = true;};
  135. p.onplay = function(){btn.innerText = "Stop Video"; toggle = false;};
  136.  
  137.  
  138.  
  139.  
  140.