Custom YouTube Video Tools

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

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

  1. // ==UserScript==
  2. // @name Custom YouTube Video Tools
  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 2.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. var ToggleOFFDivButtonText = 'Video Tools';
  19. var ToggleONDivButtonText = 'Hide Tools';
  20. //=======================================
  21.  
  22. var toggle = false;
  23. var btn;
  24. var Tbox;
  25. var SeekBBtn;
  26. var SeekFBtn;
  27. var label;
  28. var CheckBox;
  29. var tURLBtn;
  30. var HideAnnosBtn;
  31. var togHideAnno;
  32. var playVidAtBtn;
  33. var PlayVidAtHOUR;
  34. var PlayVidAtMIN;
  35. var PlayVidAtSEC;
  36. var Hlabel;
  37. var Mlabel;
  38. var Slabel;
  39. var vidSpeed;
  40. var vidSpeedlabel;
  41. var TogDiv;
  42. var div;
  43.  
  44. var p = document.getElementsByClassName('video-stream html5-main-video')[0];
  45. var container = document.getElementById('watch7-user-header');
  46.  
  47. function stopvidload(){
  48. if (p){
  49. toggle = !toggle;
  50. if (toggle){
  51. btn.innerText = "Play Video";
  52. p.pause();
  53. }else{
  54. btn.innerText = "Stop Video";
  55. p.play();
  56. }
  57. }
  58. }
  59.  
  60. function seekForward(){
  61. if (Tbox.value != "" && Tbox.value > 0){
  62. var int = parseInt(Tbox.value, 10);
  63. p.currentTime += int;
  64. }
  65. }
  66.  
  67. function seekBackward(){
  68. if (Tbox.value != "" && Tbox.value > 0){
  69. var int = parseInt(Tbox.value, 10);
  70. p.currentTime -= int;
  71. }
  72. }
  73.  
  74. function copyToClipboard(text) {
  75. window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
  76. }
  77.  
  78.  
  79. function GetTimeURL(){
  80. var winLoc = window.location.href;
  81. if (winLoc.indexOf("#t=") > -1){
  82. winLoc = winLoc.slice(0, -5);
  83. }
  84. var cTime = winLoc + "#t=" + p.currentTime.toFixed(0);
  85. copyToClipboard(cTime);
  86. }
  87.  
  88. function HideAnnos(){
  89. var anno = document.getElementsByClassName('video-annotations iv-module')[0];
  90. togHideAnno = !togHideAnno;
  91. if (togHideAnno){
  92. anno.style.display = 'none';
  93. HideAnnosBtn.innerText = "Show Annotations";
  94. }else{
  95. anno.style.display = 'block';
  96. HideAnnosBtn.innerText = "Hide Annotations";
  97. }
  98. }
  99.  
  100. function PlayVidAt(){
  101. var hour = parseInt(PlayVidAtHOUR.value,10);
  102. var min = parseInt(PlayVidAtMIN.value,10);
  103. var sec = parseInt(PlayVidAtSEC.value,10);
  104. p.currentTime = (hour*60*60) + (min*60) + (sec);
  105. p.play();
  106. }
  107.  
  108. function ToggleDiv(){
  109. TogDiv = !TogDiv;
  110. if (TogDiv){
  111. div.style.display = "block";
  112. CheckBox.value = ToggleONDivButtonText;
  113. }else{
  114. div.style.display = "none";
  115. CheckBox.value = ToggleOFFDivButtonText;
  116. }
  117. }
  118. //----------------------------------------------------------------------------------------------------
  119. div = document.createElement('div');
  120. div.id = 'myDiv';
  121. div.setAttribute('style', 'margin-top: 10px; margin-bottom: 25px; display: none; border-top: 1px solid #EEEEEE; border-bottom: 1px solid #EEEEEE; width: 100%; margin-right: 20px; padding-top: 5px; padding-bottom: 5px;');
  122. container.appendChild(div);
  123. //----------------------------------------------------------------------------------------------------
  124. btn = document.createElement('button');
  125. btn.id = 'Play-Video';
  126. btn.type = 'button';
  127. btn.title = 'Play/Pause Video';
  128. btn.className ='yt-subscription-button yt-uix-button yt-uix-button-subscribe-branded';
  129. btn.setAttribute('style', 'margin-left: 5px; display: inline;');
  130. btn.innerText = "Stop Video";
  131. div.appendChild(btn);
  132. btn.addEventListener('click',stopvidload, true);
  133. //----------------------------------------------------------------------------------------------------
  134. SeekBBtn = document.createElement('button');
  135. SeekBBtn.id = 'Seek-B-Increment';
  136. SeekBBtn.type = 'button';
  137. //SeekBBtn.title = 'Seek Backward';
  138. SeekBBtn.className = 'yt-subscription-button yt-uix-button yt-uix-button-subscribe-branded';
  139. SeekBBtn.setAttribute('style', 'margin-left: 5px; width: 25px;');
  140. SeekBBtn.innerText = "◄";
  141. div.appendChild(SeekBBtn);
  142. SeekBBtn.addEventListener('click',seekBackward, true);
  143. //----------------------------------------------------------------------------------------------------
  144. SeekFBtn = document.createElement('button');
  145. SeekFBtn.id = 'Seek-F-Increment';
  146. SeekFBtn.type = 'button';
  147. //SeekBBtn.title = 'Seek Forward';
  148. SeekFBtn.className = 'yt-subscription-button yt-uix-button yt-uix-button-subscribe-branded';
  149. SeekFBtn.setAttribute('style', 'margin-left: 5px; width: 25px;');
  150. SeekFBtn.innerText = "►";
  151. div.appendChild(SeekFBtn);
  152. SeekFBtn.addEventListener('click',seekForward, true);
  153. //----------------------------------------------------------------------------------------------------
  154. Tbox = document.createElement('input');
  155. Tbox.id = 'Increment-value';
  156. Tbox.type ='number';
  157. Tbox.setAttribute('style', 'margin-left: 5px; width: 35px; position: relative; top: 2px;');
  158. Tbox.value = "5";
  159. Tbox.min = "0";
  160. Tbox.setAttribute('maxlength', "5");
  161. div.appendChild(Tbox);
  162. //----------------------------------------------------------------------------------------------------
  163. label = document.createElement('label');
  164. label.id = 'Seek-Label';
  165. label.type = 'text';
  166. label.setAttribute('style', 'margin-left: 5px; position: relative; top: 2px;');
  167. label.innerText = "Seconds";
  168. div.appendChild(label);
  169. //---------------------------------------------------------------------------------------------------
  170. tURLBtn = document.createElement('button');
  171. tURLBtn.id = 'tURLBtn';
  172. tURLBtn.type = 'button';
  173. tURLBtn.className = 'yt-subscription-button yt-uix-button yt-uix-button-subscribe-branded';
  174. tURLBtn.setAttribute('style', 'margin-left: 5px;');
  175. tURLBtn.innerText = "Get URL at Current Time";
  176. div.appendChild(tURLBtn);
  177. tURLBtn.addEventListener('click',GetTimeURL, true);
  178. //----------------------------------------------------------------------------------------------------
  179. HideAnnosBtn = document.createElement('button');
  180. HideAnnosBtn.id = 'HideAnnos';
  181. HideAnnosBtn.type = 'button';
  182. HideAnnosBtn.className = 'yt-subscription-button yt-uix-button yt-uix-button-subscribe-branded';
  183. HideAnnosBtn.setAttribute('style', 'margin-left: 5px;');
  184. HideAnnosBtn.innerText = "Hide Annotations";
  185. div.appendChild(HideAnnosBtn);
  186. HideAnnosBtn.addEventListener('click',HideAnnos, true);
  187. //----------------------------------------------------------------------------------------------------
  188. playVidAtBtn = document.createElement('button');
  189. playVidAtBtn.id = 'playVidAtBtn';
  190. playVidAtBtn.type = 'button';
  191. playVidAtBtn.className = 'yt-subscription-button yt-uix-button yt-uix-button-subscribe-branded';
  192. playVidAtBtn.setAttribute('style', 'margin-left: 5px;');
  193. playVidAtBtn.innerText = "Play Video At";
  194. div.appendChild(playVidAtBtn);
  195. playVidAtBtn.addEventListener('click',PlayVidAt, true);
  196. //----------------------------------------------------------------------------------------------------
  197. PlayVidAtHOUR = document.createElement('input');
  198. PlayVidAtHOUR.id = 'PlayVidAtHOUR';
  199. PlayVidAtHOUR.type ='number';
  200. PlayVidAtHOUR.setAttribute('style', 'margin-left: 5px; width: 35px; position: relative; top: 2px;');
  201. PlayVidAtHOUR.value = "0";
  202. PlayVidAtHOUR.min = "0";
  203. PlayVidAtHOUR.setAttribute('maxlength', "5");
  204. div.appendChild(PlayVidAtHOUR);
  205. //----------------------------------------------------------------------------------------------------
  206. Hlabel = document.createElement('label');
  207. Hlabel.id = 'Hlabel';
  208. Hlabel.type = 'text';
  209. Hlabel.setAttribute('style', 'margin-left: 5px; position: relative; top: 2px;');
  210. Hlabel.innerText = "h";
  211. div.appendChild(Hlabel);
  212. //---------------------------------------------------------------------------------------------------
  213. PlayVidAtMIN = document.createElement('input');
  214. PlayVidAtMIN.id = 'PlayVidAtMIN';
  215. PlayVidAtMIN.type ='number';
  216. PlayVidAtMIN.setAttribute('style', 'margin-left: 5px; width: 35px; position: relative; top: 2px;');
  217. PlayVidAtMIN.value = "0";
  218. PlayVidAtMIN.min = "0";
  219. PlayVidAtMIN.setAttribute('maxlength', "5");
  220. div.appendChild(PlayVidAtMIN);
  221. //----------------------------------------------------------------------------------------------------
  222. Mlabel = document.createElement('label');
  223. Mlabel.id = 'Mlabel';
  224. Mlabel.type = 'text';
  225. Mlabel.setAttribute('style', 'margin-left: 5px; position: relative; top: 2px;');
  226. Mlabel.innerText = "m";
  227. div.appendChild(Mlabel);
  228. //---------------------------------------------------------------------------------------------------
  229. PlayVidAtSEC = document.createElement('input');
  230. PlayVidAtSEC.id = 'PlayVidAtMIN';
  231. PlayVidAtSEC.type ='number';
  232. PlayVidAtSEC.setAttribute('style', 'margin-left: 5px; width: 35px; position: relative; top: 2px;');
  233. PlayVidAtSEC.value = "0";
  234. PlayVidAtSEC.min = "0";
  235. PlayVidAtSEC.setAttribute('maxlength', "5");
  236. div.appendChild(PlayVidAtSEC);
  237. //----------------------------------------------------------------------------------------------------
  238. Slabel = document.createElement('label');
  239. Slabel.id = 'Slabel';
  240. Slabel.type = 'text';
  241. Slabel.setAttribute('style', 'margin-left: 5px; position: relative; top: 2px;');
  242. Slabel.innerText = "s";
  243. div.appendChild(Slabel);
  244. //---------------------------------------------------------------------------------------------------
  245. vidSpeedlabel = document.createElement('label');
  246. vidSpeedlabel.id = 'vidSpeedlabel';
  247. vidSpeedlabel.type = 'text';
  248. vidSpeedlabel.setAttribute('style', 'margin-left: 5px; position: relative; top: 2px;');
  249. vidSpeedlabel.innerText = "Video Speed";
  250. div.appendChild(vidSpeedlabel);
  251. //-------------------------------------------------------------------------------------------------------
  252. vidSpeed = document.createElement('input');
  253. vidSpeed.id = 'vidSpeed';
  254. vidSpeed.type ='number';
  255. vidSpeed.setAttribute('style', 'margin-left: 5px; width: 45px; position: relative; top: 2px;');
  256. vidSpeed.value = "1";
  257. vidSpeed.min = "0.25";
  258. vidSpeed.max = "2";
  259. vidSpeed.setAttribute('maxlength', "5");
  260. vidSpeed.setAttribute('step', "0.25");
  261. div.appendChild(vidSpeed);
  262. //---------------------------------------------------------------------------------------------------
  263. CheckBox = document.createElement('input');
  264. CheckBox.id = 'myCheckbox';
  265. CheckBox.type = 'button';
  266. CheckBox.title = 'Show/Hide Custom Video Tools';
  267. CheckBox.className ='yt-subscription-button yt-uix-button yt-uix-button-subscribe-branded';
  268. CheckBox.setAttribute('style', 'Border-Bottom-Left-Radius: 0px; !important; Border-Top-Left-Radius: 0px; !important; margin: -1px !important;');
  269. CheckBox.value = ToggleOFFDivButtonText;
  270. var parent = document.getElementById('watch7-subscription-container');
  271. parent.appendChild(CheckBox);
  272. CheckBox.addEventListener('click', ToggleDiv, true);
  273. //----------------------------------------------------------------------------------------------------
  274. if (showOnPageLoad){
  275. div.style.display = "block";
  276. CheckBox.value = ToggleONDivButtonText;
  277. TogDiv = true;
  278. }else{
  279. div.style.display = "none";
  280. CheckBox.value = ToggleOFFDivButtonText;
  281. }
  282. //----------------------------------------------------------------------------------------------------
  283. p.onpause = function(){btn.innerText = "Play Video"; toggle = true;};
  284. p.onplay = function(){btn.innerText = "Stop Video"; toggle = false;};
  285. vidSpeed.onchange = function(){p.playbackRate = parseInt(vidSpeed.value,10);};
  286.  
  287.  
  288.  
  289.  
  290.  
  291.